document.addEventListener('DOMContentLoaded', function () {
    const siteHeader = document.getElementById('siteHeader');
    const mobileMenuBtn = document.getElementById('mobileMenuBtn');
    const primaryNavigation = document.getElementById('primaryNavigation');

    function updateHeaderState() {
        if (!siteHeader) {
            return;
        }

        siteHeader.classList.toggle(
            'scrolled',
            window.scrollY > 15
        );
    }

    updateHeaderState();

    window.addEventListener('scroll', updateHeaderState, {
        passive: true
    });

    if (mobileMenuBtn && primaryNavigation) {
        mobileMenuBtn.addEventListener('click', function () {
            const isOpen = primaryNavigation.classList.toggle('open');

            mobileMenuBtn.setAttribute(
                'aria-expanded',
                isOpen ? 'true' : 'false'
            );

            document.body.classList.toggle('menu-open', isOpen);
        });

        primaryNavigation.querySelectorAll('a').forEach(function (link) {
            link.addEventListener('click', function () {
                primaryNavigation.classList.remove('open');
                document.body.classList.remove('menu-open');

                mobileMenuBtn.setAttribute(
                    'aria-expanded',
                    'false'
                );
            });
        });
    }

    const conferenceDate = new Date('2026-07-23T08:30:00+02:00');

    const daysElement = document.querySelector('[data-countdown-days]');
    const hoursElement = document.querySelector('[data-countdown-hours]');
    const minutesElement = document.querySelector('[data-countdown-minutes]');
    const secondsElement = document.querySelector('[data-countdown-seconds]');

    function pad(value) {
        return String(value).padStart(2, '0');
    }

    function updateCountdown() {
        if (
            !daysElement ||
            !hoursElement ||
            !minutesElement ||
            !secondsElement
        ) {
            return;
        }

        const now = new Date();
        const difference = conferenceDate.getTime() - now.getTime();

        if (difference <= 0) {
            daysElement.textContent = '00';
            hoursElement.textContent = '00';
            minutesElement.textContent = '00';
            secondsElement.textContent = '00';

            return;
        }

        const totalSeconds = Math.floor(difference / 1000);
        const days = Math.floor(totalSeconds / 86400);
        const hours = Math.floor((totalSeconds % 86400) / 3600);
        const minutes = Math.floor((totalSeconds % 3600) / 60);
        const seconds = totalSeconds % 60;

        daysElement.textContent = pad(days);
        hoursElement.textContent = pad(hours);
        minutesElement.textContent = pad(minutes);
        secondsElement.textContent = pad(seconds);
    }

    updateCountdown();

    window.setInterval(updateCountdown, 1000);
});