<?php

namespace Plainwork\UiWordPress\Renderer\Form;

use Plainwork\Http\Request;
use Plainwork\Http\Server;
use Plainwork\Ui\Component\Form\ButtonInput;

class AdminButtonInputRendererDecorator
{
    public $server = Server::class;

    public function __invoke(ButtonInput $el, Request $request, callable $next)
    {
        $prefix = $this->server->getPrefix();
        if (strlen($prefix)) {
            $name = $el->getName();
            $htmlName = strlen($prefix) ? $prefix . $name : $name;
            $el = $el->withAttr('name', $htmlName);
        }
        $el->withAttr('class', 'button');

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