jQuery(document).ready(function($) {
    // Handle form submission via AJAX
    $('#passwordForm').on('submit', function(e) {
        e.preventDefault();
        var password = $('#password_field').val();

        $.ajax({
            url: ajaxurl, // WordPress AJAX URL
            type: 'POST',
            data: {
                action: 'check_password', // Custom AJAX action
                password: password
            },
            success: function(response) {
                if (response.success) {
                    // Store the password in a cookie for 1 hour
                    document.cookie = "custom_password=" + password + ";path=/;max-age=3600";
                    // Hide the modal on success
                    UIkit.modal('#login').hide();
                    // Optionally reload the page or unhide the content
                    location.reload();
                } else {
                    $('#error-message').show(); // Show error if password is incorrect
                }
            }
        });
    });
});
