<?php

namespace Modules\Stock\MenuContextuel;

use Helpers\Outil\MenuContextuel;
use Helpers\Outil\Roles;
use Helpers\Trad\ITrad;
use Helpers\Trad\Trad;
use Modules\Stock\Interface\MenuContextuelInterface;
use Modules\Stock\Trait\MenuContextuelTrait;
use PDO;
use Skeleton\Router;

class ImportUniverselContextuel extends MenuContextuel implements MenuContextuelInterface
{
    use MenuContextuelTrait;

    /**
     * @var array<string,mixed>
     */
    public array $droit = [];

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

    /**
     * @param array<string,string|int> $entity
     * @return array<string, array<int,array<string, mixed>>>
     */
    public function generate(array $entity): array
    {
        $menuContextuel = [
            'listePrincipal' => [
                [
                    'icone' => 'visualiser_v2',
                    'libelle' => $this->trad->t('Visualiser'),
                    'lien' => $this->router->generateUri('Stock.ImportUniversel.visualiser', ['codMdle' => $entity['COD_MDLE']]),
                ]
            ]
        ];

        if (Roles::droitsUtilisateur($this->pdo, 'ST_DSM_UNI')) {
            $menuContextuel['listePrincipal'][] = [
                'icone' => 'modifier_v2',
                'libelle' => $this->trad->t('Modifier'),
                'lien' => $this->router->generateUri('Stock.ImportUniversel.modifierForm', ['codMdle' => $entity['COD_MDLE']]),
            ];
        }
        if (Roles::droitsUtilisateur($this->pdo, 'ST_DSS_UNI')) {
            $menuContextuel['listeSecondaire'][] = [
                'libelle' => $this->trad->t('Supprimer'),
                'lienJs' => 'popupConfirmSimple('
                    . join(',', [
                        json_encode($this->trad->t('Suppression du profil d\'import ' . $entity['COD_MDLE'])),
                        json_encode(Trad::strBuild($this->trad->t('Etes-vous sûr de vouloir supprimer le profil d\'import @1@ ?'), $entity['COD_MDLE'])),
                        json_encode($this->router->generateUri('Stock.ImportUniversel.supprimer', ['codMdle' => $entity['COD_MDLE']])),
                        '{}',
                        '() => {window.action.arianeReload()}'
                    ]) . ');',
            ];
        }
        if (Roles::droitsUtilisateur($this->pdo, 'ST_DS_UNI')) {
            $menuContextuel['listeSecondaire'][] = [
                'libelle' => $this->trad->t('Importer'),
                'lienJs' => 'ajaxPopup('
                    . json_encode($this->router->generateUri('Stock.ImportUniversel.importerForm', ['codMdle' => $entity['COD_MDLE']])) . ','
                    . json_encode($this->trad->t('Importer une demande de service'))
                    . ')'
            ];
        }

        return $menuContextuel;
    }
}
