<?php

ini_set('session.cookie_path', '/');
ini_set('session.cookie_domain', $_SERVER['HTTP_HOST']);
session_start();
include "Adminn/db.php";

if(!isset($_SESSION['cart'])){
    $_SESSION['cart'] = [];
}

// Remove item
if(isset($_GET['remove'])){
    $id = intval($_GET['remove']);
    unset($_SESSION['cart'][$id]);
    header("Location: cart.php");
    exit();
}

// Update quantity
if(isset($_POST['update_cart'])){
    foreach($_POST['qty'] as $id => $qty){
        $_SESSION['cart'][$id] = max(1, intval($qty));
    }
    header("Location: cart.php");
    exit();
}

$cart = $_SESSION['cart'];
?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">ApexUniversal</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <meta content="" name="keywords">
    <meta content="" name="description">

    <!-- Google Web Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link
        href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;600;700&family=Roboto:wght@400;500;700&display=swap"
        rel="stylesheet">

    <!-- Icon Font Stylesheet -->
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css" rel="stylesheet">

    <!-- Libraries Stylesheet -->
    <link href="lib/animate/animate.min.css" rel="stylesheet">
    <link href="lib/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet">


    <!-- Customized Bootstrap Stylesheet -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Template Stylesheet -->
    <link href="css/style.css" rel="stylesheet">
</head>

<body>

    <!-- Spinner Start -->
    <div id="spinner"
        class="show bg-white position-fixed translate-middle w-100 vh-100 top-50 start-50 d-flex align-items-center justify-content-center">
        <div class="spinner-border text-primary" style="width: 3rem; height: 3rem;" role="status">
            <span class="sr-only">Loading...</span>
        </div>
    </div>
    <!-- Spinner End -->


    <!-- Topbar Start -->
   
    <!-- Topbar End -->

    <!-- Navbar & Hero Start -->
    <div class="container-fluid nav-bar p-0">
        <div class="row gx-0 bg-primary px-5 align-items-center">
            <div class="col-lg-3 d-none d-lg-block">
                <nav class="navbar navbar-light position-relative" style="width: 250px;">
                    <button class="navbar-toggler border-0 fs-4 w-100 px-0 text-start" type="button"
                        data-bs-toggle="collapse" data-bs-target="#allCat">
                        <h4 class="m-0"><i class="fa fa-bars me-2"></i>All Categories</h4>
                    </button>
                    <div class="collapse navbar-collapse rounded-bottom" id="allCat">
                        <div class="navbar-nav ms-auto py-0">
                            <ul class="list-unstyled categories-bars">
                                <li>
                                    <div class="categories-bars-item">
                                        <a href="shop.php">Accessories</a>
                                        <span>(100+)</span>
                                    </div>
                                </li>
                                <li>
                                    <div class="categories-bars-item">
                                        <a href="shop.php">Electronics & Computer</a>
                                        <span>(100+)</span>
                                    </div>
                                </li>
                                <li>
                                    <div class="categories-bars-item">
                                        <a href="shop.php">Laptops & Desktops</a>
                                        <span>(100+)</span>
                                    </div>
                                </li>
                                <li>
                                    <div class="categories-bars-item">
                                        <a href="shop.php">Mobiles & Tablets</a>
                                        <span>(100+)</span>
                                    </div>
                                </li>
                                <li>
                                    <div class="categories-bars-item">
                                        <a href="shop.php">SmartPhone & Smart TV</a>
                                        <span>(100+)</span>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </nav>
            </div>
            <div class="col-12 col-lg-9">
                <nav class="navbar navbar-expand-lg navbar-light bg-primary ">
                    <!--<a href="" class="navbar-brand d-block d-lg-none">-->
                        
                    <!--   <img src="img/logo.png" alt="Logo"> -->
                    <!--</a>-->
                    <button class="navbar-toggler ms-auto" type="button" data-bs-toggle="collapse"
                        data-bs-target="#navbarCollapse">
                        <span class="fa fa-bars fa-1x"></span>
                    </button>
                    <div class="collapse navbar-collapse" id="navbarCollapse">
                        <div class="navbar-nav ms-auto py-0">
                            <a href="index.php" class="nav-item nav-link">Home</a>
                            <a href="shop.php" class="nav-item nav-link">Shop</a>
                            <a href="cart.php" class="nav-item nav-link"> Your Cart </a>
                           
                            <a href="contact.php" class="nav-item nav-link me-2">Contact</a>
                            <div class="nav-item dropdown d-block d-lg-none mb-3">
                                <a href="#" class="nav-link" data-bs-toggle="dropdown"><span class="dropdown-toggle">All
                                        Category</span></a>
                                <div class="dropdown-menu m-0">
                                    <ul class="list-unstyled categories-bars">
                                        <li>
                                            <div class="categories-bars-item">
                                                <a href="shop.php">Accessories</a>
                                                <span>(100+)</span>
                                            </div>
                                        </li>
                                        <li>
                                            <div class="categories-bars-item">
                                                <a href="shop.php">Electronics & Computer</a>
                                                <span>(100+)</span>
                                            </div>
                                        </li>
                                        <li>
                                            <div class="categories-bars-item">
                                                <a href="shop.php">Laptops & Desktops</a>
                                                <span>(100+)</span>
                                            </div>
                                        </li>
                                        <li>
                                            <div class="categories-bars-item">
                                                <a href="shop.php">Mobiles & Tablets</a>
                                                <span>(100+)</span>
                                            </div>
                                        </li>
                                        <li>
                                            <div class="categories-bars-item">
                                                <a href="shop.php">SmartPhone & Smart TV</a>
                                                <span>(100+)</span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <a href="" class="btn btn-secondary rounded-pill py-2 px-4 px-lg-3 mb-3 mb-md-3 mb-lg-0"><i
                                class="fa fa-mobile-alt me-2"></i> +0123 456 7890</a>
                    </div>
                </nav>
            </div>
        </div>
    </div>
    <!-- Navbar & Hero End -->

    <!-- Single Page Header start -->
    <div class="container-fluid page-header py-5">
        <h1 class="text-center text-white display-6 wow fadeInUp" data-wow-delay="0.1s">Your Cart </h1>
        <ol class="breadcrumb justify-content-center mb-0 wow fadeInUp" data-wow-delay="0.3s">
            
        </ol>
    </div>
    <!-- Single Page Header End -->

    <!-- Cart Page Start -->
   
