<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
$cartCount = 0;
if (isset($_SESSION['cart'])) {
    foreach ($_SESSION['cart'] as $item) {
        $cartCount += $item['quantity'];
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo isset($pageTitle) ? $pageTitle . " | ElderEase" : "ElderEase: Safety, Comfort, and Independence"; ?></title>
    <meta name="description" content="<?php echo $_SERVER['PROJECT_DESCRIPTION'] ?? 'Safety and independence for seniors at home.'; ?>">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
    <link rel="stylesheet" href="/assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-charcoal py-3">
    <div class="container">
        <a class="navbar-brand text-gold fw-bold" href="/">ElderEase</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto align-items-center">
                <li class="nav-item"><a class="nav-link" href="/">Home</a></li>
                <li class="nav-item"><a class="nav-link" href="/#products">Products</a></li>
                <li class="nav-item"><a class="nav-link" href="/about.php">Our Story</a></li>
                <li class="nav-item"><a class="nav-link" href="/faq.php">FAQ</a></li>
                <li class="nav-item ms-lg-3 mt-3 mt-lg-0">
                    <a href="/cart.php" class="btn btn-outline-gold position-relative rounded-pill px-3">
                        <i class="bi bi-cart3"></i> Cart
                        <span id="cart-count" class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger <?php echo $cartCount > 0 ? '' : 'd-none'; ?>">
                            <?php echo $cartCount; ?>
                        </span>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>
