<!-- Sidebar de navigation -->
<nav class="sidebar" role="navigation" aria-label="Navigation principale">
    <a href="/" class="logo" aria-label="Retour à l'accueil">
        <img src="img/logo.png" alt="Logo <?php echo SITE_NAME; ?>">
    </a>

    <?php
    // Détecter la page courante et ses paramètres
    $currentPage = basename($_SERVER['PHP_SELF']);
    $currentCategoryId = isset($_GET['id']) ? intval($_GET['id']) : null;
    $currentQuery = isset($_GET['q']) ? trim($_GET['q']) : '';
    $isTagSearch = !empty($currentQuery) && substr($currentQuery, 0, 1) === '#';
    $currentTag = $isTagSearch ? substr($currentQuery, 1) : '';
    ?>

    <div class="sidebar-nav">
        <a href="/" class="nav-item <?php echo ($currentPage === 'index.php') ? 'active' : ''; ?>" data-title="Accueil" aria-current="<?php echo ($currentPage === 'index.php') ? 'page' : 'false'; ?>">
            <i class="fas fa-home" aria-hidden="true"></i> <span>Accueil</span>
        </a>

        <?php if (!defined('HERO_TYPE') || HERO_TYPE === 'live'): ?>
        <a href="direct.php" class="nav-item <?php echo ($currentPage === 'direct.php') ? 'active' : ''; ?>" data-title="Direct" aria-current="<?php echo ($currentPage === 'direct.php') ? 'page' : 'false'; ?>">
            <i class="fas fa-broadcast-tower" aria-hidden="true"></i> <span>Direct</span>
        </a>
        <?php endif; ?>

        <?php if (defined('DONATIONS_ENABLED') && DONATIONS_ENABLED): ?>
        <a href="dons.php" class="nav-item donation-nav-link <?php echo ($currentPage === 'dons.php') ? 'active' : ''; ?>" data-title="Soutenir" aria-current="<?php echo ($currentPage === 'dons.php') ? 'page' : 'false'; ?>">
            <i class="fas fa-heart" aria-hidden="true"></i> <span>Soutenir</span>
        </a>
        <?php endif; ?>

        <div class="nav-divider"></div>

        <?php
        // Afficher les catégories prioritaires
        if (defined('PRIORITY_CATEGORIES') && !empty(PRIORITY_CATEGORIES)) {
            // Tableau associatif des icônes pour les catégories
            $categoryIcons = [
                1 => 'fas fa-music',            // Musique
                2 => 'fas fa-film',             // Films
                3 => 'fas fa-car',              // Véhicules
                4 => 'fas fa-palette',          // Jeux
                5 => 'fas fa-running',          // Sport
                6 => 'fas fa-laugh',            // Humour
                7 => 'fas fa-gamepad',          // Art
                8 => 'fas fa-person',           // Personnalités
                9 => 'fas fa-face-grin-tears',  // Comédie
                10 => 'fas fa-tv',              // Divertissement
                11 => 'fas fa-globe',           // Actualité & Politique
                12 => 'fas fa-chalkboard-user', // Tutoriel
                13 => 'fas fa-graduation-cap',  // Education
                14 => 'fas fa-fist-raised',     // Activisme
                15 => 'fas fa-microscope',      // Science & Technologie
                16 => 'fas fa-paw',             // Animaux
                17 => 'fas fa-child',           // Enfants
                18 => 'fas fa-utensils'         // Cuisine
            ];

            foreach (PRIORITY_CATEGORIES as $id => $name) {
                $isActive = ($currentPage === 'categories.php' && $currentCategoryId === $id);
                $icon = isset($categoryIcons[$id]) ? $categoryIcons[$id] : 'fas fa-folder';
                echo '<a href="categories.php?id=' . $id . '" class="nav-item ' . ($isActive ? 'active' : '') . '" data-title="' . htmlspecialchars($name) . '" aria-current="' . ($isActive ? 'page' : 'false') . '">';
                echo '<i class="' . $icon . '" aria-hidden="true"></i> <span>' . htmlspecialchars($name) . '</span>';
                echo '</a>';
            }
        }
        ?>

        <div class="nav-divider"></div>

        <div class="category-title" role="heading" aria-level="2">
            <i class="fas fa-hashtag" aria-hidden="true"></i> <span>Hashtags</span>
        </div>

        <?php
        if (defined('IMPORTANT_TAGS') && !empty(IMPORTANT_TAGS)):
            foreach (IMPORTANT_TAGS as $tag):
                $encodedTag = urlencode('#' . $tag);
                $isActive = ($isTagSearch && strtolower($currentTag) === strtolower($tag));
        ?>
        <a href="recherche.php?q=<?php echo $encodedTag; ?>" class="tag-item <?php echo $isActive ? 'active' : ''; ?>" data-title="<?php echo htmlspecialchars($tag); ?>" aria-current="<?php echo $isActive ? 'page' : 'false'; ?>">
            <i class="fas fa-hashtag tag-icon" aria-hidden="true"></i> <span><?php echo htmlspecialchars($tag); ?></span>
        </a>
        <?php
            endforeach;
        endif;
        ?>
    </div>

</nav>
