<?php

namespace Opentalent\OtTemplating\ViewHelpers\Request;

use Closure;
use Opentalent\OtCore\Exception\NoSuchWebsiteException;
use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
use Opentalent\OtCore\Website\OtWebsiteRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

/**
 *   Returns the current Typo3 OtWebsite (FE only)
 *
 *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 *
 *     {ot:request.getWebsite()}
 *
 * @package Opentalent\OtTemplating\ViewHelpers
 */
class GetWebsiteViewHelper extends OtAbstractViewHelper {
    public function __construct(
        private readonly OtWebsiteRepository $otWebsiteRepository,
    ) {}

    /**
     * -- This method is expected by Fluid --
     * Renders the content as html
     *
     * @return array
     * @throws NoSuchWebsiteException
     */
    public function render(): array
    {
        return $this->otWebsiteRepository->getCurrentWebsiteFromFEGlobals();
    }
}
