<?php

use App\Models\Extracuricullar;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\PerhitunganController;
use App\Http\Controllers\CriteriaController;
use App\Http\Controllers\DataUserController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\SubCriteriaController;
use App\Http\Controllers\ExtracurricularController;
use App\Http\Controllers\PenilaianController;
use App\Http\Controllers\TransformasiNilaiController;

/*
|--------------------------------------------------------------------------
| 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 view('home', [
        "title" => "Home"
    ]);
});

Route::get('/home', function () {
    return view('home',[
        "title" => "Home"
    ]);
})->name('home');

Route::get('/data-ekstrakurikuler', function () {
    return view('ekstrakurikuler', [
        "title" => "Ekstrakurikuler"
    ]);
});

Route::get('/login', function () {
    if (Auth::check()) {
        return redirect('/dashboard');
    }
    return view('auth.login');
})->name('login');
// Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/login', [AuthController::class, 'login']);

Route::get('/register', function () {
    if (Auth::check()) {
        return redirect('/login');
    }
    return view('auth.register');
})->name('register');
// Route::get('/register', [AuthController::class, 'showRegisterForm'])->name('register');
Route::post('/register', [AuthController::class, 'register']);

Route::get('/forgot-password', function () {
    if (Auth::check()) {
        return redirect('/dashboard');
    }
    return view('auth.forgot-password');
})->name('password.request');

Route::post('/forgot-password', [AuthController::class, 'sendResetLinkEmail'])->name('password.email');

Route::get('/reset-password/{token}', [AuthController::class, 'showResetForm'])->name('password.reset');
Route::post('/reset-password', [AuthController::class, 'resetPassword'])->name('password.update');

// Route::middleware(['auth', 'role:wakil_kepala'])->group(function () {
//     Route::get('/wakil_kepala/dashboard', [WakilKepalaController::class, 'dashboard'])->name('wakil_kepala.dashboard');
//     Route::get('/wakil_kepala/kriteria', [WakilKepalaController::class, 'kriteria'])->name('wakil_kepala.kriteria');
//     Route::get('/wakil_kepala/subkriteria', [WakilKepalaController::class, 'subkriteria'])->name('wakil_kepala.subkriteria');
// });

// Route::middleware(['auth', 'role:siswa'])->group(function () {
//     Route::get('/siswa/dashboard', [SiswaController::class, 'dashboard'])->name('siswa.dashboard');
// });

Route::middleware(['auth','web','PreventBackHistory'])->group(function () {
// Route::get('/dashboard', function () {
//     return view('dashboard.index');
// })->name('dashboard.index');
Route::resource('/dashboard', DashboardController::class);

Route::get('/user-profile', function () {
    if (!Auth::check()) {
        return redirect('/login');
    }
    return view('user.user-profile');
})->name('user-profile');
Route::post('/user-profile', [UserController::class, 'update_profile']);

Route::post('/update-profile-picture', [UserController::class, 'updateProfilePicture'])
        ->name('update-profile-picture');

Route::post('/update-password', [UserController::class, 'updatePassword'])->name('update-password');

Route::resource('ekstrakurikuler', ExtracurricularController::class);

Route::resource('kriteria', CriteriaController::class);
// Route::post('/kriteria/calculate', [CriteriaController::class, 'calculateBobotKriteria'])->name('kriteria.calculate');

Route::resource('subkriteria', SubCriteriaController::class);
// Route::post('/subkriteria/calculate', [SubCriteriaController::class, 'calculateBobotSubKriteria'])->name('subkriteria.calculate');

Route::resource('user', DataUserController::class);

Route::post('/kriteria/calculate', [PerhitunganController::class, 'calculateBobotKriteria'])->name('kriteria.calculate');
Route::post('/subkriteria/calculate', [PerhitunganController::class, 'calculateBobotSubKriteria'])->name('subkriteria.calculate');
Route::get('input-nilai', [PerhitunganController::class, 'penilaian'])->name(('penilaian.input-nilai'));
Route::post('/perhitungan/transformasiNilai', [PerhitunganController::class, 'transformasiNilai'])->name(('perhitungan.transformasiNilai'));

// Route::resource('input-nilai', PenilaianController::class);

Route::resource('transformasi-nilai', TransformasiNilaiController::class);

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

});
