<?php

namespace Plainwork\Ui\Renderer\Form;

use Plainwork\Http\Request;
use Plainwork\Ui\Component\Form\FormErrors;
use Plainwork\Ui\Component\BlockList;
use Plainwork\Ui\Component\HtmlElement;

final class FormErrorsRenderer
{
    public function __invoke(FormErrors $el, Request $request)
    {
        $errors = $el->getErrors();
        if (!$errors) {
            return;
        }

        $ret = new BlockList();
        foreach ($errors as $e_) {
            $ret_ = new HtmlElement('strong', $e_);
            $ret_ = (new HtmlElement('div', $ret_))->withAttr('class', 'pw-form_error-block');
            $ret->add($ret_);
        }

        return $ret;
    }
}
