<?php


namespace AutoAdmin\Bundle\Menu\Twig;

use Knp\Menu\ItemInterface;
use Knp\Menu\Twig\Helper;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class AutoAdminMenuExtension extends AbstractExtension
{
    private Helper $helper;
    private AutoAdminMenuExtension $knpExtension;

    public function __construct(Helper $helper)
    {
        $this->helper = $helper;
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('aa_menu', [$this, 'render'], ['is_safe' => ['html']]),
        ];
    }

    public function getFilters(): array
    {
        return [];
    }

    /**
     * Renders a menu with the specified renderer.
     */
    public function render(array|ItemInterface|string $menu, array $options = [], $renderer = null): string
    {
        if (empty($options['currentClass'])) {
            $options['currentClass'] = 'active';
        }

        return $this->helper->render($menu, $options, $renderer);
    }
}
