<?php

namespace Modules\Facture\MenuContextuel;

use Entity\Model\Enum\EFacDematFlowStatus;
use Entity\Model\Paravrac;
use Helpers\Outil\MenuContextuel;
use Helpers\Outil\Sql;
use Helpers\Trad\ITrad;
use Helpers\Trad\Trad;
use Skeleton\Router;

class GestionFacDematMenuContextuel extends MenuContextuel
{
    public function __construct(\PDO $pdo, Router $router, ITrad $trad)
    {
        parent::__construct($pdo, $router, $trad);
    }

    /**
     * @param array<mixed> $item
     * @return array<mixed>
     */
    public function generate($item)
    {
        $trad = $this->trad;
        
        $needResolve = $item['hasValidError'];
        return [
            'listeSecondaire' => array_filter([
                [
                    'libelle' => $trad->t('Visualiser le lisible'),
                    'route' => 'Facture.Demat.visual',
                    'routeParam' => ['id' => $item['ID']],
                    'target' => 'blank'
                ],
                ($needResolve ? [
                    'libelle' => $trad->t('Résoudre'),
                    'route' => 'Facture.Demat.formResolve',
                    'routeParam' => ['id' => $item['ID']],
                ] : null),
                ($needResolve ? [
                    'libelle' => $trad->t('Refuser'),
                    'route' => 'Facture.Demat.formRefus',
                    'routeParam' => ['id' => $item['ID']],
                ] : []),
                (!empty($item['NUM_FACT']) ? [
                    'libelle' => $trad->t('Détail de la facture intégrée'),
                    'lienJs' => $this->redirectJSWithPost2(
                        'Facture.GestionFacture.index',
                        [],
                        ['filter_egal_NUMFACTURE' => $item['NUM_FACT']]
                    ),
                ] : null),
            ])
        ];
    }
}
