<?php
// require this file from your main plugin bootstrap

class Copyspell_Addons_Manager {
    private $addon_dir;
    private $addon_url;
    private $option_license_key = 'copyspell_license_key';
    private $api_base = 'https://api.copyspell.ai'; // change to your API

    public function __construct() {
        $this->addon_dir = COPYSPELL_AI_PATH . 'addons/';
        $this->addon_url = plugins_url('addons/', dirname(__FILE__));
        //add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_assets']);
    }





    public function enqueue_admin_assets($hook) {
        if ($hook !== 'toplevel_page_copyspell-addons') return;
        wp_enqueue_script('copyspell-addons-admin', plugins_url('../assets/js/copyspell-addons-admin.js', __FILE__), ['jquery'], filemtime(plugin_dir_path(__FILE__) . '../assets/js/copyspell-addons-admin.js'), true);
        wp_localize_script('copyspell-addons-admin', 'CopyspellAddonsConfig', [
            'ajax_url' => admin_url('admin-ajax.php'),
            'nonce' => wp_create_nonce('copyspell_addons_nonce'),
            'addon_url_base' => $this->addon_url,
            'api_base' => $this->api_base,
            'license' => $this->get_stored_license()
        ]);
        wp_enqueue_style('copyspell-addons-admin-css', plugins_url('../assets/css/copyspell-addons-admin.css', __FILE__), [], filemtime(plugin_dir_path(__FILE__) . '../assets/css/copyspell-addons-admin.css'));
    }

    // AJAX actions -------------------------------------------------------



 
    
    // helper to extract a simple meta JS comment at the top of the file
    private function read_addon_meta($path) {
        $head = file_get_contents($path, false, null, 0, 1024); // read first 1KB
        if (preg_match('#/\*\s*META:\s*(\{.*?\})\s*\*/#s', $head, $matches)) {
            $json = $matches[1];
            $data = json_decode($json, true);
            if (json_last_error() === JSON_ERROR_NONE) {
                return $data;
            }
        }
        return null;
    }
}

new Copyspell_Addons_Manager();



