<?php
namespace Modules\Commande\TwigExtension;

use Psr\Container\ContainerInterface;
use Modules\Commande\Repository\GareDeTriage;
use TwigExtension\FormExtension;

// TODO : retire
class FormCommandeExtension extends FormExtension
{
    
    public function getFunctions()
    {
        return [
            new \Twig\TwigFunction(
                'inputSectImp',
                [$this,'inputSectImp'],
                ['is_safe' => ['html']]
            ),
        ];
    }
    
    public function getFilters()
    {
        return array(
            //'' => new \Twig\TwigFilter('', array($this, '')),
        );
    }
    
    // TODO : factorize all zoom "Liste des sections d'imputation"
    public function inputSectImp(
        string $societe,
        string $name,
        string $value,
        bool $hasCodeGest,
        ?string $titre = null
    ) :string {
        $trad = $this->trad;
        $router = $this->router;
        return $this->inputAdvance('ZOOMADVANCE', [
            'titre' => $titre,
            'name' => $name,
            'pahtZoom' => $router->generateUri('Ajax.liste.si'),
            'paramZoom' => json_encode([
                'CODE_STE' => $societe,
                'si_valide' => 1
            ]),
            'entity' => 'Sectimpu',
            'widthPopup' => 'modal_large',
            'titleZoom' => $trad->t('Liste des sections d’imputation'),
            'pathConvert' => $router->generateUri('Ajax.outil.convertLibelle'),
            'convertLibelle' => 'convertLibelleGlobal',
            'pathValidator' => $router->generateUri('Ajax.validator.sectionImputation'),
            'paramsValidator' => json_encode([
                'nomChamp' => $trad->t('Section d’imputation'),
                'null' => true,
                'filter_egal_CODE_STE' => $societe,
            ]),
            'value' => $value,
            'iconeLabel' => 'Inactif2.png',
            'idIconeLabel' => 'icone_SECTIMP',
            'inputAttr' => [
                'data-sectimp-hascodgest' => $hasCodeGest ? '1' : '0'
            ]
        ]);
    }
}
