<?php

namespace Opentalent\OtTemplating\ViewHelpers\Template;

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

/**
 * Returns the recorded preferences
 *
 *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 *
 *     {ot:template.preferences()}
 *
 * @package Opentalent\OtTemplating\ViewHelpers\Template
 */
class GetPreferencesViewHelper extends OtAbstractViewHelper
{
    public function __construct(
        private readonly OtWebsiteRepository $otWebsiteRepository,
        private readonly TemplateRepository $templateRepository,
    ) {}

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

}
