jQuery(document).ready(function ($) {
    // Attach click event to the dismiss button
    $(document).on('click', '.notice[data-notice="get-start"] button.notice-dismiss', function () {
        // Dismiss the notice via AJAX
        $.ajax({
            type: 'POST',
            url: ajaxurl,
            data: {
                action: 'cleaning_equipment_dismissed_notice',
            },
            success: function () {
                // Remove the notice on success
                $('.notice[data-notice="get-start"]').remove();
            }
        });
    });
});

// Plugin – AI Content Writer plugin activation
document.addEventListener('DOMContentLoaded', function () {
    const cleaning_equipment_button = document.getElementById('install-activate-button');
    const cleaning_equipment_config = window.installPluginData || window.pluginInstallerData;

    if (!cleaning_equipment_button || !cleaning_equipment_config) return;

    cleaning_equipment_button.addEventListener('click', function (e) {
        e.preventDefault();

        const cleaning_equipment_redirectUrl = cleaning_equipment_button.getAttribute('data-redirect') || cleaning_equipment_config.redirectUrl;

        cleaning_equipment_button.textContent = 'Setting up plugins & demo...';

        const cleaning_equipment_installData = new FormData();
        cleaning_equipment_installData.append('action', 'install_and_activate_wordclever_plugin');
        cleaning_equipment_installData.append('nonce', cleaning_equipment_config.nonce);

        fetch(cleaning_equipment_config.ajaxurl, {
            method: 'POST',
            body: cleaning_equipment_installData,
        })
        .then(res => res.json())
        .then(res => {
            if (res.success) {
                window.location.href = cleaning_equipment_redirectUrl;
            } else {
                alert('Activation error: ' + (res.data?.message || 'Unknown error'));
                cleaning_equipment_button.textContent = 'Try Again';
            }
        })
        .catch(error => {
            alert('Request failed: ' + error.message);
            cleaning_equipment_button.textContent = 'Try Again';
        });
    });
});