<?php 
$isLoggedIn = $isLoggedIn ?? \App\Core\View::isAuthenticated();
$isAdmin = $isAdmin ?? \App\Core\View::isAdmin();
$user = $user ?? \App\Core\View::currentUser();
?>
<style>
#catalogMenu {
    display: none;
}
#catalogDropdown.active #catalogMenu {
    display: block;
}
</style>
<header class="header">
    <div class="header__top">
        <div class="container header__top-content">
            <a href="/" class="logo">AETERNA</a>

            <div class="search-catalog">
                <div class="catalog-dropdown" id="catalogDropdown">
                    Все категории <span>&#9660;</span>
                    <div class="catalog-dropdown__menu" id="catalogMenu">
                        <ul>
                            <li><a href="/catalog">Все товары</a></li>
                            <?php if (!empty($categories)): ?>
                                <?php foreach ($categories as $category): ?>
                                <li><a href="/catalog?category=<?= $category['category_id'] ?>"><?= htmlspecialchars($category['name']) ?></a></li>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </ul>
                    </div>
                </div>
                <div class="search-box">
                    <form method="GET" action="/catalog" style="display: flex; width: 100%;">
                        <input type="text" name="search" placeholder="Поиск товаров" style="border: none; width: 100%; padding: 10px;">
                        <button type="submit" style="background: none; border: none; cursor: pointer;">
                            <span class="search-icon"><i class="fas fa-search"></i></span>
                        </button>
                    </form>
                </div>
            </div>

            <div class="header__icons--top">
                <?php if ($isLoggedIn): ?>
                <?php if (!$isAdmin): ?>
                <a href="/cart" class="icon cart-icon">
                    <i class="fas fa-shopping-cart"></i>
                    <span class="cart-count">0</span>
                </a>
                <?php endif; ?>

                <a href="/logout" style="font-size: 14px; color: #666; text-decoration: none; margin-left: 15px;">
                    <i class="fas fa-sign-out-alt"></i> Выйти
                </a>
                <?php else: ?>
                <a href="/login" class="icon"><i class="far fa-user"></i></a>
                <a href="/login" style="font-size: 12px; color: #666; margin-left: 5px;">Войти</a>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <div class="header__bottom">
        <div class="container header__bottom-content">
            <div class="catalog-menu">
                <a href="/catalog" class="catalog-link">
                    <span class="catalog-lines">☰</span>
                    Каталог
                </a>
            </div>

            <nav class="nav">
                <ul class="nav-list">
                    <li><a href="/">Главная</a></li>
                    <li><a href="/services">Услуги</a></li>
                    <li><a href="/delivery">Доставка и оплата</a></li>
                    <li><a href="/warranty">Гарантия</a></li>
                    <li><a href="#footer">Контакты</a></li>
                </ul>
            </nav>
            <div class="header-phone">+7(912)999-12-23</div>
        </div>
    </div>
</header>
