<?php
/**
 * Main plugin controller. Wires admin + front-end pieces together as a singleton.
 *
 * @package AetherisAIChat
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class Aetheris_AI_Chat_Plugin {

	private static $instance = null;

	public static function instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	private function __construct() {
		// Translations are auto-loaded by WordPress 4.6+ for plugins on .org
		// (matched by Text Domain). No explicit load_plugin_textdomain() call
		// needed; Plugin Check flags it as discouraged.

		Aetheris_AI_Chat_Settings::init();
		Aetheris_AI_Chat_Embed::init();

		if ( is_admin() ) {
			Aetheris_AI_Chat_Admin::init();
		}

		add_filter(
			'plugin_action_links_' . AETHERIS_AI_CHAT_BASENAME,
			array( $this, 'action_links' )
		);
	}

	public function action_links( $links ) {
		$settings_url = admin_url( 'admin.php?page=aetheris-ai-chat' );
		$settings     = sprintf(
			'<a href="%s">%s</a>',
			esc_url( $settings_url ),
			esc_html__( 'Settings', 'aetheris-ai-chat' )
		);
		array_unshift( $links, $settings );
		return $links;
	}

	public static function activate() {
		$existing = get_option( AETHERIS_AI_CHAT_OPTION );
		if ( ! is_array( $existing ) ) {
			add_option( AETHERIS_AI_CHAT_OPTION, Aetheris_AI_Chat_Settings::defaults() );
		}
	}

	public static function deactivate() {
		// Settings are preserved on deactivate. Uninstall removes them — see uninstall.php.
	}
}
