<?php

namespace Plainwork\UiWordPress\Renderer;

use Plainwork\Http\Request;
use Plainwork\Ui\Component\Ul;
use Plainwork\Ui\Component\Link;

class AdminUlRenderer
{
    public function __invoke(Ul $el, Request $request, callable $next): string
    {
        if (!$el->isMenu()) {
            return $next($el, $request);
        }

        $items = $el->getItems();
        foreach ($items as $item) {
            if ($item instanceof Link) {
                $item->withAttr('class', 'page-title-action');
            }
        }

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