<?php

namespace Modules\Additional\Specifique\Client64\Html;

use Psr\Container\ContainerInterface;
use Skeleton\Router;

class HtmlExtension extends \Twig\Extension\AbstractExtension
{

    protected \PDO $pdo;
    private Router $router;
    /** @phpstan-ignore-next-line */
    private ContainerInterface $contenaire;
    
    public function __construct(Router $router, ContainerInterface $contenaire, \PDO $pdo)
    {
        $this->router = $router;
        $this->pdo = $pdo;
        $this->contenaire = $contenaire;
    }

    public function getFunctions()
    {
        return [
            new \Twig\TwigFunction('specifiqueUpdateCDC', [
                $this,
                'specifiqueUpdateCDC'
            ], [
                'is_safe' => [
                    'html'
                ]
            ])
        ];
    }
    
    /**
     * @return string
     */
    public function specifiqueUpdateCDC()
    {

        $html ="<script>
                    $('#input_SI_CODE').change(function(){
                        $.ajax({
                            url: '".$this->router->generateUri('Specifique64.MaSessionSpecifique.updateCDC')."',
                            type: 'POST',
                            dataType: 'JSON',
                            data: $('#maSession').serialize(),
                            success: function (json) {
                                $('#text_CDC_CODE').val(json.CDC).change();
                            }
                        });
                    });
                </script>";
        
        return $html;
    }
}
