<?php
/**
 * Admin module wrapper.
 *
 * @package Kutby
 * @since   2.0.0
 */

declare(strict_types=1);

namespace Kutby\Modules;

use Kutby\Admin\Dashboard;
use Kutby\Admin\Showcase;
use Kutby\Contracts\ModuleInterface;
use Kutby\Events\Dispatcher;
use Kutby\Icons\Registry as IconRegistry;
use Kutby\Live\SettingsBridge;

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

/**
 * Class AdminModule
 */
final class AdminModule implements ModuleInterface {

	/**
	 * {@inheritdoc}
	 */
	public function register(): void {
		if ( ! is_admin() ) {
			return;
		}

		IconRegistry::boot();
		SettingsBridge::register();
		( new Dashboard() )->register();
		( new Showcase() )->register();

		add_action(
			'admin_enqueue_scripts',
			static function ( string $hook ): void {
				if ( false === strpos( $hook, KUTBY_ADMIN_SLUG ) ) {
					return;
				}
				Dispatcher::emit( 'admin_ready', array( 'hook' => $hook ) );
			},
			20
		);
	}

	/**
	 * {@inheritdoc}
	 */
	public function boot(): void {}
}
