<?php
if (!defined('WPINC')) {
    die;
}

class SeekMake_Public {
    private $plugin_name;
    private $version;

    public function __construct($plugin_name, $version) {
        $this->plugin_name = $plugin_name;
        $this->version = $version;
    }

    public function enqueue_styles() {
        wp_enqueue_style(
            $this->plugin_name,
            SEEKMAKE_PLUGIN_URL . 'assets/css/frontend.css',
            array(),
            $this->version,
            'all'
        );
    }

    public function enqueue_scripts() {
        wp_enqueue_script(
            $this->plugin_name,
            SEEKMAKE_PLUGIN_URL . 'assets/js/frontend.js',
            array('jquery'),
            $this->version,
            false
        );

        wp_localize_script(
            $this->plugin_name,
            'seekmakePublic',
            array(
                'ajaxUrl' => admin_url('admin-ajax.php'),
                'apiUrl' => SEEKMAKE_API_URL,
                'manufacturerId' => get_option('seekmake_manufacturer_id', ''),
                'woocommerceEnabled' => (bool)(get_option('seekmake_woocommerce_enabled', false) && class_exists('WooCommerce')),
                'wooNonce' => wp_create_nonce('seekmake_wc_cart'),
            )
        );
    }
}

class SeekMake_Activator {
    public static function activate() {
        add_option('seekmake_manufacturer_id', '');
        add_option('seekmake_settings', array(
            'auto_update' => true,
            'enable_logging' => false
        ));
        add_option('seekmake_widget_settings', array());
        
        flush_rewrite_rules();
    }
}

class SeekMake_Deactivator {
    public static function deactivate() {
        flush_rewrite_rules();
    }
}

class SeekMake_Settings {
    public static function get_manufacturer_id() {
        return get_option('seekmake_manufacturer_id', '');
    }

    public static function get_setting($key, $default = null) {
        $settings = get_option('seekmake_settings', array());
        return isset($settings[$key]) ? $settings[$key] : $default;
    }

    public static function get_widget_settings($widget_type, $default = array()) {
        $widget_settings = get_option('seekmake_widget_settings', array());
        return isset($widget_settings[$widget_type]) ? $widget_settings[$widget_type] : $default;
    }
}
