<?php
@session_start();
include("modules/db.php");
include("modules/products.php");

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

$product = new Products();

$pro_name = $_POST["pro_name"];

$products = $product->getProductListName($pro_name);

?>

<div class="container-xxl flex-grow-1 container-p-y">
	<?php
		if($pro_name != ""){
			?>
			<h4 class="fw-bold py-3 mb-4"><span class="fw-light">Search /</span><span class=" fw-light"> <?=$pro_name?> </span> </h4>
			<?php
		}
	?>
	
	<div class="row mb-5">
		<?php
		foreach ($products as $key => $value) {
			?>
				<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 class="card-body">
		              <h6 class="card-title"><?=str_replace("Out of stock HQ",'',$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>
		            <div class="card-body">
		             <div style="font-size: 1.2rem;width: 100%;display: flex;flex-direction: row;justify-content: space-around;
    align-items: cente" 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>
			<?php
		}
		?>	
	</div>
</div>
