<?php

namespace LinkFiliate\Core;

use LinkFiliate\Core\Api;
use LinkFiliate\Admin\Menu;
use LinkFiliate\Assets\Admin;
use LinkFiliate\App\Traits\Singleton;
use LinkFiliate\Libs\Utils\Redirect;
use LinkFiliate\Libs\Utils\Widget;
use LinkFiliate\Libs\Utils\Cache;
use LinkFiliate\Libs\Utils\Banner;
use LinkFiliate\Core\Install;

defined('ABSPATH') || exit;

/**
 * Main Plugin Bootstrap Class.
 *
 * Handles plugin initialization, admin setup, and core utilities.
 *
 * @since 1.0.0
 */
final class Plugin
{
	use Singleton;

	/**
	 * Boot the plugin.
	 *
	 * Called once via Singleton trait.
	 *
	 * @since 1.0.0
	 */
	protected function __construct()
	{
		add_action('init', [$this, 'register_blocks']);
		$this->init();
	}

	/**
	 * Initialize all components.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function init(): void
	{
		// Admin-specific components
		if (is_admin()) {
			Menu::getInstance()->init();
			Admin::getInstance()->bootstrap();
		}

		// Core functionalities
		Api::getInstance()->init();
		Redirect::getInstance();
		Widget::getInstance()->init();
		Banner::getInstance()->init();
		Cache::init();
	}

	/**
	 * Plugin activation hook.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public static function activate(): void
	{
		Install::getInstance()->init();
	}

	/**
	 * Plugin deactivation hook.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public static function deactivate(): void
	{
		Cache::deactivate();
	}

	/**
	 * Register Gutenberg blocks.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public function register_blocks(): void
	{
		$block_path = LINKFILIATE_PLUGIN_DIR . '/assets/blocks/block-1';
		if (file_exists($block_path)) {
			register_block_type($block_path);
		}
	}
}
