<?php
namespace Controleur;

Class FrontControleur{

    private $listAction = ['visiteur' => array('accueil','search','quote','login','singin'),
                    'user' => array('quiz','commentary','favorite','logout'),
                    'admin' => array()];
    
    private string $role = 'visiteur';
    
    public function __construct(){
        global $twig;
        session_start();
        
        $dVueEreur = [];

        $router = new \AltoRouter();

        $router->map('GET', '/', 'FrontController');
        $router->map('GET', '/user/quote/[p1:param1]?', 'UserController');

        $match = $router->match();
        if(!$match){
            $dVueEreur[] = "Requette introuvable";
            $this->vueErreur($dVueEreur);
        }
        else{
            
        }


    }

    private function ifExisteAction(string $action):bool {
        if( in_array($action , $listAction['admin']) || in_array($action , $listAction['user']) || in_array($action , $listAction['visiteur'])) return true;
        
        return false;
    }

    private function verifDroit(string $action):bool {
        if( in_array($action , $listAction['admin']) && $role == 'admin') return true;
        elseif( in_array($action , $listAction['user']) && ($role == 'admin' || $role == 'user') ) return true;
        elseif(in_array($action , $listAction['visiteur']) && ($role == 'admin'|| $role == 'user'|| $role == 'visiteur')) return true;
        return false;
    }

    private function vueErreur(array $dVueErreur){
        global $vues;
        echo "{$dVueErreur[0]}";
        require_once $vues['erreur'];
    }

}
