<?php

namespace Container\MenuTop;

use Entity\Model\Hastutil;
use Helpers\Additional\Additional;
use Helpers\Outil\Roles;
use Helpers\Outil\Sql;
use Modules\GlobalApplication\Repository\LicenceOxalys;
use Psr\Container\ContainerInterface;
use Skeleton\Router;

class RelationFournisseur extends AbsMenuTop
{
    
    use \Traits\Menu\Droit;
    
    protected string $pack;
    protected Additional $additional;

    /**
     * __construct
     *
     * @param  Additional $additional
     * @return void
     */
    public function __construct(Additional $additional)
    {
        $this->pack = 'RelationFournisseurs';
        $this->additional = $additional;
    }

    /**
     * @return array<mixed>
     */
    public function getListeAction(router $router, ContainerInterface $contenaire, \PDO $pdo)
    {
        /** @var \Helpers\Trad\ITrad */
        $trad = $contenaire->get(\Helpers\Trad\ITrad::class);
        
        $droit['OX_GESTFOU'] = Roles::droitsUtilisateur($pdo, 'OX_GESTFOU');
        $menu = [];

        if ($droit['OX_GESTFOU']  || $this->getAll()) {
            $menu[] = [
                'id'            => 'menuTopFournisseurs',
                'pathLogin'     => 'fournisseur',
                'path'          => $router->generateUri('Fournisseur.GestionFournisseur.index'),
                'libelle'       => $trad->t('Fournisseurs'),
                'menuActive'    => 'Fournisseur'
            ];
        }

        //dossier PP 301906
        $droit['HA_CEVALCM'] = Roles::droitsUtilisateur($pdo, 'HA_CEVALCM');
        $droit['HA_CEVASUP'] = Roles::droitsUtilisateur($pdo, 'HA_CEVASUP');
        $droit['HA_CEVAVIS'] = Roles::droitsUtilisateur($pdo, 'HA_CEVAVIS');
        $droit['HA_EVA_TTC'] = Roles::droitsUtilisateur($pdo, 'HA_EVA_TTC');
        $droit['ISNOTEUR']   = Sql::toBool((new Hastutil($pdo))->find(['CODE' => $_SESSION['Session_Login']])['NOTEUR']);  // utilisateur noteur ?

        if (((new LicenceOxalys($pdo))->evalFournActive() && ( $droit['HA_CEVALCM'] || $droit['HA_CEVASUP']|| $droit['HA_CEVAVIS'] || $droit['HA_EVA_TTC'] || $droit['ISNOTEUR'] ))
            || $this->getAll()
        ) {
            $menu[] = [
                'id'            => 'menuTopEval',
                'pathLogin'     => 'evaluations',
                'path'          => $router->generateUri('Evaluation.Campaign.index'),
                'libelle'       => $trad->t('Evaluations'),
                'menuActive'    => 'Evaluations'
            ];
        }
        return $menu;
    }
}
