<?php

namespace Opentalent\OtCore\ViewHelpers;

use FluidTYPO3\Vhs\Utility\ErrorUtility;
use Opentalent\OtCore\Website\OtPageRepository;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
 * Class OtAbstractViewHelper
 * Base class for Opentalent viewhelpers
 *
 * @package Opentalent\OtCore\ViewHelpers
 */
class OtAbstractViewHelper extends AbstractViewHelper {

    /**
     * @var OtPageRepository
     *
     */
    protected OtPageRepository $pageRepository;

    /**
     * Throw a VHS viewhelper error
     */
    protected function throwException(string $msg) {
        ErrorUtility::throwViewHelperException($msg);
    }

    /**
     * @param OtPageRepository $pageRepository
     */
    public function injectOtPageRepository(OtPageRepository $pageRepository)
    {
        $this->pageRepository = $pageRepository;
    }

    /**
     * Returns the language service.
     *
     * @return LanguageService
     */
    protected function getLanguageService(): LanguageService
    {
        return $GLOBALS['LANG'];
    }

    protected function translate(string $id) {
        return LocalizationUtility::translate($id, 'ot_templating');
    }
}
