<?php
namespace TwigExtension;

use Twig\Extension\AbstractExtension;
use PDO;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Helpers\Additional\Specifique\Specifique;
use Psr\Container\ContainerInterface;
use Skeleton\Router;

class SpecifiqueExtension extends AbstractExtension
{

    
    
    public function __construct(private readonly Router $router, private readonly ContainerInterface $contenaire, private readonly PDO $pdo)
    {
    }

    /**
     *
     */





    public function getFilters()
    {
        return [

            'specifiqueScript' => new TwigFilter('specifiqueScript', $this->specifiqueScript(...)),
        ];
    }

   
    public function getFunctions()
    {
        return [
            new TwigFunction(
                'specifique',
                $this->specifique(...),
                [
                'is_safe' => [
                    'html'
                ]
                ]
            ),
        ];
    }
    
    /**
     * @param array<mixed> $array
     * @return array<mixed>
     */
    public function specifiqueScript($array)
    {
        $specifique = new Specifique();
        return $specifique->getSpecifiqueScript($this->router->getNameRoute());
    }

    /**
     * @param string $class
     * @param string $function
     * @param array<mixed> $array
     * @return mixed
     */
    public function specifique($class, $function, $array = [])
    {
        $namespace = "Modules\\Additional\\Specifique\\Client".(int)$_SESSION['Session_NumClient']."\\Html\\".$class;
        if (class_exists($namespace)) {
            $class = new $namespace($this->router, $this->contenaire, $this->pdo);
            if (method_exists($class, $function)) {
                return $class->$function($array);
            }
        }
    }
}
