<?php 
include('includes/connectdb.php');
include('includes/head.php'); 
//unset($_SESSION["cart_item"]);

?>
<body>
    <div class="page-wrapper">
        <?php include('includes/header.php'); ?>

        <main class="main">
            <nav aria-label="breadcrumb" class="breadcrumb-nav">
                <div class="container">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="index"><i class="icon-home"></i></a></li>
                        <li class="breadcrumb-item active" aria-current="page">Home</li>
                    </ol>
                </div><!-- End .container -->
            </nav>
            <div class="container">
                <div class="row row-sm" id="products">
				    <?php 
					    if(isset($_GET['q'])){
							$keyword = $_GET['q'];
							$sql = mysqli_query($con, "SELECT * FROM product WHERE product_name LIKE '%" . $keyword . "%' AND availability_status = 1 LIMIT 6 OFFSET 0 ");
						}elseif(isset($_GET['scid'])){
							$sub_category_id = $_GET['scid'];
							$sql = mysqli_query($con, "SELECT * FROM product WHERE availability_status = 1 AND sub_category_id = $sub_category_id LIMIT 6 OFFSET 0 ");
						}else{
							$sql = mysqli_query($con, "SELECT * FROM product WHERE availability_status = 1 LIMIT 6 OFFSET 0 ");
						}				
					
                        while($row = mysqli_fetch_array($sql)):
						$image = $row['main_image_url'];
						
						$product_name = $row['product_name'];
						$product_name = substr($product_name, 0, 23);
						$product_id = $row['product_id'];
						$src = "uploads/" . $image;
						
						$price = $row['price'];
						
					?>
				    <div class='col-6 col-md-4 col-xl-2'>
						<div class='product'>
							<figure class='product-image-container'>
								<a href='product?pid=<?php echo $product_id ?>' class='product-image'>
									<img src='<?php echo $src ?>' alt='product'>
								</a>
								<a href='ajax/product-quick-view?pid=<?php echo $product_id ?>' class='btn-quickview'>Quick View</a>
							</figure>
							<div class='product-details'>
								<h2 class='product-title'>
									<a data-toggle='tooltip' title='' href='product?pid=<?php echo $product_id ?>'><?php echo $product_name ?></a>
								</h2>
								<div class='price-box'>
									<span class='product-price'>$<?php echo number_format($price) ?></span>
								</div><!-- End .price-box -->
								<div class='product-action'>
									<a onclick="addToCart('<?php echo $product_id ?>',<?php echo $price ?>,'<?php echo $product_name ?>','<?php echo $src ?>')" class='paction add-cart' title='Add to Cart'>
										<span class='pointer'>Add to Cart</span>
									</a>
								</div>
							</div>
						</div>
					</div>
					<?php endwhile; ?>
                </div><!-- End .row -->
				<div class="row">
					<div class="col-5"></div>
					<div class="col-6 col-offset-3" onclick="loadMore()"><button class="btn btn-primary" id="load-more">Click to load more</button></div>
				</div>
            </div><!-- End .container -->
          <div class="mb-5"></div><!-- margin -->
		  
        </main><!-- End .main -->
		
		

        <?php include('includes/footer.php') ?>
    </div><!-- End .page-wrapper -->

    <div class="mobile-menu-overlay"></div><!-- End mobil-menu-overlay -->

    <?php include('includes/mobile-menu.php') ?>

    <a id="scroll-top" href="#top" title="Top" role="button"><i class="icon-angle-up"></i></a>

    <!-- Plugins JS File -->
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.bundle.min.js"></script>
    <script src="assets/js/plugins.min.js"></script>
    <script src="assets/js/nouislider.min.js"></script>

    <!-- Main JS File -->
    <script src="assets/js/main.min.js"></script>
	
	<!-- Custom JS File -->
    <script src="assets/js/custom.js"></script>
</body>

</html>