<?php
include("modules/cart.php");
@session_start();
$cart = new Cart();

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

$order_total_price = 0;

?>
<div class="container-xxl flex-grow-1 container-p-y">
	<h4 class="fw-bold py-3 mb-4">Order</h4>
	<div class="row mb-5">
		<div class="col-12">
			
			<div class="card mb-2">
				<h5 class="card-header">Products</h5>
			   	<div class="card-body">
	            
	            <table width="100%" border="0">
	            	
		        <?php
				foreach ($carts as $key => $value) 
				{
					$product_total_price = $value->product_price*$value->product_qty;
				?>
	            	<tr>
	            		
	            		<td style="padding: 10px;background-color: #ffab0026;color: #000;" colspan="4" align="left">
							<p style="margin: 0px;font-size: 1em;">
								<?=$value->product_name?>
							</p>
						</td>
	            	</tr>
					<tr>
						<td colspan="1"></td>
						
						<td align="center">
							<p style="font-size: 1em;">
								x <?=$value->product_qty?>
							</p>
						</td>
						<td>
							<p style="font-size: 1em;"><?=number_format($value->product_price)?>.- </p>
						</td>
						<td align="right">
							<p style="color:blue;font-size: 1.1em;"><?=number_format($product_total_price)?>.- </p>
						</td>
						
					</tr>
				
				<?php
				$order_total_price += $product_total_price;
				}
				?>
				<tr>
					<td colspan="4"><hr></td>
				</tr>
				<tr>
					<td colspan="3"></td>
					<td align="right"><p style="color:blue;font-size: 1.1em;"><?=number_format($order_total_price)?>.- </p> </td>
				</tr>
				</table>
	            </div>
	        </div>

	        <div class="card mb-2">
				<h5 class="card-header">Order Detail</h5>
			   	<div class="card-body">
			   		<form action="send_order.php" method="post">
			   			<div class="mb-3 row">
		                    <label class="col-md-2 col-form-label">Name</label>
		                    <div class="col-md-10">
		                      <input name="cus_name" class="form-control" type="text" value="" required="required">
		                    </div>
	                  	</div>
	                  	<div class="mb-3 row">
		                    <label class="col-md-2 col-form-label">Address</label>
		                    <div class="col-md-10">
		                      <input name="cus_address" class="form-control" type="text" value="" required="required">
		                    </div>
	                  	</div>
	                  	<div class="mb-3 row">
		                    <label class="col-md-2 col-form-label">Phone</label>
		                    <div class="col-md-10">
		                      <input maxlength="11" name="cus_phone" class="form-control" type="text" value="" required="required">
		                    </div>
	                  	</div>
	                  	<div class="mb-3 row">
		                    <button type="submit" class="btn btn-success">SEND</button>
	                  	</div>
			   		</form>
			   		
			   	</div>
			</div>
	         
		</div>
	</div>
</div>
