<?php
namespace Modules\Index\Controller;

use Entity\Model\CampEnt;
use Entity\Model\Hastutil;
use Entity\Model\Metadata\EntityMetaQb;
use Entity\Model\Metadata\PartnFournissDemModif;
use Entity\Model\ParamDico;
use Helpers\Ariane\Ariane;
use Helpers\Trad\Trad;
use Helpers\Outil\Sql;
use Modules\Evaluation\Service\ResultatService;
use Modules\Index\Service\TableauDeBordService;
use Modules\Parametrage\Evaluation\Service\ParamEvaluationService;
use Skeleton\Controller\Controller;
use Modules\Index\Repository\Index;
use GuzzleHttp\Psr7\Response;
use Helpers\Log\LogSysteme;
use Helpers\Outil\Roles;
use Modules\Evaluation\Repository\Resultat;

class TableauDeBordController extends Controller
{
    /**
     * @return Response|void
     */
    public function init()
    {
        if (!\Helpers\Roles\Predispatch::connectRole()) {
            return $this->redirect($this->contenaire->get('base').'index.php');
        }
    }

    public function indexAction() : string
    {
        Ariane::generate(0, 'eproc');
        $tableauDeBordService = new TableauDeBordService($this->pdo, false, $this->router, $this->getTranslationService());
        $droit = $tableauDeBordService->getDroitTDB();
        $isPartenaire   = $tableauDeBordService->getPartenaire();

        return $this->renderer->render('@index/TableauDeBord/index', [
            'menuActive'    => 'eproc',
            'partenaire'    => $isPartenaire['ID1']??'',
            'droit'         => $droit,
            'login'         => $_SESSION['Session_Login'],
            'countNotifSourceExt' =>(new EntityMetaQb($this->pdo))->countAllByStruct(PartnFournissDemModif::class),
            'etatDoc'       => $tableauDeBordService->getEtatDocTDB(),
            'getdocSignTDB' => $tableauDeBordService->getdocSignTDB(),
            'blocEval'      => $tableauDeBordService->getBlocEval(),
        ]);
    }
    
    public function favorisAction() : string
    {
        $index = new Index($this->pdo);
        $liste_favoris = $index->getFavoris();
        
        return $this->renderer->render('@index/_favoris', [
            'liste_favoris' => $liste_favoris,
            'popup' => true,
        ]);
    }
}
