// ============================================================
// BENGALI E-COMMERCE — MAIN JS  (global, runs on every page)
// ============================================================

document.addEventListener('DOMContentLoaded', () => {

    // ── Hamburger Menu ──────────────────────────────────────
    const hamburger = document.getElementById('hamburger');
    const mainNav   = document.getElementById('mainNav');
    if (hamburger && mainNav) {
        hamburger.addEventListener('click', () => {
            const open = mainNav.classList.toggle('open');
            hamburger.classList.toggle('active', open);
            hamburger.setAttribute('aria-expanded', open);
        });
        // Close on outside click
        document.addEventListener('click', e => {
            if (!hamburger.contains(e.target) && !mainNav.contains(e.target)) {
                mainNav.classList.remove('open');
                hamburger.classList.remove('active');
            }
        });
        // Close when a nav link is clicked
        mainNav.querySelectorAll('.nav-link').forEach(link => {
            link.addEventListener('click', () => {
                mainNav.classList.remove('open');
                hamburger.classList.remove('active');
            });
        });
    }

    // ── Confirm-delete links ─────────────────────────────────
    document.querySelectorAll('[data-confirm]').forEach(el => {
        el.addEventListener('click', function (e) {
            if (!confirm(this.dataset.confirm || 'আপনি কি নিশ্চিত?')) e.preventDefault();
        });
    });

    // ── Auto-hide alerts after 4 s ───────────────────────────
    setTimeout(() => {
        document.querySelectorAll('.alert').forEach(a => {
            a.style.transition = 'opacity .5s';
            a.style.opacity = '0';
            setTimeout(() => a.remove(), 500);
        });
    }, 4000);

});
