<?php

namespace Plainwork\Ui\Renderer\Form;

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

final class NumberInputRenderer
{
    public function __invoke(NumberInput $el, Request $request, callable $next)
    {
        $el = $el
            ->withTag('input')
            ->withAttr('type', 'number')
            ->withAttr('value', (string) $el->getValue())
            ->withAttr('min', $el->getMin())
            ->withAttr('max', $el->getMax())
            ->withAttr('step', $el->getStep())
            ;

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

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