<?php

use App\Http\Controllers\InstallController;
use App\Http\Controllers\PwaManifestController;
use Illuminate\Support\Facades\Route;

Route::middleware(['throttle:10,1'])->group(function () {
    Route::get('/install', [InstallController::class, 'show'])->name('install.show');
    Route::post('/install', [InstallController::class, 'store'])->name('install.store');
});

/**
 * Manifest PWA dinámico (nombre + iconos desde app_settings).
 * En Apache/cPanel, si existe public/manifest.json del build, ese archivo gana a Laravel:
 * borrar manifest.json del despliegue o no copiarlo a public/.
 */
Route::get('/site.webmanifest', [PwaManifestController::class, 'show']);
Route::get('/manifest.json', [PwaManifestController::class, 'show']);
Route::get('/manifest.webmanifest', [PwaManifestController::class, 'show']);

// No capturar /api/*: si falta una ruta API, el catch-all devolvía 405 en PUT ("solo GET/HEAD").
Route::get('/{any}', function () {
    return file_get_contents(public_path('index.html'));
})->where('any', '^(?!api(?:/|$))(?!install(?:/|$)).*');
