<?php

namespace Modules\GlobalApplication\MenuContextuel;

use Helpers\Outil\MenuContextuel;
use Helpers\Trad\ITrad;
use Skeleton\Router;

class PiecesJointesMenuContextuel extends MenuContextuel
{
    public string $module;

    /**
     * @var array<mixed>
     */
    public $droit;

    public function __construct(\PDO $pdo, Router $router, ITrad $trad)
    {
        parent::__construct($pdo, $router, $trad);
        $this->droit = [];
    }

    /**
     * @param array<mixed> $object
     * @return array<mixed>
     */
    public function generate($object, string $id, string $module, string $pathModification, string $pathSuppression)
    {
        $menuContextuel = [];

        if ($pathModification) {
            $menuContextuel['listeSecondaire'][] = [
                'libelle' => $this->trad->t('Modifier'),
                'lien' => '',
                'lienJs' => $this->redirectJSWithPost($pathModification, (string)json_encode(['noOrdre' => $object['NO_ORDRE']])),
            ];
        }

        if ($pathSuppression) {
            $menuContextuel['listeSecondaire'][] = [
                'libelle' => $this->trad->t('Supprimer'),
                'lien' => '',
                'lienJs' => $this->popupConfirm(
                    true,
                    $pathSuppression,
                    $this->trad->t('Etes-vous sûr de vouloir supprimer le document').' '.$object['TITRE'].' ?',
                    true,
                    'formulaireGeneral',
                    $object['NO_ORDRE'],
                    false,
                    '',
                ),
            ];
        }

        $menuContextuel['listeSecondaire'][] = [
            'libelle' => $this->trad->t('Télécharger'),
            'lien' => $this->router->generateUri('GlobalApplication.AjaxPiecesJointes.downloadFichier', ['MODULE' => $module, 'id' => $id, 'ordre' => $object['NO_ORDRE']]),
            'target'    => '_blank',
        ];

        return $menuContextuel;
    }
}
