<?php

use App\Http\Controllers\DashboardController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\JabatanController;
use App\Http\Controllers\KualifikasiBidangController;
use App\Http\Controllers\TahunAngkatanController;
use App\Http\Controllers\DataAlumniController;
use App\Http\Controllers\FormAlumniController;
use App\Http\Controllers\ProsesKmeansController;
use App\Http\Controllers\HasilKmeansController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\ExportKmeansController;
use App\Http\Controllers\ForgotPasswordController;
use App\Http\Controllers\RegisterController;
use Illuminate\Support\Facades\Route;

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

// Login Routes
Route::get('/', [LoginController::class, 'index'])->name('login');
Route::post('/', [LoginController::class, 'login'])->name('login.process');
Route::get('/logout', [LoginController::class, 'logout'])->name('logout');
//Register routes
Route::get('register', [RegisterController::class, 'index'])->name('register');  // Form Registrasi
Route::post('register', [RegisterController::class, 'store']);  // Proses Registrasi
//forgot password
Route::get('/lupa-password', [ForgotPasswordController::class, 'showForm'])->name('password.request');
Route::post('/lupa-password', [ForgotPasswordController::class, 'verifyEmail'])->name('password.verify');

// Reset password
Route::get('/reset-password', [ForgotPasswordController::class, 'showResetForm'])->name('password.reset.form');
Route::post('/reset-password', [ForgotPasswordController::class, 'resetPassword'])->name('password.reset');


// Routes that require authentication
Route::middleware(['auth.check'])->group(function () {

    Route::get('/formalumni', [FormAlumniController::class, 'index'])->name('formalumni');
    // Pindahkan dua baris ini ke sini dari dalam group admin.check
    Route::post('/formalumni/store', [FormAlumniController::class, 'store'])->name('form_alumni.store');
    Route::put('/formalumni/{id}', [FormAlumniController::class, 'update'])->name('formalumni.update');


    // Admin routes - only accessible by users with admin role
    Route::middleware(['admin.check'])->group(function () {
        // Dashboard
        Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
        Route::post('/dashboard/filter', [DashboardController::class, 'filter'])->name('dashboard.filter');

        // User Management
        // Route::get('/datauser', [UserController::class, 'index'])->name('user');
        // Route::post('/user/store', [UserController::class, 'store'])->name('user.store');
        // Route::put('/user/update/{id}', [UserController::class, 'update'])->name('user.update');
        // Route::delete('/user/delete/{id}', [UserController::class, 'destroy'])->name('user.delete');
        Route::get('/datauser', [UserController::class, 'index'])->name('user');
        Route::post('/store', [UserController::class, 'store'])->name('store');
        Route::put('/user/update/{id}', [UserController::class, 'update'])->name('user.update');
        //Route::delete('/user/delete/{id}', [UserController::class, 'destroy'])->name('user.delete');
        Route::delete('/user/{id}', [UserController::class, 'destroy'])->name('user.destroy');


        // Jabatan (Position) Management
        Route::get('/jabatan', [JabatanController::class, 'index'])->name('jabatan.index');
        Route::post('/jabatan/store', [JabatanController::class, 'store'])->name('jabatan.store');
        Route::put('/jabatan/update/{id_kategori}', [JabatanController::class, 'update'])->name('jabatan.update');
        Route::delete('/jabatan/destroy/{id_kategori}', [JabatanController::class, 'destroy'])->name('jabatan.destroy');

        // Kualifikasi Bidang (Field Qualification) Management
        Route::get('/kualifikasi_bidang', [KualifikasiBidangController::class, 'index'])->name('kualifikasi.index');
        Route::post('/kualifikasi_bidang/store', [KualifikasiBidangController::class, 'store'])->name('kualifikasi.store');
        Route::put('/kualifikasi_bidang/update/{id_kualifikasi}', [KualifikasiBidangController::class, 'update'])->name('kualifikasi.update');
        Route::delete('/kualifikasi_bidang/destroy/{id_kualifikasi}', [KualifikasiBidangController::class, 'destroy'])->name('kualifikasi.destroy');

        // Tahun Angkatan (Graduation Year) Management
        Route::get('/tahun_angkatan', [TahunAngkatanController::class, 'index'])->name('tahun_angkatan.index');
        Route::post('/tahun_angkatan/store', [TahunAngkatanController::class, 'store'])->name('tahun_angkatan.store');
        Route::put('/tahun_angkatan/update/{id_angkatan}', [TahunAngkatanController::class, 'update'])->name('tahun_angkatan.update');
        Route::delete('/tahun_angkatan/destroy/{id_angkatan}', [TahunAngkatanController::class, 'destroy'])->name('tahun_angkatan.destroy');

        // Data Alumni Management
        Route::get('/data_alumni', [DataAlumniController::class, 'index'])->name('data_alumni.index');
        Route::post('/data_alumni/store', [DataAlumniController::class, 'store'])->name('data_alumni.store');
        Route::put('/data_alumni/update/{id_alumni}', [DataAlumniController::class, 'update'])->name('data_alumni.update');
        Route::delete('/data_alumni/destroy/{id_alumni}', [DataAlumniController::class, 'destroy'])->name('data_alumni.destroy');
        //download template
        Route::get('/template-data-alumni', [DataAlumniController::class, 'downloadTemplate'])->name('data_alumni.template');
        //perlu di review
        Route::put('/alumni/{id}/reset-review', [DataAlumniController::class, 'resetReview'])->name('data_alumni.reset_review');
        Route::put('/alumni/{id}/tandai-review', [DataAlumniController::class, 'tandaiPerluReview'])->name('data_alumni.tandai_review');
        Route::get('/data-alumni/perlu-review', [DataAlumniController::class, 'perluReview'])->name('admin.alumni.perlu-review');

        // Excel Import
        Route::post('/data_alumni/import', [DataAlumniController::class, 'import'])->name('data_alumni.import');

        // K-Means Classification  
        Route::get('/proses-klasifikasi', [ProsesKmeansController::class, 'index'])->name('proses_klasifikasi');
        Route::post('/proses-klasifikasi', [ProsesKmeansController::class, 'proses'])->name('proses_klasifikasi_proses');

        // Results Storage and Display Routes
        Route::get('/hasil-klasifikasi', [HasilKmeansController::class, 'index'])->name('hasil_klasifikasi.index');
        Route::get('/hasil-klasifikasi/{id_angkatan}', [HasilKmeansController::class, 'show'])->name('hasil_klasifikasi.show');
        Route::post('/hasil-klasifikasi/simpan', [HasilKmeansController::class, 'store'])->name('simpan_hasil_klasifikasi');
        Route::post('/hasil-klasifikasi', [HasilKmeansController::class, 'store'])->name('hasil_klasifikasi.store');

        //Eksport
        Route::get('/export-kmeans', [ExportKmeansController::class, 'index'])->name('export.kmeans.index');
        Route::get('/export-kmeans/pdf/{id_angkatan}', [ExportKmeansController::class, 'exportPDF'])->name('export.kmeans.pdf');
        Route::get('/export-kmeans/excel/{id_angkatan}', [ExportKmeansController::class, 'exportExcel'])->name('export.kmeans.excel');
    });
});
