<?php

declare(strict_types=1);

namespace Apexl\Io\User\Hooks;

use Apexl\Io\Component\Collections\ComponentCollection;
use Apexl\Io\Component\Factories\GenericComponentFactory;
use Apexl\Io\Display\Page;
use Apexl\Io\Interfaces\AbstractHook;
use Apexl\Io\User\Display\Components\MasqueradingWarning;
use Apexl\Io\User\Interfaces\MasqueradeServiceInterface;

final readonly class AddMasqueradingWarning implements AbstractHook
{
    public function __construct(
        private GenericComponentFactory $componentFactory,
        private MasqueradeServiceInterface $masqueradeService,
    ) {}

    public function hooks(): array
    {
        return [Page::HOOK__COMPONENTS];
    }

    public function __invoke(ComponentCollection $components): ComponentCollection
    {
        if ($this->masqueradeService->isMasquerading()) {
            $components->add($this->componentFactory->make(MasqueradingWarning::class));
        }

        return $components;
    }
}
