<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\SecureDashboardController;

// Welcome page
Route::get('/', function () {
    return view('welcome');
});

// Authenticated routes
Route::middleware(['auth', 'verified'])->group(function () {
    
    // Universal dashboard (secure URL)
    Route::get('/dashboard', [SecureDashboardController::class, 'index'])->name('dashboard');
    
    // Profile management
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
    
    // Admin dashboard (temporary with old URL until we implement secure routing)
    Route::middleware(['role:admin|amministratore|super-admin'])->prefix('admin')->name('admin.')->group(function () {
        Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
    });
    
    // Super admin dashboard (temporary with old URL until we implement secure routing)  
    Route::middleware(['role:super-admin'])->prefix('superadmin')->name('superadmin.')->group(function () {
        Route::get('/', function() {
            return view('admin.dashboard'); // Use admin dashboard view for now
        })->name('dashboard');
    });
    
    // Session management for building selection
    Route::post('/session/stabile', function (\Illuminate\Http\Request $request) {
        $request->validate(['stabile' => 'required|string']);
        session(['stabile_corrente' => $request->input('stabile')]);
        return response()->json(['ok' => true]);
    })->name('session.stabile');
    
});

// Authentication routes
require __DIR__.'/auth.php';
