<?php

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Route::get('/', fn () => redirect()->route('dashboard'));

// Auth
Route::livewire('/login', 'auth.login')->name('login')->middleware('guest');
Route::post('/logout', function () {
    Auth::logout();
    session()->invalidate();
    session()->regenerateToken();
    return redirect()->route('login');
})->name('logout')->middleware('auth');

// Authenticated
Route::middleware(['auth'])->group(function () {
    Route::livewire('/dashboard', 'dashboard')->name('dashboard');
    Route::livewire('/travel-requests/create', 'travel-request.create')->name('travel-requests.create');
    Route::livewire('/travel-requests/{id}', 'travel-request.show')->name('travel-requests.show');
    Route::livewire('/travel-requests/{id}/approve', 'travel-request.approve')
        ->name('travel-requests.approve')
        ->middleware('role:travel_approver|administrator');
});
