<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\hooks;

use apexl\Io\interfaces\AbstractHook;
use apexl\Io\modules\display\includes\Page;
use apexl\Io\modules\user\interfaces\MasqueradeServiceInterface;
use apexl\Io\modules\user\services\CurrentUserFactory;

final readonly class AddUserToGlobalPageData implements AbstractHook
{
    public function __construct(
        private CurrentUserFactory $currentUserFactory,
        private MasqueradeServiceInterface $masqueradeService,
    ) {}

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

    public function __invoke(array $data): array
    {
        $currentUser = $this->currentUserFactory->get();
        $data['isMasquerading'] = $this->masqueradeService->isMasquerading();
        $data['user'] = $currentUser;

        return $data;
    }
}
