<?php
namespace Modules\Catalogue\MenuContextuel;

use Entity\Model\CFormats;
use Helpers\Ariane\Ariane;
use Helpers\Outil\MenuContextuel;
use Helpers\Outil\Sql;
use Helpers\Parametres\Constante;
use Helpers\QueryBuilder\AbsRepository;
use Skeleton\Controller\Controller;

class ArticleEquivalentMenuContextuel extends MenuContextuel
{
    /**
     * @param array<mixed> $article
     * @return array<mixed>
     */
    public function generate($article, int $countArt)
    {
        $menuContextuel['listeSecondaire'][] = [
            'libelle' => $this->trad->t('Dissocier article'),
            'lienJs' => $this->popupConfirm(
                false,
                $this->router->generateUri('Catalogue.ArticleEquivalent.dissocier', [
                    'codeArt'   => $article['CODEART']  ==''? 'noID':$article['CODEART'],
                    'codeFou'   => $article['CODEFOUR'] ==''? 'noID':$article['CODEFOUR'],
                    'artFou'    => $article['ARTFOUR']  ==''? 'noID':$article['ARTFOUR'],
                    'codeFab'   => $article['CODEFAB']  ==''? 'noID':$article['CODEFAB'],
                    'artFab'    => $article['ARTFAB']   ==''? 'noID':$article['ARTFAB'],
                    'idClass'   => $article['CLASSNUM'] ==''? 'noID':$article['CLASSNUM'],
                ]),
                $this->trad->t('Etes-vous sûr de vouloir supprimer dissocier l\'article ?'),
                true,
                $countArt > 1? 'refreshDiv':'redirect',
                '',
                false,
                'filtre_equivalence'
            ),
        ];

        if (Sql::boolSql($article['REFERENCE']) == false) {
            $menuContextuel['listeSecondaire'][] = [
                'libelle' => $this->trad->t('Nouveau référent'),
                'lienJs' => $this->popupConfirm(
                    false,
                    $this->router->generateUri('Catalogue.ArticleEquivalent.referent', [
                        'codeArt'   => $article['CODEART']  ==''? 'noID':$article['CODEART'],
                        'codeFou'   => $article['CODEFOUR'] ==''? 'noID':$article['CODEFOUR'],
                        'artFou'    => $article['ARTFOUR']  ==''? 'noID':$article['ARTFOUR'],
                        'codeFab'   => $article['CODEFAB']  ==''? 'noID':$article['CODEFAB'],
                        'artFab'    => $article['ARTFAB']   ==''? 'noID':$article['ARTFAB'],
                        'idClass'   => $article['CLASSNUM'] ==''? 'noID':$article['CLASSNUM'],
                    ]),
                    $this->trad->t('Etes-vous sûr de vouloir changer l\'article référent ?'),
                    true,
                    'refreshDiv',
                    '',
                    false,
                    'filtre_equivalence'
                ),
            ];
        }

        return $menuContextuel;
    }
}
