<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\GuruController;
use App\Http\Controllers\StaffController;
use App\Http\Controllers\AbsensiController;
use App\Http\Controllers\PenggajianController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\IzinController;
use App\Http\Controllers\JadwalController;
use App\Http\Controllers\KelasController;
use App\Http\Controllers\MataPelajaranController;

/*
|--------------------------------------------------------------------------
| 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('/', function () {
    return redirect('/dashboard');
});

Route::get('/login', [AuthController::class,'loginForm'])->name('login');
Route::post('/login', [AuthController::class,'login']);

Route::middleware('auth')->group(function () {

    // PROFILE USER
    Route::get('/dashboard', [DashboardController::class, 'index'])->middleware('auth');
    Route::get('/profile', [UserController::class,'profile'])->middleware('auth');
    Route::get('/profile/password', [UserController::class, 'password']);
    Route::post('/profile/password', [UserController::class, 'updatePassword']);

    // ADMIN
    Route::middleware('role:admin')->group(function () {

        
        Route::resource('guru', GuruController::class);
        Route::resource('staff', StaffController::class);
        Route::resource('user', \App\Http\Controllers\UserController::class);
       
        // 🔥 JADWAL
        Route::resource('jadwal',JadwalController::class);
        Route::resource('kelas',KelasController::class);
        Route::resource(
            'mata-pelajaran',
            MataPelajaranController::class
        );
        // 🔥 PENGGAJIAN
        Route::get('/penggajian/generate', [PenggajianController::class,'generate']); 
        Route::get('/penggajian/export', [PenggajianController::class,'exportExcel']);
        Route::get('/penggajian/slip/{id}', [PenggajianController::class,'slip']);   
        Route::resource('penggajian', PenggajianController::class);
        
        

        // 🔥 MONITORING
        Route::get('/monitoring',[AbsensiController::class,'monitoring']);

    });

    // GURU
    Route::middleware('role:guru')->group(function () {

        
        Route::get('/absensi', [AbsensiController::class,'index']);
        Route::post('/absensi/hadir/{jadwal}',[AbsensiController::class,'hadir']);
        // 🔥 RIWAYAT ABSENSI
        Route::get('/absensi/riwayat', [AbsensiController::class,'riwayat']);
        Route::get('/absensi/rekap',[AbsensiController::class,'rekap']);
        // 🔥 PENGAJUAN IZIN
        Route::get('/izin',
        [IzinController::class,'index']);
        Route::get('/izin/create',
        [IzinController::class,'create']);
        Route::post('/izin',
        [IzinController::class,'store']);

    });

    // LOGOUT
    Route::post('/logout', [AuthController::class,'logout']);

});
