/*------------------------------------------------*/
/* Current Year */
/*------------------------------------------------*/
// var currentYear = new Date().getFullYear()
// document.getElementById("current-year").innerHTML = currentYear;


/*------------------------------------------------*/
/* Mobile Navigation */
/*------------------------------------------------*/
// Mobile Navigation Variables
var headerNav = document.querySelector('.header__nav');
var openNav = document.querySelector('.nav-button--open');
var closeNav = document.querySelector('.nav-button--close');
var nav = document.getElementById("nav");
var account = document.querySelector('.header__account');

if (headerNav) {
    // Open Nav
    openNav.addEventListener('click', (event) => {
        event.preventDefault();
        nav.classList.add("nav-mobile");
        account.classList.add("show");
        openNav.classList.add("nav-button--hidden");
        closeNav.classList.remove("nav-button--hidden");
    });

    // Close Nav
    closeNav.addEventListener('click', (event) => {
        event.preventDefault();
        nav.classList.remove("nav-mobile");
        account.classList.remove("show");
        openNav.classList.remove("nav-button--hidden");
        closeNav.classList.add("nav-button--hidden");
    });
};


/*------------------------------------------------*/
/* System Messages */
/*------------------------------------------------*/
// Check if the systemMessage element exists before calling closeSystemMessage
var systemMessage = document.getElementById('systemMessage');
var timeoutId; // Variable to store the timeout ID

if (systemMessage) {
    closeSystemMessage();
}

function closeSystemMessage() {
    var countdown = systemMessage.querySelector('.system-message-countdown');
    var progress = countdown.querySelector('.system-message-progress');

    // Display the countdown bar
    countdown.style.display = 'block';

    var startTime = performance.now();
    var duration = 4000; // milliseconds

    function animate() {
        var currentTime = performance.now();
        var elapsed = currentTime - startTime;

        // Update the countdown bar and check if the time is up
        if (elapsed >= duration) {
            systemMessage.classList.add('close-animation');
            timeoutId = setTimeout(function () {
                systemMessage.style.display = 'none';
            }, 200); // Adjust duration to match CSS animation duration
        } else {
            var progressPercentage = (elapsed / duration) * 100;
            progress.style.width = progressPercentage + '%';
            requestAnimationFrame(animate);
        }
    }

    // Start the animation
    animate();
}

// Function for the close button
function closeMessageImmediately() {
    systemMessage.classList.add('close-animation');
    clearTimeout(timeoutId); // Clear the countdown timeout
    setTimeout(function () {
        systemMessage.style.display = 'none';
    }, 200); // Adjust duration to match CSS animation duration
}
