(function ($) {
    "use strict";

    // Handle install and activate plugins button click
    $("#install-activate-button").on("click", function (e) {
        e.preventDefault();
        var button = $(this);
        button.attr("disabled", "disabled");
        button.text("Installing & Activating recommended plugins").addClass("processing-spinner");

        var activationData = {
            action: "soccer_sports_install_and_activate_plugins",
            nonce: soccer_sports_localize.nonce,
        };

        $.post(soccer_sports_localize.ajax_url, activationData, function (response) {
            console.log("asdasd", response);
            if (response.success) {
                window.location.href = soccer_sports_localize.redirect_url;
            } else {
                button.text(response.data.message);
            }
        });
    });

    // Handle notice dismiss button click
    $(document).on('click', '.soccer-sports-notice-wrapper .notice-dismiss', function () {
        var $notice = $(this).closest('.soccer-sports-notice-wrapper');
        var type = $notice.data('notice');

        $.ajax({
            type: 'POST',
            url: soccer_sports_localize.ajax_url,
            data: {
                action: 'soccer_sports_dismissed_notice_handler',
                type: type,
                wpnonce: soccer_sports_localize.dismiss_nonce
            },
            success: function (response) {
                if (response.success) {
                    console.log("Notice dismissed successfully");
                    // Remove the notice from DOM after successful dismissal
                    $notice.fadeOut('fast', function() {
                        $(this).remove();
                    });
                } else {
                    console.log("Failed to dismiss notice");
                }
            }
        });
    });

})(jQuery);
