/**
 * Admin banner functionality
 */
(function ($) {
    'use strict';

    $(document).ready(function () {
        // Use delegated events to catch clicks even if banner is added dynamically
        $(document).on('click', '.devikit-infakt-banner-remind-later', function (e) {
            e.preventDefault();
            e.stopPropagation();
            e.stopImmediatePropagation();
            dismissBanner('remind_later');
            return false;
        });

        // Handle "Don't remind me anymore" button
        $(document).on('click', '.devikit-infakt-banner-dismiss-permanent', function (e) {
            e.preventDefault();
            e.stopPropagation();
            e.stopImmediatePropagation();
            dismissBanner('dismiss_permanent');
            return false;
        });

        /**
         * Dismiss banner via AJAX
         * @param {string} actionType - Type of action (remind_later or dismiss_permanent)
         */
        function dismissBanner(actionType) {
            $.ajax({
                url: devikitInfaktBanner.ajaxurl,
                type: 'POST',
                data: {
                    action: 'devikit_infakt_dismiss_banner',
                    action_type: actionType,
                    nonce: devikitInfaktBanner.nonce
                },
                success: function (response) {
                    if (response.success) {
                        // Hide the banner with fade effect
                        $('.devikit-infakt-pro-banner').fadeOut(300, function () {
                            $(this).remove();
                        });
                    } else {
                        console.error('Error dismissing banner:', response.data);
                    }
                },
                error: function (xhr, status, error) {
                    console.error('AJAX error:', error);
                }
            });
        }
    });

})(jQuery);





