<?php
declare(strict_types=1);

/**
 * Quick Form Query extension for Typo3
 * Krzysztof K. Putyra
 * support@math.uzh.ch
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 */

namespace IMATHUZH\Qfq\Core\Typo3;

class TextFieldRenderer
{
    public function renderSmall(array $params): string
    {
        return $this->render($params, 5);
    }
    public function renderLarge(array $params): string
    {
        return $this->render($params, 15);
    }

    protected function render(array $params, int $rows): string
    {
        // Typo3 assumes that each field has as id the string
        //   em-<ext_key>-<field_name>
        // and creates a label for such an element. See
        // TYPO3\CMS\Core\ViewHelpers\Form\TypoScriptConstantsViewHelper::addIdAttribute
        $extKey = 'qfq';
        $fieldName = htmlspecialchars($params['fieldName']);
        $fieldValue = htmlspecialchars($params['fieldValue']);
        return "<textarea id=\"em-$extKey-$fieldName\" name=\"$fieldName\" rows=\"$rows\" class=\"form-control\">$fieldValue</textarea>";
    }
}
