<?php

namespace Container\MenuTop;

use Helpers\Additional\Additional;
use Helpers\Log\LogSysteme;
use Helpers\Outil\Roles;
use Modules\Stock\Helper\RulesHelper;
use Psr\Container\ContainerInterface;
use Skeleton\Router;

class P2P extends AbsMenuTop
{
    
    use \Traits\Menu\Droit;
    protected string $pack;

    /**
     * __construct
     *
     * @param  Additional $additional
     * @return void
     */
    public function __construct(Additional $additional)
    {
        $this->pack = 'P2P';
        $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[] = [
            'id'            => 'menuTopEProc',
            'pathLogin'     => 'eproc',
            'path'          => $router->generateUri('Index.TableauDeBord.index'),
            'libelle'       => $trad->t('eProcurement'),
            'menuActive'    => 'eproc'
        ];

        if (($_SESSION['AcessFacture']
            && Roles::droitsUtilisateur($pdo, 'HA_FA_VISU')
            && Roles::droitsUtilisateur($pdo, 'U8zXaa77yt'))
            || $this->getAll()) {
            $menu[] = [
                'id'            => 'menuTopFactures',
                'pathLogin'     => 'facture',
                'path'          => $router->generateUri('Facture.GestionFacture.index'),
                'libelle'       => $trad->t('Factures'),
                'menuActive'    => 'Facture'
            ];
        }

        if (Roles::droitsUtilisateur($pdo, 'HA_ACD_CM') || Roles::droitsUtilisateur($pdo, 'HA_MAR_CM') || Roles::droitsUtilisateur($pdo, 'HA_TYM_CM')  || $this->getAll()) {
            $menu[] = [
                'id'            => 'menuTopContrats',
                'pathLogin'     => 'contrat',
                'path'          => $router->generateUri('Contrat.accord-cadre.index', ['type' => 'ALL', 'idacc' => 'ALL' ]),
                'libelle'       => $trad->t('Accords-cadres'),
                'menuActive'    => 'Contrats'
            ];
        }

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

        if (RulesHelper::hasStockAccessRights($pdo) || $this->getAll()) {
            $menu[] = [
                'id'            => 'menuTopStock',
                'pathLogin'     => 'stock',
                'path'          => $router->generateUri('Stock.GestionStock.gestion'),
                'libelle'       => $trad->t('Stocks'),
                'menuActive'    => 'Stock'
            ];
        }

        if ($this->getAll() /*|| (Roles::droitsUtilisateur($pdo, 'OXACAT') && $_SESSION['Session_NumClient'] == '0')*/) {
            $menu[] = [
                'id'            => 'menuTopCatalogue',
                'pathLogin'     => 'catalogue',
                'path'          => $router->generateUri('Catalogue.Format.listeFormat'),
                'libelle'       => '[DEV] '.$trad->t('Catalogue'),
                'menuActive'    => 'Catalogue'
            ];
        }

        return $menu;
    }
}
