<?php

namespace Modules\Consultation\MenuContextuel;

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

class QuestionReponseMenuContextuel extends MenuContextuel
{
    /**
     * Summary of generate
     * @param array<mixed> $qr
     * @return array<mixed>
     */
    public function generate($qr)
    {
        if ($qr['AUTEUR_OXALINK'] == '') {
            $menuContextuel['listeSecondaire'][] = [
                'lien' => $this->router->generateUri('Consultation.QuestionReponse.createEditQuestion', [
                                'idAO'      => $qr['NO_AO'],
                                'typeFG'    => $qr['ORIGIN_TYPE_FG']? $qr['ORIGIN_TYPE_FG']:$qr['TYPE_FG'],
                                'idFrs'     => $qr['ORIGIN_CODE_FOU']? $qr['ORIGIN_CODE_FOU']:$qr['CODE_FOU'],
                                'idQst'     => $qr['ORIGIN_ID_QR']? $qr['ORIGIN_ID_QR']:$qr['ID_QR']
                            ]),
                'libelle' => $this->trad->t('Modifier la question'),
            ];
        }

        $menuContextuel['listeSecondaire'][] = [
            'lien' => $this->router->generateUri('Consultation.QuestionReponse.repondre', [
                            'idAO'      => $qr['NO_AO'],
                            'typeFG'    => $qr['ORIGIN_TYPE_FG']? $qr['ORIGIN_TYPE_FG']:$qr['TYPE_FG'],
                            'idFrs'     => $qr['ORIGIN_CODE_FOU']? $qr['ORIGIN_CODE_FOU']:$qr['CODE_FOU'],
                            'idQst'     => $qr['ORIGIN_ID_QR']? $qr['ORIGIN_ID_QR']:$qr['ID_QR']
                        ]),
            'libelle' => $this->trad->t('Réponse avancée'),
        ];

        $deleteRoute = $this->router->generateUri('Consultation.QuestionReponse.delete', [
            'idAO'      => $qr['NO_AO'],
            'typeFG'    => $qr['ORIGIN_TYPE_FG']? $qr['ORIGIN_TYPE_FG']:$qr['TYPE_FG'],
            'idFrs'     => $qr['ORIGIN_CODE_FOU']? $qr['ORIGIN_CODE_FOU']:$qr['CODE_FOU'],
            'idQst'     => $qr['ORIGIN_ID_QR']? $qr['ORIGIN_ID_QR']:$qr['ID_QR']
        ]);

        if ($qr['AUTEUR_OXALINK'] == '') {
            $menuContextuel['listeSecondaire'][] = [
                'lien' => '',
                'lienJs' => $this->popupConfirm(
                    false,
                    $deleteRoute,
                    $this->trad->t('Etes-vous sûr de vouloir supprimer la question ?'),
                    true,
                    'Consultation',
                    '',
                    false,
                    'filtre_Consultation'
                ),
                'libelle' => $this->trad->t('Supprimer la question/réponse'),
            ];
        }

        /** @phpstan-ignore-next-line */
        if ($qr['REP'] && (!Sql::boolSql($qr['PUBLIC']) || (Sql::boolSql($qr['PUBLIC']) && $qr['DATE_ENV_REP']) != '00000000')) {
            $route = $this->router->generateUri('Consultation.QuestionReponse.envoieUnitaire', [
                        'idAO'      => $qr['NO_AO'],
                        'typeFG'    => $qr['TYPE_FG'],
                        'idFrs'     => $qr['CODE_FOU'],
                        'idQst'     => $qr['ID_QR']
            ]);
            $menuContextuel['listeSecondaire'][] = [
                'lien' => '',
                'lienJs' => $this->popupConfirm(
                    false,
                    $route,
                    $this->trad->t('Etes-vous sûr de vouloir envoyer la réponse ?'),
                    true,
                    'Consultation',
                    '',
                    false,
                    'filtre_Consultation'
                ),
                'libelle' => $this->trad->t('Envoi unitaire'),
            ];
        }

        $menuContextuel['listeSecondaire'][] = [
            'lien' => $this->router->generateUri('Consultation.Event.suivi', [
                'id'        => $qr['NO_AO'],
                'typeFG'    => $qr['TYPE_FG'],
                'idFrs'     => $qr['CODE_FOU'],
                'idQst'     => $qr['ID_QR']
            ]),
            'libelle' => $this->trad->t('Suivi des évènements'),
        ];
        

        return $menuContextuel;
    }
}
