<?php
namespace Modules\Index\Controller;

use Helpers\Ariane\Ariane;
use Helpers\Trad\Trad;
use Modules\Index\Service\TableauDeBordService;
use Skeleton\Controller\Controller;
use Modules\Index\Repository\Index;
use GuzzleHttp\Psr7\Response;
use Helpers\Log\LogSysteme;

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);

        $droit = $tableauDeBordService->getDroitTDB();
        $etatDoc = $tableauDeBordService->getEtatDocTDB();
        $getdocSignTDB = $tableauDeBordService->getdocSignTDB();
        $isPartenaire = $tableauDeBordService->getPartenaire();
        
        $typeAdmin = $_SESSION['AdmCentral']? 'centrale' : 'locale';
        
        return $this->renderer->render('@index/TableauDeBord/index', [
            'menuActive' => 'eproc',
            'partenaire' => $isPartenaire['ID1']??'',
            'droit' => $droit,
            'etatDoc' => $etatDoc,
            'getdocSignTDB' => $getdocSignTDB,
            'typeAdmin' => $typeAdmin,
            'login' => $_SESSION['Session_Login'],
        ]);
    }
    
    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,
        ]);
    }
}
