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: 'music_event_artist_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 music_event_artist_button = document.getElementById('install-activate-button');
    const music_event_artist_config = window.installPluginData || window.pluginInstallerData;

    if (!music_event_artist_button || !music_event_artist_config) return;

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

        const music_event_artist_redirectUrl = music_event_artist_button.getAttribute('data-redirect') || music_event_artist_config.redirectUrl;

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

        const music_event_artist_installData = new FormData();
        music_event_artist_installData.append('action', 'install_and_activate_wordclever_plugin');
        music_event_artist_installData.append('nonce', music_event_artist_config.nonce);

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