<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\HttpKernel\KernelInterface;
use App\Controller\WebrootController;

class MainController extends WebrootController
{
    #[Route('/', name: 'app_main')]
    public function index(KernelInterface $kernel): Response
    {
        $dotenvlocal = join(DIRECTORY_SEPARATOR,[$kernel->getProjectDir(),".env.local"]);
        if (!file_exists($dotenvlocal)) {
            return $this->redirectToRoute('webroot.setup');
        }
        
        $user = $this->getUser();
        if (!$user) {
            return $this->redirectToRoute("app_login");
        }
        
        return $this->render('main/index.html.twig', array_merge(
                $this->getControllerVariables(),
                [
                    'user' => $user,
                ]));
    }
}
