<?php

use App\Http\Controllers\ProfileController;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\ConfirmablePasswordController;
use App\Http\Controllers\Auth\EmailVerificationNotificationController;
use App\Http\Controllers\Auth\EmailVerificationPromptController;
use App\Http\Controllers\Auth\NewPasswordController;
use App\Http\Controllers\Auth\PasswordController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\VerifyEmailController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\SekolahController;
use App\Http\Controllers\KurikulumController;
use App\Http\Controllers\MapelController;
use App\Http\Controllers\AlternatifController;
use App\Http\Controllers\KriteriaController;
use App\Http\Controllers\SubkriteriaController;
use App\Http\Controllers\CripsController;
use App\Http\Controllers\OpsiSubkriteriaController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\PerhitunganController;
use App\Http\Controllers\TahunAjaranController;
use Illuminate\Support\Facades\Route;

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


Route::middleware('auth')->group(function () {
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
Route::get('/kriteria-by-kurikulum', [DashboardController::class, 'getKriteriaByKurikulum'])->name('getKriteriaByKurikulum');
Route::get('/hasil/{sesi_id}', [DashboardController::class, 'lihatHasil'])->name('lihatHasil');
Route::delete('/riwayat/{sesi_id}', [DashboardController::class, 'hapusRiwayat'])->name('hapusRiwayat');
Route::post('/submitpenilaian', [DashboardController::class, 'submitpenilaian'])->name('submitpenilaian');
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');
Route::put('/password', [PasswordController::class, 'update'])->name('password.update');
Route::get('/debug-saw/{sesiId}', [DashboardController::class, 'debugSAW'])->name('debug.saw');
Route::get('/cek-data-opsi/{kurikulumId}', [DashboardController::class, 'cekDataOpsi'])->name('cek.data.opsi');
// Route untuk debug hasil terbaru
Route::get('/debug-hasil', [DashboardController::class, 'debugHasilTerbaru'])->middleware('auth');

// Route untuk debug hasil spesifik  
Route::get('/debug-hasil/{sesiId}', [DashboardController::class, 'showDebugDetail'])->middleware('auth');
});

Route::middleware('guest')->group(function () {
Route::get('login', [AuthenticatedSessionController::class, 'create'])->name('login');
Route::post('login', [AuthenticatedSessionController::class, 'store']);
Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])->name('password.request');
Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])->name('password.email');
Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])->name('password.reset');
Route::post('reset-password', [NewPasswordController::class, 'store'])->name('password.store');
});

Route::middleware('auth')->group(function () {  
Route::get('verify-email', EmailVerificationPromptController::class)->name('verification.notice');
Route::get('verify-email/{id}/{hash}', VerifyEmailController::class)->middleware(['signed', 'throttle:6,1'])->name('verification.verify');
Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store'])->middleware('throttle:6,1')->name('verification.send');
Route::get('confirm-password', [ConfirmablePasswordController::class, 'show'])->name('password.confirm');
Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']);
Route::put('password', [PasswordController::class, 'update'])->name('password.update');
Route::post('logout', [AuthenticatedSessionController::class, 'destroy'])->name('logout');
});

