<?php

namespace Modules\Stock\MenuContextuel;

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

class StockLocalContextuel 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>>>
     * @throws Exception
     */
    public function generate(array $entity): array
    {
        $parameters = ['codeArt' => $entity['CODE_ART'], 'site' => $entity['SITE']];

        $menuContextuel = [
            'listePrincipal' => [
                [
                    'icone' => 'visualiser_v2',
                    'libelle' => $this->trad->t('Visualiser'),
                    'lien' => $this->router->generateUri('Stock.StockLocal.visualiser', $parameters),
                ],
                [
                    'icone' => 'documents_attaches',
                    'libelle' => $this->trad->t('Documents rattachés'),
                    'lien' => $this->router->generateUri('GlobalApplication.DocumentRattaches.document', [
                        'MODULE' => 'StockLocal',
                        'id' => Docatt::getCodeEnr('SSTOCKLO', $entity),
                    ]),
                ]
            ],
            'listeSecondaire' => [
                [
                    'target' => '_blank',
                    'libelle' => $this->trad->t('Imprimer étiquette'),
                    'lien' => $this->router->generateUri('Stock.StockLocal.imprimerEtiquette', $parameters),
                ]
            ]
        ];

        if (Roles::droitsUtilisateur($this->pdo, 'ST_STL_MOD')) {
            $menuContextuel['listeSecondaire'][] = [
                'libelle' => $this->trad->t('Modifier'),
                'lien' => $this->router->generateUri('Stock.StockLocal.modifierForm', $parameters),
            ];
        }

        return $menuContextuel;
    }
}
