<?php
@session_start();
header('Content-Type: text/html; charset=utf-8');
include("modules/db.php");
include("modules/products.php");
$product = new Products();

$category = $_POST["category"];
$sub_category = $_POST["sub_category"];
$sub_category_name = $_POST["sub_category_name"];
$skip = $_POST["skip"];
$take = $_POST["take"];

if(isset($_SESSION['currency'])){
	$currency =$_SESSION['currency'];
}else{
	$currency = "MMK";
}

$data = $product->getProductListFromUrl($category,$sub_category,$skip,$take);

$res = [];
$res["next"] = $data["next"];
$res["skip"] = $skip + $take;
$res["products"] = [];
foreach ($data["products"] as $key => $value) {
	$product = "
		<div class=\"col-md-6 col-lg-4 div-product\">
          <div class=\"card\">
            <img class=\"card-img-top\" src=".$value->product_img." onerror=\"this.src='https://via.placeholder.com/150/'\">
            <div style=\"height: 10rem;\" class=\"card-body\">
              <h6 class=\"card-title\">".$value->product_name."</h6>
              <p class=\"card-text\">".$value->product_desc."</p>
            </div>
            <ul class=\"list-group list-group-flush\">
              <li class=\"list-group-item\">
              	<font color=\"#157bed\">".number_format($value->product_price_srp)." ".$currency ."</font> 
              	<font color=\"red\" style=\"float: right\">".$value->product_warranty."
              	</font>
              </li>
             
            </ul>
			<a style=' align-self: center;' class='' href='product_detail.php?pro_name=".$value->product_name."'>Product Detail</a>
            <div class=\"card-body\">
           
              <div style=\"font-size: 1.2rem;width: 100%;display: flex;flex-direction: row;justify-content: space-around;
    align-items: center;\" onclick=\"add_cart('".$value->id."','".$value->product_code."','".$value->product_name."','".$value->product_desc."','".$value->product_price_srp."','".$value->product_img."','".$value->product_warranty."')\" class=\"btn btn-primary\"> <i style=\"font-size: 2rem;\" class=\"bx bx-cart\"></i>".number_format($value->product_price_srp)." ".$currency ." </div>
	
            </div>
          </div>
        </div>";

        array_push($res["products"], $product);
	
}
echo json_encode($res);
?>	
	

