<?php
if(!isset($pageTitle)) $pageTitle = 'کیف‌لند';
if(!isset($settings)) $settings = SiteSettings::getInstance();
$cartCount   = getCartCount();
$currentUser = Auth::currentUser();
$currentPage = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="fa" dir="rtl" data-theme="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
    <title><?= htmlspecialchars($pageTitle) ?></title>
    <meta name="description" content="<?= htmlspecialchars($settings->get('meta_description','فروشگاه تخصصی کیف')) ?>">
    <meta name="theme-color" content="#10b981">
    <link rel="icon" href="uploads/logo/<?= htmlspecialchars($settings->get('site_favicon','favicon.ico')) ?>">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    <link href="https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
</head>
<body>

<!-- NAVBAR دسکتاپ -->
<header class="site-header" id="siteHeader">
    <nav class="navbar-inner">
        <a href="index.php" class="nav-logo">
            <span class="logo-icon"><i class="fas fa-shopping-bag"></i></span>
            <span class="logo-text"><?= htmlspecialchars($settings->get('site_name','کیف‌لند')) ?></span>
        </a>

        <ul class="nav-menu">
            <li><a href="index.php" class="nav-link <?= $currentPage=='index.php'?'active':'' ?>">خانه</a></li>
            <li><a href="products.php" class="nav-link <?= $currentPage=='products.php'?'active':'' ?>">محصولات</a></li>
            <li><a href="search.php" class="nav-link <?= $currentPage=='search.php'?'active':'' ?>">جستجو</a></li>
            <?php if(Auth::isLoggedIn()): ?>
            <li><a href="profile.php" class="nav-link <?= $currentPage=='profile.php'?'active':'' ?>">پروفایل</a></li>
            <?php if(Auth::isAdmin()): ?>
            <li><a href="admin/index.php" class="nav-link" style="color:var(--primary)"><i class="fas fa-cog"></i> پنل مدیریت</a></li>
            <?php endif; ?>
            <?php endif; ?>
        </ul>

        <div class="nav-end">
            <div class="nav-search" id="navSearch">
                <form action="search.php" method="GET">
                    <input type="text" name="q" placeholder="جستجو در محصولات..." value="<?= isset($_GET['q'])?htmlspecialchars($_GET['q']):'' ?>" autocomplete="off">
                    <button type="submit"><i class="fas fa-search"></i></button>
                </form>
            </div>
            <button class="nav-icon-btn" id="searchToggle" aria-label="جستجو"><i class="fas fa-search"></i></button>
            <button class="nav-icon-btn" id="themeToggle" aria-label="تغییر تم"><i class="fas fa-moon" id="themeIco"></i></button>
            <a href="cart.php" class="nav-icon-btn cart-btn" aria-label="سبد خرید">
                <i class="fas fa-shopping-bag"></i>
                <?php if($cartCount > 0): ?>
                <span class="cart-bubble" id="cartCount"><?= $cartCount ?></span>
                <?php else: ?>
                <span class="cart-bubble" id="cartCount" style="display:none">0</span>
                <?php endif; ?>
            </a>
            <?php if(Auth::isLoggedIn()): ?>
            <a href="profile.php" class="nav-avatar" title="<?= htmlspecialchars($currentUser['full_name']??'') ?>">
                <?= mb_substr($currentUser['full_name']??'ک', 0, 1) ?>
            </a>
            <?php else: ?>
            <a href="login.php" class="nav-login-btn"><i class="fas fa-sign-in-alt"></i><span>ورود</span></a>
            <?php endif; ?>
        </div>
    </nav>

    <!-- جستجوی موبایل -->
    <div class="mobile-search-bar" id="mobileSearchBar">
        <form action="search.php" method="GET" class="msb-inner">
            <button type="button" id="msbClose"><i class="fas fa-times"></i></button>
            <input type="text" name="q" placeholder="دنبال چی می‌گردی؟" id="msbInput" value="<?= isset($_GET['q'])?htmlspecialchars($_GET['q']):'' ?>" autocomplete="off">
            <button type="submit"><i class="fas fa-arrow-left"></i></button>
        </form>
        <div class="msb-suggest">
            <div class="msb-tags">
                <span class="msb-tag" onclick="doSearch('کیف چرمی')">کیف چرمی</span>
                <span class="msb-tag" onclick="doSearch('کوله پشتی')">کوله پشتی</span>
                <span class="msb-tag" onclick="doSearch('کیف اداری')">کیف اداری</span>
                <span class="msb-tag" onclick="doSearch('کیف ورزشی')">کیف ورزشی</span>
            </div>
        </div>
    </div>
</header>

<!-- ========================================
     نوار شیشه‌ای شناور موبایل
     شامل: خانه، جستجو، پروفایل/ورود، پنل ادمین
======================================== -->
<nav class="glass-bottom-nav" id="glassBottomNav">
    <a href="index.php" class="gnav-item <?= $currentPage=='index.php'?'active':'' ?>">
        <div class="gnav-icon-wrap">
            <i class="fas fa-home"></i>
        </div>
        <span>خانه</span>
    </a>
    <a href="products.php" class="gnav-item <?= $currentPage=='products.php'?'active':'' ?>">
        <div class="gnav-icon-wrap">
            <i class="fas fa-box-open"></i>
        </div>
        <span>محصولات</span>
    </a>
    <a href="search.php" class="gnav-item <?= $currentPage=='search.php'?'active':'' ?>">
        <div class="gnav-icon-wrap gnav-search-btn">
            <i class="fas fa-search"></i>
        </div>
        <span>جستجو</span>
    </a>
    <a href="cart.php" class="gnav-item <?= $currentPage=='cart.php'?'active':'' ?>" style="position:relative">
        <div class="gnav-icon-wrap">
            <i class="fas fa-shopping-bag"></i>
            <?php if($cartCount>0): ?><span class="gnav-badge"><?= $cartCount ?></span><?php endif; ?>
        </div>
        <span>سبد</span>
    </a>
    <?php if(Auth::isLoggedIn()): ?>
    <a href="profile.php" class="gnav-item <?= $currentPage=='profile.php'?'active':'' ?>">
        <div class="gnav-icon-wrap">
            <i class="fas fa-user"></i>
        </div>
        <span>پروفایل</span>
    </a>
    <?php if(Auth::isAdmin()): ?>
    <a href="admin/index.php" class="gnav-item gnav-admin">
        <div class="gnav-icon-wrap gnav-admin-icon">
            <i class="fas fa-crown"></i>
        </div>
        <span>ادمین</span>
    </a>
    <?php endif; ?>
    <?php else: ?>
    <a href="login.php" class="gnav-item <?= $currentPage=='login.php'?'active':'' ?>">
        <div class="gnav-icon-wrap">
            <i class="fas fa-right-to-bracket"></i>
        </div>
        <span>ورود</span>
    </a>
    <?php endif; ?>
</nav>

<div class="site-overlay" id="siteOverlay"></div>
<div class="toast-wrap" id="toastWrap"></div>

<main id="pageMain">
