<?php

namespace Modules\Evaluation\MenuContextuel;

use Helpers\Outil\MenuContextuel;
use Helpers\Outil\Roles;
use Helpers\Trad\ITrad;
use Helpers\Trad\Trad;
use Modules\GlobalApplication\Repository\LicenceOxalys;
use Skeleton\Router;

class ResultatMenuContextuel extends MenuContextuel
{
    /**
     * @var array<mixed> droit
     */
    public $droit;

    public function __construct(\PDO $pdo, Router $router, ITrad $trad)
    {
        parent::__construct($pdo, $router, $trad);

        $this->droit = [
            'DOA_DOA_CM'    => Roles::droitsUtilisateur($this->pdo, 'DOA_DOA_CM'),
        ];
    }

    /**
     * @param string $campaign
     * @param string $supplier
     * @return array<mixed>
     */
    public function generateSupplierMenu(string $campaign, string $supplier): array
    {
        $menuContextuel = [];

        $menuContextuel['listeSecondaire'][] = [
            'lien' => $this->router->generateUri('Evaluation.Resultat.comparativeView', ['supplier' => $supplier]),
            'libelle' => $this->trad->t('Détails fournisseur'),
        ];

        $menuContextuel['listeSecondaire'][] = [
            'lien' => '',
            'libelle' => $this->trad->t('Export résultats fournisseur'),
            'lienJs' => "exportCSV2('" . $this->router->generateUri('Evaluation.Resultat.export', ['campaign' => $campaign, 'supplier' => $supplier]) . "', 
                'filtre_campagne', 
                '" . $this->router->generateUri('Ajax.Erreur.popupInformation') . "', 
                '" . $this->router->generateUri('Ajax.Outil.appelAsync') . "');",
        ];

        if ((new LicenceOxalys($this->pdo))->dOAActive() && $this->droit['DOA_DOA_CM']) {
            $menuContextuel['listeSecondaire'][] = [
                'lien' => $this->router->generateUri('ProjetAchat.ModeleProjet.createEdit', ['type' => 'D', 'idProjet' => 'noId']),
                'libelle' => $this->trad->t('Initialisation d\'un plan d\'action'),
            ];
        }

        return $menuContextuel;
    }

    /**
     * @param string $idCamp
     * @return array<mixed>
     */
    public function generateCampaignMenu(string $idCamp): array
    {
        $menuContextuel = [];

        $menuContextuel['listeSecondaire'][] = [
            'lien' => $this->router->generateUri('Evaluation.Resultat.index', ['id' => $idCamp]),
            'libelle' => $this->trad->t('Résultats campagne'),
        ];

        return $menuContextuel;
    }
}
