<?php
namespace Modules\Index\Controller;

use Entity\Model\Metadata\EntityMetaQb;
use Entity\Model\Metadata\PartnFournissDemModif;
use Helpers\Ariane\Ariane;
use Modules\Index\Service\TableauDeBordService;
use Skeleton\Controller\Controller;
use Modules\Index\Repository\Index;
use GuzzleHttp\Psr7\Response;

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(),
            'getdocS2C'     => $tableauDeBordService->getdocS2C(),
            'blocEval'      => $tableauDeBordService->getBlocEval(),
            'supplierCategories' => $tableauDeBordService->getSupplierTDB(),
        ]);
    }
    
    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,
        ]);
    }
}