Route::prefix('admin')->middleware(['auth', 'admin'])->group(function () {
    Route::get('dashboard', [HomeController::class, 'dashboard'])->name('admin.dashboard');
    Route::post('toggle-quiz-access', [HomeController::class, 'toggleQuizAccess'])->name('admin.toggle-quiz-access');

    
    Route::get('sekolah', [SekolahController::class, 'sekolah'])->name('sekolah');
    Route::post('sekolah/tambah', [SekolahController::class, 'tambahsekolah'])->name('tambah.sekolah');
    Route::put('sekolah/update/{id}', [SekolahController::class, 'updatesekolah'])->name('update.sekolah');
    Route::get('sekolah/hapus/{id}', [SekolahController::class, 'hapussekolah'])->name('hapus.sekolah');
    Route::get('sekolah/download', [SekolahController::class, 'downloadsekolah'])->name('download.sekolah');

    Route::get('kelas', [SekolahController::class, 'kelas'])->name('kelas');
    Route::get('kelas/getkelas/{id}', [SekolahController::class, 'getkelas']);
    Route::post('kelas/tambah', [SekolahController::class, 'tambahkelas'])->name('tambah.kelas');
    Route::put('kelas/update/{id}', [SekolahController::class, 'updatekelas'])->name('update.kelas');
    Route::get('kelas/hapus/{id}', [SekolahController::class, 'hapuskelas'])->name('hapus.kelas');
    Route::get('kelas/download', [SekolahController::class, 'downloadkelas'])->name('download.kelas');

    Route::get('tahunajaran', [TahunAjaranController::class, 'tahunajaran'])->name('tahunajaran');
    Route::post('tahunajaran/tambah', [TahunAjaranController::class, 'tambahtahunajaran'])->name('tambah.tahunajaran');
    Route::put('tahunajaran/update/{id}', [TahunAjaranController::class, 'updatetahunajaran'])->name('update.tahunajaran');
    Route::get('tahunajaran/hapus/{id}', [TahunAjaranController::class, 'hapustahunajaran'])->name('hapus.tahunajaran');
    Route::get('tahunajaran/download', [TahunAjaranController::class, 'downloadtahunajaran'])->name('download.tahunajaran');
    Route::get('tahunajaran/setaktif/{id}', [TahunAjaranController::class, 'setaktif'])->name('setaktif.tahunajaran');

    Route::get('siswa', [SekolahController::class, 'siswa'])->name('siswa');
    Route::post('siswa/tambah', [SekolahController::class, 'tambahsiswa'])->name('tambah.siswa');
    Route::put('siswa/update/{id}', [SekolahController::class, 'updatesiswa'])->name('update.siswa');
    Route::get('siswa/hapus/{id}', [SekolahController::class, 'hapussiswa'])->name('hapus.siswa');
    Route::get('siswa/download', [SekolahController::class, 'downloadsiswa'])->name('download.siswa');

    Route::get('kurikulum', [KurikulumController::class, 'kurikulum'])->name('kurikulum');
    Route::post('kurikulum/tambah', [KurikulumController::class, 'tambahkurikulum'])->name('tambah.kurikulum');
    Route::put('kurikulum/update/{id}', [KurikulumController::class, 'updatekurikulum'])->name('update.kurikulum');
    Route::get('kurikulum/hapus/{id}', [KurikulumController::class, 'hapuskurikulum'])->name('hapus.kurikulum');
    Route::get('kurikulum/download', [KurikulumController::class, 'downloadkurikulum'])->name('download.kurikulum');

    Route::get('mapel', [MapelController::class, 'mapel'])->name('mapel');
    Route::post('mapel/tambah', [MapelController::class, 'tambahmapel'])->name('tambah.mapel');
    Route::put('mapel/update/{id}', [MapelController::class, 'updatemapel'])->name('update.mapel');
    Route::get('mapel/hapus/{id}', [MapelController::class, 'hapusmapel'])->name('hapus.mapel');
    Route::get('mapel/download', [MapelController::class, 'downloadmapel'])->name('download.mapel');


    Route::get('alternatif', [AlternatifController::class, 'alternatif'])->name('alternatif');
    Route::post('alternatif/tambah', [AlternatifController::class, 'tambahalternatif'])->name('tambah.alternatif');
    Route::put('alternatif/update/{id}', [AlternatifController::class, 'updatealternatif'])->name('update.alternatif');
    Route::get('alternatif/hapus/{id}', [AlternatifController::class, 'hapusalternatif'])->name('hapus.alternatif');
    Route::get('alternatif/download', [AlternatifController::class, 'downloadalternatif'])->name('download.alternatif');

    Route::get('kriteria', [KriteriaController::class, 'kriteria'])->name('kriteria');
    Route::post('kriteria/tambah', [KriteriaController::class, 'tambahkriteria'])->name('tambah.kriteria');
    Route::put('kriteria/update/{id}', [KriteriaController::class, 'updatekriteria'])->name('update.kriteria');
    Route::get('kriteria/hapus/{id}', [KriteriaController::class, 'hapuskriteria'])->name('hapus.kriteria');
    Route::get('kriteria/download', [KriteriaController::class, 'downloadkriteria'])->name('download.kriteria');

    Route::get('subkriteria', [SubkriteriaController::class, 'subkriteria'])->name('subkriteria');
    Route::post('subkriteria/tambah', [SubkriteriaController::class, 'tambahsubkriteria'])->name('tambah.subkriteria');
    Route::put('subkriteria/update/{id}', [SubkriteriaController::class, 'updatesubkriteria'])->name('update.subkriteria');
    Route::get('subkriteria/hapus/{id}', [SubkriteriaController::class, 'hapussubkriteria'])->name('hapus.subkriteria');
    Route::get('subkriteria/download', [SubKriteriaController::class, 'downloadsubkriteria'])->name('download.subkriteria');

    Route::get('opsisubkriteria', [OpsiSubkriteriaController::class, 'opsisubkriteria'])->name('opsisubkriteria');
    Route::post('opsisubkriteria/tambah', [OpsiSubkriteriaController::class, 'tambahopsisubkriteria'])->name('tambah.opsub');
    Route::put('opsisubkriteria/update/{id}', [OpsiSubkriteriaController::class, 'updateopsisubkriteria'])->name('update.opsub');
    Route::get('opsisubkriteria/hapus/{id}', [OpsiSubkriteriaController::class, 'hapusopsisubkriteria'])->name('hapus.opsub');
    Route::get('opsisubkriteria/download', [OpsiSubkriteriaController::class, 'downloadopsisubkriteria'])->name('download.opsub');

    Route::get('crips', [CripsController::class, 'crips'])->name('crips');
    Route::post('crips/tambah', [CripsController::class, 'tambahcrips'])->name('tambah.crips');
    Route::put('crips/update/{id}', [CripsController::class, 'updatecrips'])->name('update.crips');
    Route::get('crips/hapus/{id}', [CripsController::class, 'hapuscrips'])->name('hapus.crips');
    Route::get('crips/download', [CripsController::class, 'downloadcrips'])->name('download.crips');

    Route::get('user', [UserController::class, 'user'])->name('user');
    Route::post('user/tambah', [UserController::class, 'tambahuser'])->name('tambah.user');
    Route::put('user/update/{id}', [UserController::class, 'updateuser'])->name('update.user');
    Route::get('user/hapus/{id}', [UserController::class, 'hapususer'])->name('hapus.user');
    Route::get('user/download', [UserController::class, 'downloaduser'])->name('download.user');

    
    Route::get('/perhitungan', [PerhitunganController::class, 'index'])->name('perhitungan');
    Route::get('/saw/sesi/detail/{id}', [PerhitunganController::class, 'getSesiDetail']);
    Route::get('/saw/perhitungan/detail/{id}', [PerhitunganController::class, 'getPerhitunganDetail']);
    Route::get('/saw/sesi/print/{id}', [PerhitunganController::class, 'printSesiPDF'])->name('admin.saw.sesi.print');
    Route::get('/saw/sesi/print-all', [PerhitunganController::class, 'printAllSesiPDF'])->name('admin.saw.sesi.printAll');

    Route::get('/profilesaya', [ProfileController::class, 'profilesaya'])->name('profilesaya');
    Route::put('/profilesaya/update', [ProfileController::class, 'updateprofilesaya'])->name('profilesaya.update');
    Route::delete('/profilesaya/delete', [ProfileController::class, 'deleteprofilesaya'])->name('profilesaya.delete');
});