<?php

namespace Plainwork\Ui\Renderer;

use Plainwork\Ui\Component\Ul;
use Plainwork\Ui\Component\HtmlElement;

final class UlRenderer
{
    public function __invoke(Ul $el)
    {
        $items = $el->getItems();
        if (!$items) {
            return;
        }

        $ret = (new HtmlElement('ul'))
            ->withAttr('class', 'pw-ul')
            ;

        $attr = $el->getAttr();
        foreach ($attr as $k_ => $v_) {
            $ret->withAttr($k_, $v_);
        }

        foreach ($items as $item) {
            $v = (new HtmlElement('li', $item));
            $ret->append($v);
        }

        return $ret;
    }
}
