<?php
/**
 * Theme Admin Info class
 */
class Corporate_Fse_Admin_Info {
    /**
     * Initialize the theme
     */
    public function __construct() {
        add_action('admin_notices', array($this, 'compatible_check'));
        add_action('admin_footer', array($this, 'admin_notice_script'));
        add_action('wp_ajax_dismiss_corporate_fse_notification', array($this, 'dismiss_notification_ajax_handler'));
    }

    
    /**
     * Check compatibility and display notification
     */
    public function compatible_check() {
        // Check if the notification has been dismissed
        $dismissed = get_transient('corporate_fse_notification_dismissed');
        if ($dismissed !== '1') {
            include_once dirname( __FILE__ ) . '/../inc/theme-notice.php';
        }
    }
    
    /**
     * Dismiss the notification
     */
    public function dismiss_notification() {
        // Set the notification dismissal state in a transient for 7 days (adjust the expiration time as needed)
        set_transient('corporate_fse_notification_dismissed', '1', 7 * DAY_IN_SECONDS);
    }
    
    /**
     * Dismiss the notification via AJAX
     */
    public function dismiss_notification_ajax_handler() {
        check_ajax_referer('dismiss_notification_nonce', 'nonce');
        $this->dismiss_notification();
        wp_die();
    }
    
    /**
     * Enqueue admin notice script
     */
    public function admin_notice_script() {
        ?>
        <script>
            (function($) {
                $(document).on('click', '.notice.is-dismissible .notice-dismiss', function() {
                    $.ajax({
                        url: ajaxurl,
                        type: 'POST',
                        data: {
                            action: 'dismiss_corporate_fse_notification',
                        }
                    });
                });
            })(jQuery);
        </script>
        <?php
    }
}

// Instantiate the Corporate FSE Info class
new Corporate_Fse_Admin_Info();
