<?php

use App\Http\Controllers\InstallationController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

// Installation Routes
Route::middleware(['install'])->group(function () {
    Route::get('/install', [InstallationController::class, 'welcome'])->name('install.welcome');
    Route::get('/install/requirements', [InstallationController::class, 'requirements'])->name('install.requirements');
    Route::get('/install/database', [InstallationController::class, 'database'])->name('install.database');
    Route::get('/install/admin', [InstallationController::class, 'admin'])->name('install.admin');
    Route::get('/install/company', [InstallationController::class, 'company'])->name('install.company');
    Route::get('/install/api-keys', [InstallationController::class, 'apiKeys'])->name('install.api-keys');
    
    // API routes for installation
    Route::post('/install/test-database', [InstallationController::class, 'testDatabase'])->name('install.test-database');
    Route::post('/install/process', [InstallationController::class, 'install'])->name('install.process');
});

// Admin Panel Route (will be handled by React)
Route::get('/admin/{any?}', function () {
    return view('admin');
})->where('any', '.*')->name('admin');

// Fallback route
Route::get('/', function () {
    if (config('app.installed', false)) {
        return redirect('/admin');
    }
    return redirect('/install');
});