<?php

namespace Plainwork\Ui\Renderer\Form;

use Plainwork\Http\Request;
use Plainwork\Ui\Component\Form\DateInput;
use Plainwork\Ui\Component\HtmlElement;

final class NativeDateInputRenderer
{
    public function __invoke(DateInput $el, Request $request, callable $next)
    {
        $value = $el->getValue();
        $htmlValue = $value ? $value->format('Y-m-d') : '';

        $el = $el
            ->withTag('input')
            ->withAttr('type', 'date')
            ->withAttr('value', $htmlValue)
            ;

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