<!-- Header avec barre de recherche et icônes -->
<header class="header" role="banner">
    <div class="search-container">
        <form action="recherche.php" method="get" role="search" aria-label="Recherche de vidéos">
            <label for="search-input" class="sr-only">Rechercher des vidéos</label>
            <input type="text" id="search-input" name="q" placeholder="Rechercher..." aria-describedby="search-help">
            <button type="submit" aria-label="Lancer la recherche">
                <i class="fas fa-search" aria-hidden="true"></i>
            </button>
            <div id="search-help" class="sr-only">Tapez vos mots-clés pour rechercher des vidéos</div>
        </form>
    </div>

    <nav class="social-icons" aria-label="Réseaux sociaux">
        <?php if (!empty(MASTODON_URL) && MASTODON_URL !== '#'): ?>
        <a target="_blank" rel="me noreferrer" href="<?php echo MASTODON_URL; ?>" class="icon-button" aria-label="Suivre sur Mastodon">
            <i class="fab fa-mastodon icon-mastodon" aria-hidden="true"></i>
        </a>
        <?php endif; ?>

        <?php if (!empty(INSTAGRAM_URL) && INSTAGRAM_URL !== '#'): ?>
        <a target="_blank" rel="noreferrer" href="<?php echo INSTAGRAM_URL; ?>" class="icon-button" aria-label="Suivre sur Instagram">
            <i class="fab fa-instagram icon-instagram" aria-hidden="true"></i>
        </a>
        <?php endif; ?>

        <?php if (!empty(TIKTOK_URL) && TIKTOK_URL !== '#'): ?>
        <a target="_blank" rel="noreferrer" href="<?php echo TIKTOK_URL; ?>" class="icon-button" aria-label="Suivre sur TikTok">
            <i class="fab fa-tiktok icon-tiktok" aria-hidden="true"></i>
        </a>
        <?php endif; ?>

        <?php
        // Vérifier s'il y a au moins un réseau social dans le menu déroulant
        $hasDropdownSocial = (!empty(FACEBOOK_URL) && FACEBOOK_URL !== '#') ||
                            (!empty(YOUTUBE_URL) && YOUTUBE_URL !== '#') ||
                            (!empty(X_URL) && X_URL !== '#');

        if ($hasDropdownSocial):
        ?>
        <div class="more-social-container">
            <button type="button" class="icon-button more-social-toggle" aria-expanded="false" aria-controls="social-dropdown" aria-label="Voir plus de réseaux sociaux">
                <i class="fas fa-ellipsis-h" aria-hidden="true"></i>
            </button>
            <div id="social-dropdown" class="more-social-dropdown" role="menu">
                <?php if (!empty(FACEBOOK_URL) && FACEBOOK_URL !== '#'): ?>
                <a target="_blank" rel="noreferrer" href="<?php echo FACEBOOK_URL; ?>" class="more-social-item" role="menuitem">
                    <i class="fab fa-facebook icon-facebook" aria-hidden="true"></i> Facebook
                </a>
                <?php endif; ?>

                <?php if (!empty(YOUTUBE_URL) && YOUTUBE_URL !== '#'): ?>
                <a target="_blank" rel="noreferrer" href="<?php echo YOUTUBE_URL; ?>" class="more-social-item" role="menuitem">
                    <i class="fab fa-youtube icon-youtube" aria-hidden="true"></i> YouTube
                </a>
                <?php endif; ?>

                <?php if (!empty(X_URL) && X_URL !== '#'): ?>
                <a target="_blank" rel="noreferrer" href="<?php echo X_URL; ?>" class="more-social-item" role="menuitem">
                    <i class="fab fa-x-twitter icon-x" aria-hidden="true"></i> X
                </a>
                <?php endif; ?>
            </div>
        </div>
        <?php endif; ?>
    </nav>

    <div class="action-icons">
        <?php if (defined('DONATIONS_ENABLED') && DONATIONS_ENABLED): ?>
        <a href="dons.php" class="icon-button donation-link" aria-label="Soutenir <?php echo SITE_NAME; ?>" title="Faire un don">
            <i class="fas fa-heart" aria-hidden="true"></i>
        </a>
        <?php endif; ?>
        <button id="theme-toggle" class="icon-button" aria-label="Basculer entre mode clair et sombre" title="Changer le thème">
            <i class="fas fa-sun" aria-hidden="true"></i>
        </button>
        <button id="install-pwa" class="icon-button install-pwa-button" style="display: none;" nonce="<?php echo getCspNonce(); ?>" aria-label="Installer l'application">
            <i class="fas fa-download" aria-hidden="true"></i>
        </button>
        <button class="mobile-menu-toggle" aria-expanded="false" aria-controls="mobile-menu" aria-label="Ouvrir le menu de navigation">
            <i class="fas fa-bars" aria-hidden="true"></i>
        </button>
    </div>
</header>
