<?php

namespace App\Controller;

use App\Service\Page;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{
    #[Route('/{slug}', name: 'default', requirements: ['slug' => '[a-zA-Z0-9\/]+'])]
    public function DefaultAction(Page $page, string $slug = 'index')
    {
        $return = $page->getPage($slug);
        $response = new Response('', (int)$return['status']);
        return $this->render('app.html.twig', $return, $response);
    }

    #[Route('/error/{status}', name: 'error', requirements: ['status' => '[0-9]{3}'], priority: 2)]
    public function ErrorAction(Page $page, string $status = '404')
    {
        $return = $page->getPage('error/' . $status);
        $response = new Response('', (int)$status);
        return $this->render('app.html.twig', $return, $response);
    }
}
