<?php
/**
 * Core Plugin Functionality
 *
 * @package ReplyIt_Chat_Widget
 */

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}

class ReplyIt_Core {

    /**
     * Single instance
     */
    private static $instance = null;

    /**
     * Get instance
     */
    public static function instance() {
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * Constructor
     */
    private function __construct() {
        add_action('admin_notices', [$this, 'admin_notices']);
    }

    /**
     * Admin notices
     */
    public function admin_notices() {
        // Check if plugin is configured
        $widget_id = get_option('replyit_widget_id');
        $api_secret = get_option('replyit_api_secret');

        if (empty($widget_id) || empty($api_secret)) {
            $settings_url = admin_url('options-general.php?page=replyit-chat-settings');
            ?>
            <div class="notice notice-warning is-dismissible">
                <p>
                    <strong><?php esc_html_e('ReplyIt Chat Widget:', 'replyit-chat-widget'); ?></strong>
                    <?php printf(
                        wp_kses_post(__('Please configure your widget settings to activate the chat widget. <a href="%s">Go to Settings</a>', 'replyit-chat-widget')),
                        esc_url($settings_url)
                    ); ?>
                </p>
            </div>
            <?php
        }
    }

    /**
     * Get widget configuration
     */
    public static function get_config() {
        return [
            'widget_id' => get_option('replyit_widget_id', ''),
            'api_secret' => get_option('replyit_api_secret', ''),
            'api_url' => get_option('replyit_api_url', 'https://replyit.ai'),
            'enabled' => get_option('replyit_enabled', true),
            'woocommerce_enabled' => get_option('replyit_woocommerce_enabled', false),
        ];
    }

    /**
     * Check if plugin is configured
     */
    public static function is_configured() {
        $config = self::get_config();
        return !empty($config['widget_id']) && !empty($config['api_secret']);
    }
}
