<?php


namespace AutoAdmin\Bundle\Admin\Twig\Extension;

use AutoAdmin\Bundle\Admin\Router\AdminRouter;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class RoutingExtension extends AbstractExtension
{
    private AdminRouter $adminRouter;

    public function __construct(AdminRouter $adminRouter)
    {
        $this->adminRouter = $adminRouter;
    }


    public function getFunctions(): array
    {
        return [
            new TwigFunction('admin_path', [$this, 'getPath']),
        ];
    }

    public function getPath($entity, $action, $parameters = []): string
    {
        return $this->adminRouter->generate($entity, $action, $parameters);
    }
}