<?php

namespace Plainwork\Ui\Renderer;

use Plainwork\Ui\Component\Ol;
use Plainwork\Ui\Component\HtmlElement;

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

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

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

        foreach ($items as $item) {
            $v = (new HtmlElement('li', $item))
                ->withAttr('class', 'pw-ol_li')
                // ->withAttr('style', ['border' => 'red 1px solid'])
                ;
            $ret->append($v);
        }

        return $ret;
    }
}
