/**
 * Admin Notice JavaScript
 * Handles pro upgrade notice dismiss
 */

jQuery(document).ready(function($) {
    var $notice = $('#ai-blog-pro-notice');
    var $dismissBtn = $('#ai-blog-pro-dismiss');
    var $closeBtn = $('#ai-blog-pro-close');

    /**
     * Fade out notice with animation.
     */
    function hideNotice() {
        $notice.addClass('ai-blog-pro-exit');
        $notice.on('animationend', function() {
            $notice.remove();
        });
    }

    // Close button (X) — temporary hide only
    $closeBtn.on('click', function(e) {
        e.preventDefault();
        hideNotice();
    });

    // "Maybe Later" button — permanent dismiss
    $dismissBtn.on('click', function(e) {
        e.preventDefault();
        hideNotice();

        // Persist via URL param (existing system)
        var currentUrl = window.location.href;
        var separator = currentUrl.indexOf('?') > -1 ? '&' : '?';
        window.location.href = currentUrl + separator + 'xbnotice=1';
    });

    // Legacy support for old notice classes
    $('.mgadin-notice .btnend').on('click', function(e) {
        e.preventDefault();
        var currentUrl = window.location.href;
        var separator = currentUrl.indexOf('?') > -1 ? '&' : '?';
        window.location.href = currentUrl + separator + 'xbnotice=1';
    });

    $('.mgadin-notice.is-dismissible .notice-dismiss').on('click', function(e) {
        e.preventDefault();
        var currentUrl = window.location.href;
        var separator = currentUrl.indexOf('?') > -1 ? '&' : '?';
        window.location.href = currentUrl + separator + 'xbnotice=1';
    });
});
