const mobileCart = $('#mobile-cart');
const mobileCartOverlay = $('#mobile-cart-overlay');
const mobileCartClose = $('#mobile-cart-close');
const mobileCartContinue = $('#mobile-cart-continue');

function closeMobileCart() {
    mobileCart.removeClass('mobile-cart--opened');
}

function openMobileCart() {
    mobileCart.addClass('mobile-cart--opened');
}

function checkIfProductIsAdded() {
    if (mobileCart.length) {
        const notificationText = $('.w-notification .panel-body').text();
        const triggerMessage = mobileCart.data('messageTrigger');

        console.log(notificationText);
        console.log(triggerMessage);
        console.log(notificationText === triggerMessage);

        if (notificationText.includes(triggerMessage)) {
            openMobileCart();
        }
    }
}

checkIfProductIsAdded();

mobileCartOverlay.add(mobileCartClose).add(mobileCartContinue).on('click', function () {
    closeMobileCart();
});

$(document).ready(function(){
    function checkWidth() {
        var screenWidth = $(window).width();
        if (screenWidth < 960) {
            $('.productfilter .panel-body').addClass('is-collapsed');
            $('.productfilter .panel-heading .button').addClass('is-closed');
        } else {
            $('.productfilter .panel-body').removeClass('is-collapsed');
            $('.productfilter .panel-heading .button').removeClass('is-closed');
        }
    }

    checkWidth();

    $(window).resize(function() {
        checkWidth();
    });
});

$(document).ready(function() {
    $('.toggle-btn').click(function() {
        $(this).toggleClass('toggle-btn--revealed-desktop');
        
        // Toggle between the buttons
        $('.button.xsmall').find('.icon-c, .icon-o').toggleClass('is-hidden');
    });
});

// $(document).ready(function() {
//     // Function to check screen width and apply functionality
//     function checkScreenWidth() {
//         // Check if screen width is less than or equal to 768px
//         if ($(window).width() <= 768) {
//             // Check if there are more than 12 images
//             if ($('.productLinkItem').length > 12) {
//                 // Show the "+ Se mere" button
//                 $('#seMereBtn').show();

//                 // Hide images beyond the first 12
//                 $('.productLinkItem:nth-child(n+12)').hide();
//             }

//             // Toggle functionality for the "+ Se mere" button
//             $('#seMereBtn').click(function(e) {
//                 e.preventDefault();
//                 $('.productLinks').toggleClass('expanded');
//                 if ($(this).text() === '+ Se mere') {
//                     $(this).text('- Se mindre');
//                 } else {
//                     $(this).text('+ Se mere');
//                 }
//             });
//         } else {
//             // If screen width is greater than 768px, hide the button and show all images
//             $('#seMereBtn').hide();
//             $('.productLinkItem').show();
//         }
//     }

//     // Call the function on document ready
//     checkScreenWidth();

//     // Call the function on window resize
//     $(window).resize(function() {
//         checkScreenWidth();
//     });
// });
