<?php

if (! defined('ABSPATH')) {
    exit;
} class PufferGo_Fse_Theme_Notice
{
    public const DISMISSED_META_KEY = 'puffergo_fse_notice_dismissed';

    public const AJAX_ACTION = 'puffergo_dismiss_fse_notice';

    public const SCRIPT_HANDLE = 'puffergo-fse-notice';

    public const DOCS_URL = 'https://puffergo.com/docs/why-generatepress';

    public const SEARCH_SLUG = 'GeneratePress';

    public static function init()
    {
        add_action('admin_enqueue_scripts', array(__CLASS__, 'maybe_enqueue'));
        add_action('wp_ajax_' . self::AJAX_ACTION, array(__CLASS__, 'handle_dismiss'));
    }

    public static function maybe_enqueue()
    {
        if (! self::should_show()) {
            return;
        } $plugin_dir = plugin_dir_path(PUFFERGO_PLUGIN_FILE);
        $plugin_url = plugin_dir_url(PUFFERGO_PLUGIN_FILE);
        $asset_file = $plugin_dir . 'build/admin/fse-notice/index.asset.php';

        if (! file_exists($asset_file)) {
            return;
        } $asset = require $asset_file;
        wp_enqueue_script(self::SCRIPT_HANDLE, $plugin_url . 'build/admin/fse-notice/index.js', $asset['dependencies'], $asset['version'], true);
        wp_localize_script(self::SCRIPT_HANDLE, 'puffergoFseNotice', array('installUrl' => admin_url('theme-install.php?search=' . self::SEARCH_SLUG), 'docsUrl' => self::DOCS_URL, 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce(self::AJAX_ACTION), 'action' => self::AJAX_ACTION, 'isEditor' => self::is_editor_screen(), ));
    }

    public static function handle_dismiss()
    {
        check_ajax_referer(self::AJAX_ACTION, 'nonce');
        update_user_meta(get_current_user_id(), self::DISMISSED_META_KEY, 1);
        wp_send_json_success();
    }

    private static function should_show()
    {
        if (! current_user_can('manage_options')) {
            return false;
        }

if (get_user_meta(get_current_user_id(), self::DISMISSED_META_KEY, true)) {
            return false;
        } $screen = get_current_screen();

        if (! $screen || ! in_array($screen->base, array('dashboard', 'edit', 'post'), true)) {
            return false;
        }

return wp_is_block_theme();
    }

    private static function is_editor_screen()
    {
        $screen = get_current_screen();

        return $screen && $screen->base === 'post';
    }
}
