(function ($) {
    'use strict';

    var config = window.promopilotBanner || {};
    var ajaxUrl = config.ajaxUrl || window.ajaxurl || '';
    var nonce = config.nonce || '';

    function dismissNotice(id) {
        if (!ajaxUrl || !nonce || !id) {
            return;
        }

        $.post(ajaxUrl, {
            action: 'promopilot_dismiss_notice',
            notice_id: id,
            nonce: nonce
        });
    }

    $(function () {
        $(document).on('click', '.promopilot-dismiss', function () {
            var $notice = $(this).closest('.promopilot-admin-notice');
            var noticeId = $notice.data('notice-id');

            $notice.fadeOut(200, function () {
                $(this).remove();
            });

            dismissNotice(noticeId);
        });
    });
}(jQuery));
