<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\MakananController;
use App\Http\Controllers\PerbandinganKriteriaController;
use App\Http\Controllers\ProsesController;
use App\Http\Controllers\AlternatifController;
use App\Http\Controllers\LandingPageController;
use App\Http\Controllers\RegisterController;
use App\Http\Controllers\RekomendasiController;

/*
|--------------------------------------------------------------------------
| 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('welcome');
// });



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

    Route::get('/admindash', [AdminController::class, 'admindash'])->name('admindash');
    
    Route::get('/datauser', [AdminController::class, 'datauser'])->name('datauser');
    Route::get('/edituser/{user}/edituser', [AdminController::class, 'edituser'])->name('edituser');
    Route::put('/datauser/{user}', [AdminController::class, 'updateuser'])->name('updateuser');
    Route::delete('/datauser/{user}', [AdminController::class, 'deleteuser'])->name('deleteuser');
    Route::get('/tambahuser', [AdminController::class, 'tambahuser'])->name('tambahuser');
    Route::post('/datauser/storeuser', [AdminController::class, 'storeuser'])->name('storeuser');
    
    Route::get('/role', [AdminController::class, 'role'])->name('role');
    Route::get('/editrole/{role}/editrole', [AdminController::class, 'editrole'])->name('editrole');
    Route::put('/role/{role}', [AdminController::class, 'updaterole'])->name('updaterole');
    Route::delete('/role/{role}', [AdminController::class, 'deleterole'])->name('deleterole');
    Route::get('/tambahrole', [AdminController::class, 'tambahrole'])->name('tambahrole');
    Route::post('/role/storerole', [AdminController::class, 'storerole'])->name('storerole');
});

// Routes untuk kategori, jenis makanan, dan makanan
Route::middleware(['cekrole:admin'])->group(function () {
    Route::get('/kategori', [MakananController::class, 'kategori'])->name('kategori');
    Route::get('/editkategori/{kategori}/editkategori', [MakananController::class, 'editkategori'])->name('editkategori');
    Route::put('/kategori/{kategori}', [MakananController::class, 'updatekategori'])->name('updatekategori');
    Route::delete('/kategori/{kategori}', [MakananController::class, 'deletekategori'])->name('deletekategori');
    Route::get('/tambahkategori', [MakananController::class, 'tambahkategori'])->name('tambahkategori');
    Route::post('/kategori/storekategori', [MakananController::class, 'storekategori'])->name('storekategori');
    
    Route::get('/jenismakanan', [MakananController::class, 'jenismakanan'])->name('jenismakanan');
    Route::get('/editjenismakanan/{jenis}/editjenismakanan', [MakananController::class, 'editjenismakanan'])->name('editjenismakanan');
    Route::put('/jenismakanan/{jenis}', [MakananController::class, 'updatejenismakanan'])->name('updatejenismakanan');
    Route::delete('/jenismakanan/{jenis}', [MakananController::class, 'deletejenismakanan'])->name('deletejenismakanan');
    Route::get('/tambahjenismakanan', [MakananController::class, 'tambahjenismakanan'])->name('tambahjenismakanan');
    Route::post('/jenismakanan/storejenismakanan', [MakananController::class, 'storejenismakanan'])->name('storejenismakanan');
    
    Route::get('/makanan', [MakananController::class, 'makanan'])->name('makanan');
    Route::get('/editmakanan/{makanan}/editmakanan', [MakananController::class, 'editmakanan'])->name('editmakanan');
    Route::put('/makanan/{makanan}', [MakananController::class, 'updatemakanan'])->name('updatemakanan');
    Route::delete('/makanan/{makanan}', [MakananController::class, 'deletemakanan'])->name('deletemakanan');
    Route::get('/tambahmakanan', [MakananController::class, 'tambahmakanan'])->name('tambahmakanan');
    Route::post('/makanan/storemakanan', [MakananController::class, 'storemakanan'])->name('makanan.storemakanan');
});

Route::middleware(['cekrole:admin'])->group(function () {
    Route::get('/kriteria', [PerbandinganKriteriaController::class, 'kriteria'])->name('kriteria');
    Route::get('/editkriteria/{kriteria}/editkriteria', [PerbandinganKriteriaController::class, 'editkriteria'])->name('editkriteria');
    Route::put('/kriteria/{kriteria}', [PerbandinganKriteriaController::class, 'updatekriteria'])->name('updatekriteria');
    Route::delete('/kriteria/{kriteria}', [PerbandinganKriteriaController::class, 'deletekriteria'])->name('deletekriteria');
    Route::get('/tambahkriteria', [PerbandinganKriteriaController::class, 'tambahkriteria'])->name('tambahkriteria');
    Route::post('/kriteria/storekriteria', [PerbandinganKriteriaController::class, 'storekriteria'])->name('storekriteria');
});

// Routes untuk proses
Route::middleware(['cekrole:admin'])->group(function () {
    Route::get('/perbandingan', [ProsesController::class, 'showPerbandingan'])->name('perbandingan');
    Route::post('/perbandingan/proses', [ProsesController::class, 'prosesSementara'])->name('sementara');
    Route::post('/simpan-perbandingan', [ProsesController::class, 'simpanPerbandingan'])->name('simpan.perbandingan');
    Route::get('/perbandingan/normalisasi', [ProsesController::class, 'hasilNormalisasi'])->name('hasil.normalisasi');
    Route::get('perbandingan-alternatif', [ProsesController::class, 'perbandinganAlternatif'])->name('perbandingan.alternatif');


    // Alternatif
    Route::get('/alternatif/pilih', [AlternatifController::class, 'formPilihAlternatif'])->name('alternatif.pilih');
    Route::post('/alternatif/pilih', [AlternatifController::class, 'pilihAlternatif'])->name('alternatif.pilih.simpan');
    Route::get('/alternatif/perbandingan', [AlternatifController::class, 'tampilPerbandingan'])->name('alternatif.perbandingan');
    Route::post('/alternatif/perbandingan', [AlternatifController::class, 'simpanPerbandingan'])->name('alternatif.simpan');
    Route::get('/alternatif/normalisasi', [AlternatifController::class, 'tampilNormalisasi'])->name('alternatif.normalisasi');
    Route::post('/alternatif/simpan-normalisasi', [AlternatifController::class, 'simpanNormalisasi'])->name('alternatif.simpanNormalisasi');



    Route::get('/rekomendasi/proses', [RekomendasiController::class, 'hitungDanSimpan'])->name('rekomendasi.proses');
    Route::get('/rekomendasi/hasil', [RekomendasiController::class, 'tampil'])->name('rekomendasi.hasil');
    Route::post('/rekomendasi/kirim/{user}', [RekomendasiController::class, 'kirimKeUser'])->name('rekomendasi.kirim');
    Route::delete('/rekomendasi/hapus', [RekomendasiController::class, 'hapusSemua'])->name('rekomendasi.hapusSemua');


});

// User Routes (Hanya bisa diakses oleh User)
Route::middleware(['cekrole:user'])->group(function () {
    Route::get('/userdash', [UserController::class, 'userdash'])->name('userdash');
    Route::get('/userabout', [UserController::class, 'userabout'])->name('userabout');
    Route::get('/userresult', [UserController::class, 'userresult'])->name('userresult');
    Route::get('/userfeature', [UserController::class, 'userfeature'])->name('userfeature');
    Route::get('/userdata', [UserController::class, 'userdata'])->name('userdata');
    Route::get('/userfeatures/{id}', [UserController::class, 'show'])->name('userfeatures.show');
    Route::get('/user/makanan', [UserController::class, 'userdata'])->name('user.makanan');


});

// Landing Page Routes
Route::get('/', [LandingPageController::class, 'lp'])->name('lp');

// Auth Routes
Route::get('/login', [LoginController::class, 'login'])->name('login');
Route::post('/login', [LoginController::class, 'loginPost'])->name('login.post');
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');

// Register Routes
Route::get('/register', [ RegisterController::class, 'register'])->name('register');
Route::post('/register', [RegisterController::class, 'registerPost'])->name('register.post');

