<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%@ page import ="com.dao.ProductDao" %> 
<%@ page import ="com.entities.Product" %> 
<%@ page import ="com.dao.CategoryDao" %> 
<%@ page import ="com.entities.Category" %> 
<%@ page import ="com.dao.CategoriesDao" %> 
<%@ page import ="com.entities.Categories" %> 
<%@ page import ="com.artifacts.FactoryProvider" %> 
<%@ page import ="com.artifacts.Helper" %> 
<%@ page import ="java.util.List" %> 

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<meta name="viewport" content="width-device-width, inital-scale=1.0">
        <title>Artifacts|Products</title>
        <link rel = "icon" href = "images/icon.jpg" type = "image/x-icon">
        <link rel="stylesheet" href="stylec.css">
        
        
      
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
         <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="preconnect" href="https://fonts.gstatic.com">
        <link href="https://fonts.googleapis.com/css2?family=Kaushan+Script&family=Poppins:wght@300;400;500;600;700;900&display=swap" rel="stylesheet">
        <%@include file="components/bootstrapcss.jsp" %>
</head>
<body>
    
            <a href="about.jsp">
            <img src="images/logos1.png" class="logo">
            </a> 
            <h1>Products</h1>
           
            
            
          
         <%
            CategoriesDao cadao = new CategoriesDao(FactoryProvider.getFactory());
            List<Categories> calist = cadao.getCategoriees();
            
            String cats = request.getParameter("cates");
           
            CategoryDao cdao = new CategoryDao(FactoryProvider.getFactory());
           
            
            List<Category>clist = null;
            if(cats==null){
            	clist = cdao.getCategory();
            }
            else{
            	
            	int cids =Integer.parseInt(cats.trim());
            	clist = cdao.getAllCategoryById(cids);
            	
            }
            
            String cat = request.getParameter("cate");
            
            ProductDao dao = new ProductDao(FactoryProvider.getFactory());
            List<Product> list =null;
            if(cat==null){
            	list = dao.getAllProducts();
            }
            else{
            	
            	int cid =Integer.parseInt(cat.trim());
            	list = dao.getAllProductsById(cid);
            	
            }
            %>
           
   <div class="row">
       <div class="col-md-4" >   
       <nav id="menu">

        <ul class="parent-menu">
        <li><a href="index.jsp"><strong>Home</strong></a></li>
        <li><a href="#" data-toggle="modal"  data-target="#cart">
                 Cart <i class="fa fa-shopping-bag"></i><span class="cart-items">(0)</span>
                 </a></li>
        <li><a href="#"><strong>Categories</strong></a></li>
        
        <%
       							for(Categories categories: calist){
       						
       						
       						
       						%>

            <li><a href="products.jsp?cates=<%=categories.getCategoriesId()%>"><%=categories.getCategoriesTitle() %></a>

                <ul>
                 <%
       							for(Category category: clist){
       						
       						
       						
       						%>

                    <li><a href="products.jsp?cate=<%=category.getCategoryId()%>"><%=category.getCategoryTitle() %></a></li>
                     <%} %>

                    
                </ul>

            </li>
             <%} %>

            
        </ul>

    </nav>  
    </div>
      
           
            

     
 
<div class="col-md-8">

<div class="row-mt-1">
<div class="col-md-12">
<div class="card-columns">

<%  for (Product product: list){ %>
           <div class="card">
           <div class="card-body">
   <div class="container-fluid text-center">       
  <img src="images/products/<%=product.getpPhoto() %>" style="max-height: 270px; max-width: 100%; width: auto;"class="card-img-top m-2" alt="...." >
  </div> 
  <h2 class="card-title"><%=product.getpName() %></h2>
  
  <p class="card-text"><%=Helper.get10Words(product.getpDesc()) %></p>
  <p class="price"> Rs.<%=product.getpPrice() %></p>
  <div class="rating">
                        <i class="fa fa-star"></i>
                        <i class="fa fa-star"></i>
                        <i class="fa fa-star"></i>
                        <i class="fa fa-star"></i>
                        <i class="fa fa-star-o"></i>
                    </div>
  
  </div> 
  <div class="card-footer">
  
         <button class="btn btn-outline-primary" onclick= "add_to_cart( '<%=product.getpPhoto()%>' , <%= product.getpId()%> , '<%= product.getpName()%>' , <%= product.getpPrice() %>)" >Add to Cart</button>  
  
  </div>


</div>  
<% } %>   


</div>


</div>

</div>
</div>
</div>



   
             
     <!----------------------------footer-------------------------->
        <section id="footer">
        <img src="images/logos2.png" class="footer-img">
       
        
        <div class="social-links">
            <i class="fa fa-facebook"></i>
            <i class="fa fa-whatsapp"></i>
            <i class="fa fa-instagram"></i>
            <i class="fa fa-twitter"></i>
            <p>=============Copyright Artifact's &amp; Terms &amp; Conditions============</p>
            
        </div>
        
    </section>
   
   <%@include file="components/modal.jsp" %>
    
    
</body>
</html>