<?php
include("modules/cart.php");
@session_start();
$cart = new Cart();
if(isset($_SESSION['currency'])){
	$currency =$_SESSION['currency'];
}else{
	$currency = "MMK";
}
if(isset($_POST['action']) and isset($_POST['pro_id'])){
	$action = $_POST['action'];
	$pro_id = $_POST['pro_id'];
	if($action == "1"){
		$cart->add_qty($pro_id);
	}elseif($action == "2"){
		$cart->minus_qty($pro_id);
	}elseif($action == "3"){
		$cart->delete_item($pro_id);
	}

}

if(isset($_SESSION['cart'])){
	$carts = json_decode($_SESSION['cart']);
}else{
	$carts = array();
}

?>
<div class="container-xxl flex-grow-1 container-p-y">
	<h4 class="fw-bold py-3 mb-4">Cart</h4>
	<div class="row mb-5">
		<div class="col-12">
			<?php
			if(count($carts) == 0)
			{
				?>
					 <div class="card mb-2">
		            
		            	<div class="card-body">
		            		<center><h5>You have no items in your shopping cart</h5></center>
		            	</div>
		            </div>
				<?php

			}else{
				foreach ($carts as $key => $value) {
			?>
				   <div class="card mb-2">
		            
		            <div class="card-body">
		              <table width="100%" border="0">
							

								<tr>
									
									<td colspan="4" align="left">
										<p style="font-size: 1em;">
											<?=$value->product_name?>
										</p>
									</td>
									
								</tr>
								<tr>
									<td width="100" align="left">
										<img width="100" src="<?=$value->product_img?>">
									</td>
									<td>
										<p style="font-size: 1em;"><?=number_format($value->product_price)." ".$currency?>.- </p>
										<div class="quantity buttons_added">
											<input onclick="cart_minus_qty('<?=$value->product_id?>')" type="button" value="-" class="minus"><input type="number" step="1" min="1" max="" name="quantity" value="<?=$value->product_qty?>" title="Qty" class="input-text qty text" size="4" pattern="" readonly inputmode=""><input onclick="cart_add_qty('<?=$value->product_id?>')" type="button" value="+" class="plus">
										</div>
									</td>
									<td width="150" align="right">
										<p style="color:blue;font-size: 1.1em;"><?=number_format($value->product_price*$value->product_qty)?>.- <?=$currency?></p>
									</td>
									<td align="right" width="100">
										<a  onclick="cart_delete_item('<?=$value->product_id?>')"href="#" style="color: red">
											<i class="menu-icon tf-icons bx bx-trash">
											</i>
										</a>
									</td>
								</tr>

								
						</table>
		            </div>
		          </div>
		          <?php
				}
			}

			?>
		</div>
	</div>
</div>
<?php
if(count($carts) > 0){
	?>
		<div class="buy-now">
		  
		  <div style="box-shadow: 0 1px 20px 1px #696cff;" class="btn-buy-now">
		  	<button onclick="page_order()" class="btn btn-primary">Order now</button>
		  </div>
		  
		</div>
	<?php
}
?>