<?php
/**
 * Customer Header Template
 * File: templates/layouts/customer/header.php
 * Description: Main header navigation for customer dashboard and pages
 */

// Ensure user is logged in
if (!isset($_SESSION['user_id'])) {
    redirect('/auth/login.php');
}

// Get current user info
$user_name = $_SESSION['first_name'] ?? 'Customer';
$user_email = $_SESSION['user_email'] ?? '';
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="<?= asset('assets/images/favicon.png') ?>">
    <title><?= $page_title ?? 'rentidium' ?> - Nigeria's Premier Rental Marketplace</title>
    
    <!-- CSS Files -->
    <link href="<?= asset('assets/plugins/aos/aos.min.css') ?>" rel="stylesheet">
    <link href="<?= asset('assets/plugins/bootstrap/css/bootstrap.min.css') ?>" rel="stylesheet">
    <link href="<?= asset('assets/plugins/fontawesome/css/all.min.css') ?>" rel="stylesheet">
    <link href="<?= asset('assets/plugins/OwlCarousel2/css/owl.carousel.min.css') ?>" rel="stylesheet">
    <link href="<?= asset('assets/plugins/OwlCarousel2/css/owl.theme.default.min.css') ?>" rel="stylesheet">
    <link href="<?= asset('assets/plugins/select2/select2.min.css') ?>" rel="stylesheet">
    <link href="<?= asset('assets/plugins/select2-bootstrap-5/select2-bootstrap-5-theme.min.css') ?>" rel="stylesheet">
    <link href="<?= asset('assets/css/style.css') ?>" rel="stylesheet">
</head>
<body>
    <!-- Start Navbar -->
    <nav class="navbar navbar-expand-lg navbar-light sticky-top">
        <div class="container">
            <!-- Logo -->
            <a class="navbar-brand m-0" href="<?= url('/public/index.php') ?>">
                <img class="logo-white" src="<?= asset('assets/images/logo-white.png') ?>" alt="rentidium">
                <img class="logo-dark" src="<?= asset('assets/images/logo.png') ?>" alt="rentidium">
            </a>
            
            <div class="d-flex order-lg-2">
                <!-- Favorites Button -->
                <a href="<?= url('/customer/favorites.php') ?>" 
                   class="d-flex align-items-center justify-content-center p-0 btn-user position-relative" 
                   data-bs-toggle="tooltip" 
                   data-bs-placement="bottom" 
                   data-bs-title="Favorites">
                    <i class="fa-solid fa-heart"></i>
                    <span class="align-items-center bg-primary d-flex end-0 fs-11 justify-content-center nav-count position-absolute rounded-circle text-white">
                        <?= get_favorites_count() ?>
                    </span>
                </a>
                
                <!-- User Dropdown -->
                <div class="dropdown">
                    <button class="d-flex align-items-center justify-content-center p-0 btn-user dropdown-toggle" 
                            type="button" 
                            id="userDropdown" 
                            data-bs-toggle="dropdown" 
                            aria-expanded="false">
                        <i class="fa-solid fa-user"></i>
                    </button>
                    <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                        <li class="dropdown-header">
                            <strong><?= esc($user_name) ?></strong>
                            <br>
                            <small class="text-muted"><?= esc($user_email) ?></small>
                        </li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="<?= url('/customer/index.php') ?>">
                            <i class="fa-solid fa-gauge me-2"></i>Dashboard
                        </a></li>
                        <li><a class="dropdown-item" href="<?= url('/customer/profile.php') ?>">
                            <i class="fa-solid fa-user me-2"></i>My Profile
                        </a></li>
                        <li><a class="dropdown-item" href="<?= url('/customer/orders.php') ?>">
                            <i class="fa-solid fa-shopping-bag me-2"></i>My Orders
                        </a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item text-danger" href="<?= url('../auth/logout.php') ?>">
                            <i class="fa-solid fa-sign-out-alt me-2"></i>Logout
                        </a></li>
                    </ul>
                </div>
                
                <!-- Theme Toggle -->
                <button type="button" id="themeToggleBtn" class="align-items-center bg-transparent border-0 btn-user d-flex justify-content-center p-0">
                    <i class="fa-solid fa-moon"></i>
                </button>
                
                <!-- Mobile Toggle -->
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span id="nav-icon">
                        <span></span>
                        <span></span>
                        <span></span>
                    </span>
                </button>
            </div>
            
            <!-- Navigation Menu -->
            <div class="collapse navbar-collapse" id="navbarContent">
                <ul class="navbar-nav m-auto mb-2 mb-lg-0">
                    <li class="nav-item">
                        <a class="nav-link <?= is_active_page('index') ?>" href="<?= url('/public/index.php') ?>">Home</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= is_active_page('browse') ?>" href="<?= url('/customer/browse.php') ?>">Browse Items</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= is_active_page('orders') ?>" href="<?= url('/customer/orders.php') ?>">My Orders</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= url('/public/about.php') ?>">About</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="<?= url('/public/contact.php') ?>">Contact</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <!-- End Navbar -->
    
    <?php
    // Display flash messages if any
    if (has_flash('success')): ?>
        <div class="container mt-3">
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="fa-solid fa-check-circle me-2"></i>
                <?= flash('success') ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        </div>
    <?php endif; ?>
    
    <?php if (has_flash('error')): ?>
        <div class="container mt-3">
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <i class="fa-solid fa-exclamation-circle me-2"></i>
                <?= flash('error') ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        </div>
    <?php endif; ?>
    
    <?php if (has_flash('warning')): ?>
        <div class="container mt-3">
            <div class="alert alert-warning alert-dismissible fade show" role="alert">
                <i class="fa-solid fa-exclamation-triangle me-2"></i>
                <?= flash('warning') ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        </div>
    <?php endif; ?>
    
    <?php if (has_flash('info')): ?>
        <div class="container mt-3">
            <div class="alert alert-info alert-dismissible fade show" role="alert">
                <i class="fa-solid fa-info-circle me-2"></i>
                <?= flash('info') ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        </div>
    <?php endif; ?>
    
    <!-- Main Content Starts Here -->