<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Mahasiswa\BiodataController;
use App\Http\Controllers\Mahasiswa\DashboardController;

/*
|--------------------------------------------------------------------------
| 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!
|
*/


Route::get('login', [LoginController::class, 'index'])->name('login');
Route::post('login', [LoginController::class, 'login']);
Route::post('logout', [LoginController::class, 'logout'])->name('logout');
// Route::get('sso/{email}/{sessionid}', [LoginController::class, 'sso']);

Route::get('/', function () {
    if (auth()->check()) {
        if (auth()->user()->role == 'laman') {
            return redirect()->route('mahasiswa.dashboard');
        }
        elseif (auth()->user()->role == 'admin') {
            return redirect()->route('admin.dashboard');
        } else {
            return redirect()->route('login');
        }
    }

    return redirect()->route('login');
});

Route::middleware('auth')->group(function () {
    // Routes for Admin

    // Routes for Mahasiswa
    Route::prefix('pendaftar')->middleware('role:laman')->group(function () {
        Route::get('dashboard', [DashboardController::class, 'index'])->name('mahasiswa.dashboard');
        Route::resource('biodata', BiodataController::class);
    });
});

Route::get('/logout', [LoginController::class, 'logout'])->name('admin.logout');