<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\hooks;

use apexl\Io\interfaces\AbstractHook;
use apexl\Io\modules\component\Collections\ComponentCollection;
use apexl\Io\modules\component\Factories\GenericComponentFactory;
use apexl\Io\modules\display\includes\Page;
use apexl\Io\modules\user\interfaces\MasqueradeServiceInterface;
use apexl\Io\modules\userDisplay\components\MasqueradingWarning;

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;
    }
}