<!DOCTYPE html>
<html>
<head>
    <title>Your Cart - ApexUniversalMart</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
/* ===== APEX CART UNIQUE STYLE ===== */
.apex-cart *{
    box-sizing:border-box;
}

.apex-cart{
    font-family:Segoe UI, sans-serif;
    background:#f4f4f4;
    padding:40px 15px;
}

.apex-cart-header{
    text-align:center;
    font-size:26px;
    font-weight:600;
    color:rgb(242,139,0);
    margin-bottom:30px;
}

.apex-cart-container{
    max-width:1100px;
    margin:auto;
    background:white;
    padding:25px;
    border-radius:15px;
    box-shadow:0 8px 25px rgba(0,0,0,0.08);
}

.apex-cart table{
    width:100%;
    border-collapse:collapse;
}

.apex-cart th{
    background:rgb(242,139,0);
    color:white;
    padding:15px;
    text-align:center;
}

.apex-cart td{
    padding:15px;
    text-align:center;
    border-bottom:1px solid #eee;
}

.apex-cart img{
    width:70px;
    border-radius:10px;
}

.apex-cart input[type="number"]{
    width:60px;
    padding:6px;
    border:1px solid #ddd;
    border-radius:6px;
}

.apex-btn{
    background:rgb(242,139,0);
    color:white;
    padding:10px 18px;
    border:none;
    border-radius:6px;
    cursor:pointer;
    text-decoration:none;
    display:inline-block;
    transition:0.3s;
    font-weight:500;
}

.apex-btn:hover{
    background:rgb(220,120,0);
}

.apex-btn-danger{
    background:#e53935;
}

.apex-btn-danger:hover{
    background:#c62828;
}

.apex-total{
    text-align:right;
    font-size:22px;
    margin-top:20px;
    font-weight:600;
}

.apex-cart-actions{
    display:flex;
    justify-content:space-between;
    align-items:center;
    margin-top:25px;
    flex-wrap:wrap;
    gap:10px;
}

.apex-checkout{
    font-size:18px;
    padding:14px 30px;
    border-radius:30px;
}

/* Mobile Responsive */
@media(max-width:768px){
    .apex-cart table,
    .apex-cart thead,
    .apex-cart tbody,
    .apex-cart th,
    .apex-cart td,
    .apex-cart tr{
        display:block;
    }

    .apex-cart th{
        display:none;
    }

    .apex-cart td{
        text-align:right;
        position:relative;
        padding-left:50%;
    }

    .apex-cart td::before{
        content:attr(data-label);
        position:absolute;
        left:10px;
        font-weight:bold;
        color:rgb(242,139,0);
        text-align:left;
    }
}
</style>
</head>

<body>

<div class="apex-cart">

<div class="apex-cart-header">
 Your Cart
</div>

<div class="apex-cart-container">

<?php if(empty($cart)){ ?>
    <div style="text-align:center;padding:40px;">
        <p style="font-size:18px;">Your cart is empty</p>
        <br>
        <a href="shop.php" class="apex-btn">Go Shopping</a>
    </div>
<?php } else { ?>

<form method="POST">

<table>
<tr>
    <th>Image</th>
    <th>Product</th>
    <th>Price</th>
    <th>Qty</th>
    <th>Total</th>
    <th>Action</th>
</tr>

<?php
$grand_total = 0;

foreach($cart as $id => $qty):
$result = mysqli_query($conn, "SELECT * FROM products WHERE id=$id");
$product = mysqli_fetch_assoc($result);
if(!$product) continue;

$total = $product['price'] * $qty;
$grand_total += $total;
?>

<tr>
<td data-label="Image">
    <img src="Adminn/uploads/<?php echo $product['image']; ?>">
</td>

<td data-label="Product">
    <?php echo $product['name']; ?>
</td>

<td data-label="Price">
    <?php echo $product['price']." ".$product['currency']; ?>
</td>

<td data-label="Qty">
    <input type="number" name="qty[<?php echo $id; ?>]" value="<?php echo $qty; ?>" min="1">
</td>

<td data-label="Total">
    <?php echo $total." ".$product['currency']; ?>
</td>

<td data-label="Action">
    <a href="cart.php?remove=<?php echo $id; ?>" class="apex-btn apex-btn-danger">Remove</a>
</td>
</tr>

<?php endforeach; ?>
</table>

<div class="apex-cart-actions">

<button type="submit" name="update_cart" class="apex-btn">
Update Cart
</button>

<a href="checkout.php" class="apex-btn apex-checkout">
Proceed to Checkout
</a>

</div>

<div class="apex-total">
Grand Total: <?php echo $grand_total; ?>
</div>

</form>

<?php } ?>

