'use strict';

(function () {
    function initHamburger() {
        const hamburger = document.getElementById('hamburger');
        const nav = document.getElementById('nav');

        if (!hamburger || !nav) {
            console.error('Hamburger or nav element not found!');
            return;
        }

        hamburger.addEventListener('click', function () {
            hamburger.classList.toggle('active');
            nav.classList.toggle('open');
        });

        // Close menu when clicking nav items on mobile
        const navButtons = nav.querySelectorAll('.neu-nav-btn');
        for (let i = 0; i < navButtons.length; i++) {
            navButtons[i].addEventListener('click', function () {
                if (window.innerWidth <= 768) {
                    hamburger.classList.remove('active');
                    nav.classList.remove('open');
                }
            });
        }

        // Close menu when clicking outside
        document.addEventListener('click', function (e) {
            if (window.innerWidth <= 768) {
                if (!nav.contains(e.target) && !hamburger.contains(e.target)) {
                    hamburger.classList.remove('active');
                    nav.classList.remove('open');
                }
            }
        });
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initHamburger);
    } else {
        initHamburger();
    }
})();
