<?php

namespace App\Controller;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

final class SpaController
{
    #[Route('/app/{path}', name: 'app_spa', requirements: ['path' => '.*'], defaults: ['path' => ''], methods: ['GET'])]
    public function __invoke(): Response
    {
        $index = dirname(__DIR__, 2).'/public/app/index.html';
        $content = @file_get_contents($index);
        if (false === $content) {
            return new JsonResponse(['error' => 'frontend_not_built'], 503);
        }

        return new Response($content, 200, [
            'Content-Type' => 'text/html; charset=UTF-8',
            'Cache-Control' => 'no-store',
        ]);
    }
}
