<?php

namespace Modules\Stock\MenuContextuel;

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

class StockArticleContextuel 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
    {
        return [
            'listePrincipal' => [
                [
                    'icone' => 'modifier_v2',
                    'libelle' => $this->trad->t('Modifier'),
                    'lien' => $this->router->generateUri('Stock.StockArticle.modifierForm', ['codeArt' => $entity['CODE_ART']]),
                ],
                [
                    'icone' => 'documents_attaches',
                    'libelle' => $this->trad->t('Documents rattachés'),
                    'lien' => $this->router->generateUri('GlobalApplication.DocumentRattaches.document', [
                        'MODULE' => 'StockArticle',
                        'id' => $entity['CODE_ART']
                    ]),
                ]
            ],
            'listeSecondaire' => [
                [
                    'libelle' => $this->trad->t('Stock global'),
                    'lienJs' => 'ajaxPopup('
                        . json_encode($this->router->generateUri('Stock.StockArticle.stockGlobal', ['codeArt' => $entity['CODE_ART']])) . ','
                        . json_encode(Trad::strBuild($this->trad->t('Stock global article @1@ - @2@'), $entity['CODE_ART'], $entity['DESIGN']))
                    . ')'
                ],
                [
                    'libelle' => $this->trad->t('Mouvements'),
                    'lien' => $this->router->generateUri('Stock.StockArticle.mouvements', ['codeArt' => $entity['CODE_ART']]),
                ],
                [
                    'libelle' => $this->trad->t('Stock par société'),
                    'lien' => $this->router->generateUri('Stock.StockArticle.stockParSociete', ['codeArt' => $entity['CODE_ART']]),
                ],
                [
                    'libelle' => $this->trad->t('Stock local'),
                    'lien' => $this->router->generateUri('Stock.StockArticle.stockArticleParSite', ['codeArt' => $entity['CODE_ART']]),
                ],
                [
                    'libelle' => $this->trad->t('Articles de remplacement'),
                    'lien' => $this->router->generateUri('Stock.StockArticle.articlesDeRemplacementForm', ['codeArt' => $entity['CODE_ART']]),
                ],
                [
                    'libelle' => $this->trad->t('Fournisseurs préférentiels'),
                    'lien' => $this->router->generateUri('Stock.StockArticle.fournisseursPreferentielsForm', ['codeArt' => $entity['CODE_ART']]),
                ]
            ]
        ];
    }
}
