/**=======================================
     * LOAD ITEMS BACK
==========================================*/
$(document).ready(function() {
    $('.accordion-button').on('click', function() {
        var activeTabId = $(this).attr('data-bs-target');
        localStorage.setItem('activeAccordionTab', activeTabId);
    });

    // Retrieve and activate the stored active accordion tab on page load
    var activeAccordionTab = localStorage.getItem('activeAccordionTab');
    if (activeAccordionTab) {
        $(activeAccordionTab).collapse('show');
    }
});

$(document).ready(function() {

$('.user-register').click(function() {
    event.preventDefault();

    

    // Handle User Details form submission
    var form = $('#user-details-form')[0];
    var formData = new FormData(form);
    $.ajax({
        type: "POST",
        url: base_url + "cart/register",
        dataType: "JSON",
        data: formData,
        processData: false,
        contentType: false,
        headers: { 'X-Requested-With': 'XMLHttpRequest' },
        success: function (userData) {
            if (userData.success == true) {
                // User registration was successful
                toastr.success(data.msg);
                window.location.href = base_url +"shop";
            } else {
                // Handle user registration errors
                var errorHtml = '<div class="alert alert-danger"><ul>';
                for (var key in userData.validation) {
                    if (userData.validation.hasOwnProperty(key)) {
                        errorHtml += '<li>' + userData.validation[key] + '</li>';
                    }
                }
                errorHtml += '</ul></div>';
                $('#error-container').html(errorHtml);
            }
        }
    });
});

});