<?php

use GuzzleHttp\Middleware;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\RegisterUserController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\Auth\ForgotPasswordController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/



Route::get('/forgot-password', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request');
Route::post('/forgot-password', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email');
Auth::routes(['verify' => false, 'register' => false]);

// Route untuk halaman welcome dan redirect ke home jika sudah login
Route::get('/', function () {
        return view('welcome');
})->name('welcome');


// Route untuk dashboard yang memerlukan autentikasi
Route::get('/home', [HomeController::class, 'index'])->name('home');

Route::get('/register', [RegisterUserController::class, 'showRegistrationForm'])->name('register.user');
Route::post('/register/user', [RegisterUserController::class, 'register'])->name('register.user.submit');

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

    // Route untuk Admin
    Route::get('/admin/home', [App\Http\Controllers\HomeController::class, 'adminHome'])
    ->name('admin.home')
    ->middleware('admin');

    Route::get('/user/home', [App\Http\Controllers\HomeController::class, 'userHome'])
    ->name('user.home')
    ->middleware('user');
    
    
});
Route::get('/profile', [ProfileController::class, 'index'])->name('profile');
Route::put('/profile/update-photo', [ProfileController::class, 'updatePhoto'])->name('profile.updatePhoto');
Route::put('/profile/change-password', [ProfileController::class, 'updatePassword'])->name('profile.updatePassword') ->middleware('auth');

Route::resource('kriteria', 'App\Http\Controllers\KriteriaController')->except(['create']);
Route::resource('alternatif', 'App\Http\Controllers\AlternatifController')->except(['create']);
Route::resource('crips', 'App\Http\Controllers\CripsController')->except(['index','create','show']);
// Route::get('/penilaian', [App\Http\Controllers\PenilaianController::class, 'index'])->name('penilaian.index');
Route::resource('/penilaian', 'App\Http\Controllers\PenilaianController');
Route::resource('user', 'App\Http\Controllers\UserController')->except(['create']);
Route::get('/laporan', function () {
    return view('admin.report.index');
})->name('laporan');

//Route::get('/perhitungan', [PenilaianController::class, 'perhitungan'])->name('perhitungan.index');  ga kepake

Route::get('/perhitungan', [App\Http\Controllers\AlgoritmaController::class, 'index'])->name('perhitungan.index');
Route::get('download-perhitungan-pdf', [App\Http\Controllers\AlgoritmaController::class, 'downloadPDF']);
Route::get('download-alternatif-pdf', [App\Http\Controllers\AlternatifController::class, 'downloadPDF']);
Route::get('download-user-pdf', [App\Http\Controllers\UserController::class, 'downloadPDF']);
Route::get('download-kriteria-pdf', [App\Http\Controllers\KriteriaController::class, 'downloadPDF']);
Route::get('/download-crips-pdf/{id}', [App\Http\Controllers\KriteriaController::class, 'downloadCripsPDF']);
Route::get('download-penilaian-pdf', [App\Http\Controllers\PenilaianController::class, 'downloadPDF']);