<?php

namespace Plainwork\Ui\Renderer;

use Plainwork\Ui\Component\Href;
use Plainwork\Http\Uri;
use Plainwork\Http\Request;
use Plainwork\Http\RequestFactory;

final class HrefRenderer
{
    public $uri = Uri::class;
    public $requestFactory = RequestFactory::class;

    public function __invoke(Href $el, Request $request): string
    {
        $path = $el->getPath();
        $params = $el->getParams();

        $request_ = $this->requestFactory->from($request, $path, $params);
        $path = $request_->getPath();
        $params = $request_->getQueryParams();

        $ret = $this->uri->to($path, $params);

        return $ret;
    }
}
