<?php

namespace Opentalent\OtTemplating\ViewHelpers\Template;


use Closure;
use Opentalent\OtCore\Exception\NoSuchWebsiteException;
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 name of the current template
 *
 *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 *
 *     {ot:template.current()}
 *
 * @package Opentalent\OtTemplating\ViewHelpers\Template
 */
class CurrentViewHelper 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 string
     * @throws NoSuchWebsiteException
     */
    public function render(): string
    {
        $website = $this->otWebsiteRepository->getCurrentWebsiteFromFEGlobals();

        return $this->templateRepository->getTemplate($website);
    }
}
