<?php

namespace Plainwork\Ui\Renderer\Form;

use Plainwork\Http\Request;
use Plainwork\Ui\Component\Form\TextareaInput;

final class TextareaInputRenderer
{
    public function __invoke(TextareaInput $el, Request $request, callable $next)
    {
        $value = $el->getValue();
        $value = esc_textarea($value);

        $el = $el
            ->withTag('textarea')
            ->setContent($value)
            ;

        if (null === $el->getAttr('rows')) {
            $el->withAttr('rows', 6);
        }

        return $next($el, $request);
    }
}
