<?php 

class SyrusAI {
    
    private static $instance;

    public function __construct() {

        /**
         * 
         * Qui sotto inseriamo tutte le action
         * 
         */
        add_action('admin_enqueue_scripts',[$this,'admin_enqueue_scripts']);
    }

    public static function getInstance() {
        if(!isset(self::$instance)) 
        self::$instance = new self();

        return self::$instance;
    }

    public static function get_templates_dir($file = ""){
        return SYRUS_THEME_PATH . "/template-parts/" . $file;
    }

    public function aggiungi_metabox_generatore_contenuto_post() {
        add_meta_box(
            'syrus-ai-generatore-contenuto',
            __('ChatGPT','syrus'),
            [$this, 'render_metabox_generatore_contenuto_post'],
            'post',
            'side',
            'high'
        );
    }

    public function render_metabox_generatore_contenuto_post() {
        global $syrus;
        $openai_key = $syrus->get_option('generali','chatgpt_token') ? true : false;
        include_once self::get_templates_dir("wp-admin/meta-boxes/meta-box-generatore-contenuto-post.php");
    }

    public static function admin_enqueue_scripts() {
        global $pagenow;

        if($pagenow == "post.php" || $pagenow == "post-new.php") {
            wp_register_script('SyrusAI', SYRUS_THEME_URI . "/js/admin/SyrusAI.class.js",['jquery'],rand(0,999));

            wp_localize_script('SyrusAI','syrus_ai_args',[
                'ajax_url' => admin_url('admin-ajax.php'),
            ]);

            wp_enqueue_script('SyrusAI');
        }

    }

}

$syrusAI = SyrusAI::getInstance();