</div>
</div>
</body>
</html>
    <!-- Cart Page End -->

    <!-- Footer Start -->
    <div class="container-fluid footer py-5 wow fadeIn" data-wow-delay="0.2s">
        <div class="container py-5">
            <div class="row g-4 rounded mb-5" style="background: rgba(255, 255, 255, .03);">
                <div class="col-md-6 col-lg-6 col-xl-3">
                    <div class="rounded p-4">
                        <div class="rounded-circle bg-secondary d-flex align-items-center justify-content-center mb-4"
                            style="width: 70px; height: 70px;">
                            <i class="fas fa-map-marker-alt fa-2x text-primary"></i>
                        </div>
                        <div>
                            <h4 class="text-white">Address</h4>
                            <p class="mb-2">123 Street New York.USA</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-6 col-lg-6 col-xl-3">
                    <div class="rounded p-4">
                        <div class="rounded-circle bg-secondary d-flex align-items-center justify-content-center mb-4"
                            style="width: 70px; height: 70px;">
                            <i class="fas fa-envelope fa-2x text-primary"></i>
                        </div>
                        <div>
                            <h4 class="text-white">Mail Us</h4>
                            <p class="mb-2">info@example.com</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-6 col-lg-6 col-xl-3">
                    <div class="rounded p-4">
                        <div class="rounded-circle bg-secondary d-flex align-items-center justify-content-center mb-4"
                            style="width: 70px; height: 70px;">
                            <i class="fa fa-phone-alt fa-2x text-primary"></i>
                        </div>
                        <div>
                            <h4 class="text-white">Telephone</h4>
                            <p class="mb-2">(+012) 3456 7890</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-6 col-lg-6 col-xl-3">
                    <div class="rounded p-4">
                        <div class="rounded-circle bg-secondary d-flex align-items-center justify-content-center mb-4"
                            style="width: 70px; height: 70px;">
                            <i class="fab fa-firefox-browser fa-2x text-primary"></i>
                        </div>
                        <div>
                            <h4 class="text-white">ApexUniversalMart</h4>
                            <p class="mb-2">(+012) 3456 7890</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row g-5">
                <div class="col-md-6 col-lg-6 col-xl-3">
                    <div class="footer-item d-flex flex-column">
                        <div class="footer-item">
                            <h4 class="text-primary mb-4">Newsletter</h4>
                            <
                            <div class="position-relative mx-auto rounded-pill">
                                <input class="form-control rounded-pill w-100 py-3 ps-4 pe-5" type="text"
                                    placeholder="Enter your email">
                                <button type="button"
                                    class="btn btn-primary rounded-pill position-absolute top-0 end-0 py-2 mt-2 me-2">SignUp</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-6 col-lg-6 col-xl-3">
                    <div class="footer-item d-flex flex-column">
                        <h4 class="text-primary mb-4">Customer Service</h4>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Contact Us</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Returns</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Order History</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Site Map</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Testimonials</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> My Account</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Unsubscribe Notification</a>
                    </div>
                </div>
                <div class="col-md-6 col-lg-6 col-xl-3">
                    <div class="footer-item d-flex flex-column">
                        <h4 class="text-primary mb-4">Information</h4>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> About Us</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Delivery infomation</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Privacy Policy</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Terms & Conditions</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Warranty</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> FAQ</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Seller Login</a>
                    </div>
                </div>
                <div class="col-md-6 col-lg-6 col-xl-3">
                    <div class="footer-item d-flex flex-column">
                        <h4 class="text-primary mb-4">Extras</h4>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Brands</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Gift Vouchers</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Affiliates</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Wishlist</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Order History</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Track Your Order</a>
                        <a href="#" class=""><i class="fas fa-angle-right me-2"></i> Track Your Order</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Footer End -->


    <!-- Copyright Start -->
  
    
    <!-- Copyright End -->


    <!-- Back to Top -->
    <a href="#" class="btn btn-primary btn-lg-square back-to-top"><i class="fa fa-arrow-up"></i></a>


    <!-- JavaScript Libraries -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="lib/wow/wow.min.js"></script>
    <script src="lib/owlcarousel/owl.carousel.min.js"></script>


    <!-- Template Javascript -->
    <script src="js/main.js"></script>
</body>

</html>