<?php

namespace Modules\Evaluation\TwigExtension;

use Modules\Evaluation\Service\ResultatService;
use Psr\Container\ContainerInterface;
use Entity\Model\ParamDico;

use PDO;
use Twig\TwigFilter;

class ResultatExtension extends \Twig\Extension\AbstractExtension
{
    protected PDO $pdo;

    protected ContainerInterface $contenaire;

    public function __construct(PDO $pdo, ContainerInterface $contenaire)
    {
        $this->pdo = $pdo;
        $this->contenaire = $contenaire;
    }

    public function getFunctions()
    {
        return [];
    }

    public function getFilters()
    {
        return array(
            'status' => new TwigFilter('status', array($this, 'status')),
            'colorClass' => new TwigFilter('colorClass', array($this, 'colorClass')),
        );
    }

    /**
     * status
     *
     * @param  string $value
     * @return string
     */
    public function status($value)
    {
        $param = (new ResultatService($this->pdo))->getEvalParamdico();

        return ($value <= $param['ALPHA3'])
            ? $param['ALPHA6']
            : (($value <= $param['ALPHA4'])
                ? $param['ALPHA7']
                : $param['ALPHA8']);
    }

    /**
     * colorClass
     *
     * @param  string $value
     * @return string
     */
    public function colorClass($value)
    {
        $param = (new ResultatService($this->pdo))->getEvalParamdico();

        return ($value <= $param['ALPHA3'])
            ? 'rouge'
            : (($value <= $param['ALPHA4'])
                ? 'orange'
                : 'vert');
    }
}
