<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| VRC PWA shells (history-mode fallback)
|--------------------------------------------------------------------------
| Serve the Vite build for any sub-path so vue-router history mode survives a
| reload. Hashed assets in public/<dir>/ are served by the web server directly
| and never hit these routes. Until `npm run build` runs, a friendly notice is
| shown.
*/
foreach ([
    'vrc-app'       => 'pwa-vrc-owner',
    'vrc-staff-app' => 'pwa-vrc-staff',
] as $dir => $appName) {
    Route::prefix($dir)->group(function () use ($dir, $appName) {
        Route::get('/{any?}', function () use ($dir, $appName) {
            $shell = public_path($dir . '/index.html');
            if (! file_exists($shell)) {
                return response()->view('vrcPortalApi::build_notice', ['app' => $appName, 'dir' => $dir], 200);
            }
            return response()->file($shell, [
                'Content-Type'  => 'text/html; charset=utf-8',
                'Cache-Control' => 'no-store, must-revalidate',
                'Pragma'        => 'no-cache',
                'Expires'       => '0',
            ]);
        })->where('any', '.*');
    });
}
