<?php
namespace Modules\Catalogue\MenuContextuel;

use Entity\Model\CFormats;
use Helpers\Ariane\Ariane;
use Helpers\Outil\MenuContextuel;
use Helpers\QueryBuilder\AbsRepository;
use Helpers\Trad\Trad;
use Skeleton\Controller\Controller;

class VersionMenuContextuel extends MenuContextuel
{
    /**
     * @param array<mixed> $version
     * @return array<mixed>
     */
    public function generate($version)
    {
        $id = $version['ID_CATAL'];
        $idVersion = $version['IDATACATA'];

        $menuContextuel['listeSecondaire'][] = [
            'libelle' => $this->trad->t('Modifier'),
            'lien' => $this->router->generateUri('Catalogue.VersionCataExterne.createEdit', ['idCatalogue' => $id, 'idVersion' => $idVersion]),
        ];

        $menuContextuel['listeSecondaire'][] = [
            'libelle' => $this->trad->t('Chargement'),
            'lienJs'  => $this->ajaxPopupV2(
                $this->router->generateUri('Catalogue.ChargementCatalogue.chargement', ['idVersion' => $idVersion]),
                '',
                $this->trad->t('Chargement')
            )
        ];

        $menuContextuel['listeSecondaire'][] = [
            'libelle' => $this->trad->t('Contrôle'),
            'lien' => $this->router->generateUri('Catalogue.ControleVersion.listeArticles', ['idVersion' => $idVersion]),
        ];

        $menuContextuel['listeSecondaire'][] = [
            'libelle' => $this->trad->t('Assistant'),
            'lienJs'  => $this->ajaxPopup(
                $this->router->generateUri('Catalogue.ChargementCatalogue.assistant', ['idVersion' => $idVersion]),
                $this->trad->t('Assistant')
            )
        ];

        if ($version['STATUT'] == 'H') {
            $menuContextuel['listeSecondaire'][] = [
                'libelle'   => $this->trad->t('Supprimer'),
                'lienJs'    => $this->popupConfirm(
                    false,
                    $this->router->generateUri('Catalogue.VersionCataExterne.delete', ['idVersion' => $idVersion]),
                    Trad::strBuild($this->trad->t('Etes-vous sûr de vouloir supprimer la version @1@ ?'), $version['VERSCATA']),
                    false,
                    'versionCatalogue',
                    '',
                    false,
                    ''
                ),
            ];
    
            $menuContextuel['listeSecondaire'][] = [
                'libelle'   => $this->trad->t('RAZ'),
                'lienJs'    => $this->popupConfirm(
                    false,
                    $this->router->generateUri('Catalogue.VersionCataExterne.RAZ', ['idVersion' => $idVersion]),
                    Trad::strBuild($this->trad->t('Etes-vous sûr de vouloir supprimer le contenu la version @1@ ?'), $version['VERSCATA']),
                    false,
                    'versionCatalogue',
                    '',
                    false,
                    ''
                ),
            ];
        }

        return $menuContextuel;
    }
}
