/**
 * Easy Invoice Promotion Banner JavaScript
 */
jQuery(document).ready(function($) {
    
    // Handle promotion banner dismissal
    $('#easy-invoice-promotion-dismiss').on('click', function(e) {
        e.preventDefault();
        
        $.ajax({
            url: easyInvoicePromotion.ajaxUrl,
            type: 'POST',
            data: {
                action: 'easy_invoice_dismiss_promotion',
                nonce: easyInvoicePromotion.nonce
            },
            success: function(response) {
                if (response.success) {
                    // Hide the notice with a smooth fade out
                    $('#easy-invoice-promotion-notice').fadeOut(300, function() {
                        $(this).remove();
                    });
                }
            },
            error: function() {
                // If AJAX fails, still hide the notice
                $('#easy-invoice-promotion-notice').fadeOut(300, function() {
                    $(this).remove();
                });
            }
        });
    });
    
    // Override the default WordPress notice dismiss handler for our promotion notice
    $(document).on('click', '#easy-invoice-promotion-notice .notice-dismiss', function(e) {
        e.preventDefault();
        
        $.ajax({
            url: easyInvoicePromotion.ajaxUrl,
            type: 'POST',
            data: {
                action: 'easy_invoice_dismiss_promotion',
                nonce: easyInvoicePromotion.nonce
            },
            success: function(response) {
                if (response.success) {
                    $('#easy-invoice-promotion-notice').fadeOut(300, function() {
                        $(this).remove();
                    });
                }
            },
            error: function() {
                $('#easy-invoice-promotion-notice').fadeOut(300, function() {
                    $(this).remove();
                });
            }
        });
    });
});
