<?php

namespace App\Controller;

use App\Container;
use App\Router\Request\IRequest;
use App\Router\Response\Response;
use Shared\Attributes\Route;
use Twig\Environment;
use Data\Core\Preferences;
use Shared\Log;

// TODO : Remove this BaseClass
class Controller extends BaseController
{
    private Environment $twig;
    private Preferences $preference;

    public function __construct()
    {
       session_start();
       $this->preference = new Preferences();
    }
    
    #[Route(path: '/', name: 'home', methods: ['GET'])]
    public function index(): Response
    {
        return $this->render('./page/home.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => [],
            'infoUser' => [],
            'exos' => [],
            'member' => []
        ]);
    }

    #[Route(path: '/analyses', name: 'analyses', methods: ['GET'])]
    public function analyses(): Response
    {
        return $this->render('./page/analyze.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => [],
            'infoUser' => [],
            'exos' => [],
            'member' => []
        ]);
    }

    #[Route(path: '/exercice', name: 'exercice', methods: ['GET'])] // 8
    public function exercice(): Response
    {
        return $this->render('./page/exercice.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => [],
            'infoUser' => [],
            'exos' => [],
            'member' => []
        ]);
    }
    #[Route(path: '/search-user', name: 'search-user', methods: ['GET'])]
    public function searchUser(string $username, IRequest $req): Response
    {
        $taberror = [];
        $utiliArray = [
            [
                'nom' => 'John',
                'prenom' => 'Doe',
                'img' => 'john_doe',
                'username' => 'johndoe',
            ],
            [
                'nom' => 'Alice',
                'prenom' => 'Smith',
                'img' => 'alice_smith',
                'username' => 'alicesmith',
            ],
        ];
        // if(!Validation::val_string($name)){
        try {
                //code...
                //     $model->userMgr->addFriend($name);
                return $this->render('./page/addfriend.html.twig',[
                    'css' => $this->preference->getCookie(),
                    'pp' => "test2",
                    'user' => "Doe",
                    'role' => "Athlète",
                    'friendship' => [],
                    'analyzes' => [],
                    'mails' => [],
                    'users' => $utiliArray,
                    'infoUser' => [],
                    'exos' => [],
                    'member' => [],
                    'responce' => "Notification d'ajout envoyée à $username"
                ]);
            } catch (\Throwable $th) {
                //throw $th;
                // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]);
            }
        // }
        
    }

    #[Route(path: '/add-friend', name: 'add-friend', methods: ['POST'])]
    public function addFriend(string $username, IRequest $req): Response
    {
        $taberror = [];
        $utiliArray = [
            [
                'nom' => 'John',
                'prenom' => 'Doe',
                'img' => 'john_doe',
                'username' => 'johndoe',
            ],
            [
                'nom' => 'Alice',
                'prenom' => 'Smith',
                'img' => 'alice_smith',
                'username' => 'alicesmith',
            ],
        ];
        // if(!Validation::val_string($name)){
        try {
                //code...
                //     $model->userMgr->addFriend($name);
                return $this->render('./page/addfriend.html.twig',[
                    'css' => $this->preference->getCookie(),
                    'pp' => "test2",
                    'user' => "Doe",
                    'role' => "Athlète",
                    'friendship' => [],
                    'analyzes' => [],
                    'mails' => [],
                    'users' => $utiliArray,
                    'infoUser' => [],
                    'exos' => [],
                    'member' => [],
                    'responce' => "Notification d'ajout envoyée à $username"
                ]);
            } catch (\Throwable $th) {
                //throw $th;
                // return $this->render("addfriend.html.twig", ['tabError' => $taberror ]);
            }
        // }
        
    }

    #[Route(path: '/friend', name: 'friend', methods: ['GET'])]
    public function friend(): Response
    {
        $utiliArray = [
            [
                'nom' => 'John',
                'prenom' => 'Doe',
                'img' => 'john_doe',
                'username' => 'johndoe',
            ],
            [
                'nom' => 'Alice',
                'prenom' => 'Smith',
                'img' => 'alice_smith',
                'username' => 'alicesmith',
            ],
        ];
        return $this->render('./page/addfriend.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => $utiliArray,
            'infoUser' => [],
            'exos' => [],
            'member' => [],
        ]);
    }

    #[Route(path: '/coaching', name: 'coaching', methods: ['GET'])]
    public function coaching(): Response
    {
        return $this->render('./page/coaching.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => [],
            'infoUser' => [],
            'exos' => [],
            'member' => []
        ]);
    }

    #[Route(path: '/mail', name: 'mail', methods: ['GET'])]
    public function mail(): Response
    {
        return $this->render('./page/mail.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => [],
            'infoUser' => [],
            'exos' => [],
            'member' => []
        ]);
    }

    #[Route(path: '/import', name: 'import', methods: ['GET'])]
    public function import(): Response
    {
        return $this->render('./page/import.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => [],
            'infoUser' => [],
            'exos' => [],
            'member' => []
        ]);
    }

    #[Route(path: '/settings', name: 'settings', methods: ['GET'])]
    public function settings(IRequest $req): Response
    {
        return $this->render('./page/settings.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => [],
            'infoUser' => [],
            'exos' => [],
            'member' => []
        ]);
    }

    #[Route(path: '/preferences', name: 'preferences', methods: ['POST'])]
    public function preferences(string $theme, IRequest $req): Response
    {
        /*TODO*/

        //  VALIDER LES DONNEES
        $this->preference->majCookie($theme);
       
        return $this->render('./page/settings.html.twig',[
            'css' => $this->preference->getCookie(),
            'pp' => "test2",
            'user' => "Doe",
            'role' => "Athlète",
            'friendship' => [],
            'analyzes' => [],
            'mails' => [],
            'users' => [],
            'infoUser' => [],
            'exos' => [],
            'member' => []
        ]);
    }

}



