<?php

namespace Plainwork\Ui\Renderer\Form;

use Plainwork\Ui\Component\Form\DurationInput;
use Plainwork\Ui\Component\InlineList;
use Plainwork\Ui\Component\HtmlElement;

class DurationInputRenderer
{
    public function __invoke(DurationInput $el)
    {
        $ret = [];

        $inp = $el->getHourQtyInput();
        if ($inp) {
            $inp->withAttr('size', 2);

            $ret_ = (new InlineList())
                ->setSpacing(1)
                ->add($inp)
                ->add('__Hours__')
                ;
            $ret_ = new HtmlElement('label', $ret_);
            $ret[] = $ret_;
        }

        $inp = $el->getMinuteQtyInput();
        if ($inp) {
            $inp->withAttr('size', 3);

            $ret_ = (new InlineList())
                ->setSpacing(1)
                ->add($inp)
                ->add('__Minutes__')
                ;
            $ret_ = new HtmlElement('label', $ret_);
            $ret[] = $ret_;
        }

        $ret = (new InlineList($ret))->setSpacing(3);

        return $ret;
    }
}
