document.addEventListener('DOMContentLoaded', function () {
    //  Don't show popups if already shown this session
    if (sessionStorage.getItem('wavypopup_shown') === 'true') {
        return;
    }

    //  Delay to allow DOM and injected popups to fully render
    setTimeout(function () {
        const modals = document.querySelectorAll('.wavypopup-modal');

        if (modals.length > 0) {
            modals.forEach(function(modal) {
                modal.style.display = 'block';
            });

            //  Set the session flag AFTER showing
            sessionStorage.setItem('wavypopup_shown', 'true');
        }

        //  Add close button functionality
        document.querySelectorAll('.wavypopup-close').forEach(function(btn) {
            btn.addEventListener('click', function () {
                btn.closest('.wavypopup-modal').style.display = 'none';
            });
        });

        //  Add overlay click to close
        document.querySelectorAll('.wavypopup-overlay').forEach(function(overlay) {
            overlay.addEventListener('click', function () {
                overlay.closest('.wavypopup-modal').style.display = 'none';
            });
        });

    }, 1000); // Wait for 1s to ensure popup is injected
});

jQuery( document ).ready( function() {

    if ( jQuery('#wavypopup-confetti').length ) {
        const wprConfetti = confetti.create( document.getElementById('wavypopup-confetti'), {
            resize: true
        });

        setTimeout(function () {
            // 🎉 From top-right corner
            wprConfetti({
                particleCount: 150,
                origin: { x: 1, y: 0 }, // top-right
                gravity: 0.3,
                spread: 50,
                ticks: 150,
                angle: 240, // shoot diagonally downward to the left
                startVelocity: 60,
                colors: [
                    '#0e6ef1',
                    '#f5b800',
                    '#ff344c',
                    '#98e027',
                    '#9900f1',
                ],
            });
        }, 1500);

        setTimeout(function () {
            // 🎉 From top-left corner
            wprConfetti({
                particleCount: 150,
                origin: { x: 0, y: 0 }, // top-left
                gravity: 0.3,
                spread: 50,
                ticks: 200,
                angle: 300, // shoot diagonally downward to the right
                startVelocity: 60,
                colors: [
                    '#0e6ef1',
                    '#f5b800',
                    '#ff344c',
                    '#98e027',
                    '#9900f1',
                ],
            });
        }, 1900);

    }

    
});
