<?php
// includes/header.php
require_once __DIR__ . '/../config/database.php';
$settings    = getAllSettings($pdo);
$siteName    = $settings['site_name'] ?? 'বাংলা শপ';
$menus       = $pdo->query("SELECT * FROM menus ORDER BY position ASC")->fetchAll();
$currentPage = basename($_SERVER['PHP_SELF']);
$cartCount   = 0;
if (isset($_SESSION['checkout_items'])) {
    foreach ($_SESSION['checkout_items'] as $ci) $cartCount += (int)$ci['quantity'];
}
?>
<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="<?= e($siteName) ?> — বাংলাদেশের সেরা অনলাইন শপিং">
<meta name="theme-color" content="#1A2A4F">
<title><?= e($siteName) ?></title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/assets/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
</head>
<body>

<!-- Top Bar (desktop only via CSS) -->
<div class="top-bar">
    <div class="container">
        <span><i class="fas fa-phone"></i> <?= e($settings['contact_phone'] ?? '') ?></span>
        <span><i class="fas fa-envelope"></i> <?= e($settings['contact_email'] ?? '') ?></span>
    </div>
</div>

<!-- Main Header -->
<header class="main-header">
    <div class="container header-inner">

        <!-- Logo -->
        <a href="<?= BASE_URL ?>/index.php" class="logo">
            <?php if (!empty($settings['site_logo'])): ?>
                <img src="<?= UPLOADS_URL . e($settings['site_logo']) ?>" alt="<?= e($siteName) ?>">
            <?php else: ?>
                <span class="logo-text"><?= e($siteName) ?></span>
            <?php endif; ?>
        </a>

        <!-- Desktop Nav -->
        <nav class="main-nav" id="mainNav" role="navigation" aria-label="প্রধান মেনু">
            <?php foreach ($menus as $menu): ?>
                <a href="<?= e($menu['link']) ?>"
                   class="nav-link <?= $currentPage === basename($menu['link']) ? 'active' : '' ?>">
                    <?= e($menu['name']) ?>
                </a>
            <?php endforeach; ?>
        </nav>

        <!-- Right Icons -->
        <div class="header-actions">
            <?php if (isLoggedIn()): ?>
                <?php if (isAdmin()): ?>
                    <a href="<?= BASE_URL ?>/admin/index.php" class="user-btn" title="অ্যাডমিন প্যানেল">
                        <i class="fas fa-user-shield"></i>
                    </a>
                <?php elseif (isInvestor()): ?>
                    <a href="<?= BASE_URL ?>/investor-dashboard.php" class="user-btn" title="ইনভেস্টর ড্যাশবোর্ড">
                        <i class="fas fa-chart-line"></i>
                    </a>
                <?php else: ?>
                    <a href="<?= BASE_URL ?>/user-dashboard.php" class="user-btn" title="আমার অ্যাকাউন্ট">
                        <i class="fas fa-user"></i>
                    </a>
                <?php endif; ?>
                <a href="<?= BASE_URL ?>/logout.php" class="user-btn logout-btn" title="লগআউট">
                    <i class="fas fa-sign-out-alt"></i>
                </a>
            <?php else: ?>
                <a href="<?= BASE_URL ?>/login.php" class="user-btn" title="লগইন">
                    <i class="fas fa-user"></i>
                </a>
            <?php endif; ?>

            <a href="<?= BASE_URL ?>/checkout.php" class="cart-btn" title="চেকআউট">
                <i class="fas fa-shopping-bag"></i>
                <?php if ($cartCount > 0): ?>
                    <span class="cart-count"><?= $cartCount ?></span>
                <?php endif; ?>
            </a>

            <!-- Hamburger (mobile) -->
            <button class="hamburger" id="hamburger"
                    aria-controls="mainNav" aria-expanded="false" aria-label="মেনু">
                <span></span><span></span><span></span>
            </button>
        </div>

    </div>
</header>
