function hide(id) {
    let htmlChange = document.getElementById('show-' + id);
    htmlChange.style.display = "none";
    htmlChange.id = `hide-${id}`;
    let buttonChange = document.getElementById(id);
    buttonChange.onclick = function() { show(id); };
}

function show(id) {
    let htmlChange = document.getElementById('hide-' + id);
    htmlChange.style.display = "block";
    htmlChange.id = `show-${id}`;
    let buttonChange = document.getElementById(id);
    buttonChange.onclick = function() { hide(id); };
}

// Fonction pour supprimer le message d'alerte après 5 secondes
document.addEventListener('DOMContentLoaded', function() {
    let messages = document.querySelector('.flash_messages')
    if (messages) {
        setTimeout(function() {
                messages.style.opacity = 0;
                setTimeout(function() {
                    messages.style.display = 'none';
                }, 1000);
            }, 5000);
    }

    // Theme toggle setup
    var toggle = document.getElementById('themeToggle');
    var themeLink = document.getElementById('theme-css');
    function applyTheme(theme) {
        document.documentElement.setAttribute('data-theme', theme);
        if (theme === 'light') {
            if (themeLink) themeLink.href = themeLink.href.replace('colors_dark.css', 'colors_light.css');
        } else {
            if (themeLink) themeLink.href = themeLink.href.replace('colors_light.css', 'colors_dark.css');
        }
        var icon = toggle && toggle.querySelector('i');
        if (icon) {
            icon.classList.remove('fa-sun','fa-moon');
            icon.classList.add(theme === 'light' ? 'fa-moon' : 'fa-sun');
        }
        if (toggle) {
            toggle.setAttribute('aria-pressed', theme === 'dark' ? 'true' : 'false');
            toggle.setAttribute('aria-label', theme === 'light' ? 'Activer le thème sombre' : 'Activer le thème clair');
            toggle.title = toggle.getAttribute('aria-label');
        }
    }
    try {
        var current = document.documentElement.getAttribute('data-theme') || 'dark';
        applyTheme(current);
        if (toggle) {
            toggle.addEventListener('click', function() {
                var next = (document.documentElement.getAttribute('data-theme') === 'light') ? 'dark' : 'light';
                localStorage.setItem('pdz-theme', next);
                applyTheme(next);
            });
        }
    } catch(e) {}
});

// Fonction pour générer des flocons de neige
function createSnowflake() {
    const snowflake = document.createElement('div');
    snowflake.classList.add('snowflake');
    snowflake.textContent = '•';

    snowflake.style.left = `${Math.random() * 100}vw`;

    const size = Math.random() * 1.5 + 0.5; 
    snowflake.style.fontSize = `${size}em`;

    const duration = Math.random() * 5 + 5;
    snowflake.style.animationDuration = `${duration}s`;

    document.body.appendChild(snowflake);

    setTimeout(() => {
        snowflake.remove();
    }, duration * 1000);
}

// On génère les flocons toutes les 300ms
setInterval(createSnowflake, 300);