<?php

declare(strict_types=1);

namespace FleekDash\Admin;

/**
 * Class Dashboard
 *
 * Main class that coordinates all admin functionality.
 *
 * @package FleekDash\Admin
 */
class Dashboard
{
    private ?AdminMenu $menu = null;

    private ?Assets $assets = null;

    private ?Mount $mount = null;

    private ?Interceptor $interceptor = null;

    private ?Iframe $iframe = null;

    private ?AdminWordPressToolbarPolicy $wordPressToolbarPolicy = null;

    /**
     * Frontend bootstrapper.
     *
     * @return void
     */
    public function bootstrap(): void
    {
        // USE SINGLETON INSTANCE: Prevents multiple menu captures
        $this->menu = AdminMenu::getInstance();
        $this->mount = new Mount();
        $this->interceptor = new Interceptor();
        $this->iframe = new Iframe();
        $this->wordPressToolbarPolicy = new AdminWordPressToolbarPolicy();
        $this->assets = new Assets($this->menu);

        // USE SINGLETON: Prevents duplicate hook registration (also called in Frontend/Assets)
        $adminBarCustomizer = $this->resolveAdminBarCustomizer();

        // Bootstrap each component
        $this->menu->bootstrap();
        $this->assets->bootstrap();
        $this->mount->bootstrap();
        $this->interceptor->bootstrap();
        $this->iframe->bootstrap();
        $this->wordPressToolbarPolicy->bootstrap();
        $adminBarCustomizer->bootstrap();

        // Store menu globally for API access
        global $fleekdash_admin_menu;
        $fleekdash_admin_menu = $this->menu;
    }

    private function resolveAdminBarCustomizer(): AdminBarCustomizer
    {
        return AdminBarCustomizer::getInstance();
    }
}
