<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\SiswaController;
use App\Http\Controllers\GuruController;
use App\Http\Controllers\ProfilController;
use App\Http\Controllers\AuthController;

/*
|--------------------------------------------------------------------------
| SIMSekolah — Web Routes
|--------------------------------------------------------------------------
*/

// Jika mengakses root (/), otomatis dialihkan ke login jika belum login
Route::get('/', function () {
    return redirect()->route('login');
});

// ─── ROUTE KHUSUS TAMU (GUEST) ──────────────────────────────────────────
// Route ini hanya bisa diakses oleh orang yang BELUM login
Route::middleware('guest')->group(function () {
    // Route Login  
    Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [AuthController::class, 'prosesLogin'])->name('login.proses');

    // ─── routee register───
    Route::get('/register', [AuthController::class, 'showRegister'])->name('register');
    Route::post('/register', [AuthController::class, 'prosesRegister'])->name('register.proses');
});


// ─── ROUTE PROTEKSI (WAJIB LOGIN) ───────────────────────────────────────
// Route di dalam grup ini dikunci oleh middleware 'auth'. 
// Orang yang belum login TIDAK AKAN BISA masuk ke sini langsung.
Route::middleware('auth')->group(function () {

    // Proses Logout
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

    // Dashboard
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    Route::resource('siswa', SiswaController::class);

    Route::resource('guru', GuruController::class);

    // Profil Sekolah
    Route::get('/profil', [ProfilController::class, 'index'])->name('profil');

// }};
// }};

});

   
 