<?php

use App\Http\Controllers\AlternatifSolusiController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\ChoiceController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\HasilController;
use App\Http\Controllers\MateriController;
use App\Http\Controllers\NodeController;
use App\Http\Controllers\PuzleController;
use App\Http\Controllers\QuizController;
use App\Http\Controllers\ResultController;
use App\Http\Controllers\StudyKasusController;
use App\Http\Controllers\UserKasus;
use App\Models\CaseStudy;
use App\Models\FinalAkhir;
use App\Models\Materi;
use App\Models\User;
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!
|
*/



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

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

// Route::get('/quiz/result', function () {
//     return view('user.quiz.result');
// });






Route::middleware(['auth', 'role:admin'])->group(function () {
    // Route::get('/admin', function () {
    //     return view('index');
    // });

    Route::get('/dashboard', [DashboardController::class, 'index']);
    Route::post('/dashboard/image', [DashboardController::class,'storeHero']);

    //kategori
    Route::get('/kategori', [CategoryController::class, 'index']);
    Route::post('/kategori/store', [CategoryController::class, 'store']);
    Route::get('/kategori/delete/{id}', [CategoryController::class, 'delete']);

    //study kasus
    Route::get('/study-kasus', [StudyKasusController::class, 'adminIndex']);
    Route::get('/study-kasus/create', [StudyKasusController::class, 'create']);
    Route::post('/study-kasus/store', [StudyKasusController::class, 'createStore']);
    Route::post('/study-kasus/update-gambar', [StudyKasusController::class, 'updateGambar']);
    Route::get('/study-kasus/{id}', [StudyKasusController::class, 'detail']);
    Route::get('/study-kasus/delete/{id}', [StudyKasusController::class, 'delete']);
    Route::get('/study-kasus/update/{id}', [StudyKasusController::class, 'update']);


    //node
    Route::get('/study-kasus/skenario/{id}', [NodeController::class, 'index']);
    Route::get('/node/update/{id}', [NodeController::class, 'update']);
    Route::post('/node/new', [NodeController::class, 'new']);
    Route::post('/node/update-gambar', [NodeController::class, 'updateGambar']);
    Route::get('/node/delete/{id}', [NodeController::class, 'delete']);

    //choices
    Route::post('/choices/new', [ChoiceController::class, 'new']);
    Route::get('/choices/update/{id}', [ChoiceController::class, 'update']);


    //alternatif solusi
    Route::get('/study-kasus/alternatif-solusi/{id}', [AlternatifSolusiController::class, 'index']);
    Route::post('/alternatif_solusi/new', [AlternatifSolusiController::class, 'new']);

    //puzzle
    Route::get('study-kasus/puzzle/update/{id}', [PuzleController::class, 'puzzleUpdate']);

    //materi
    Route::get('/materi-admin', [MateriController::class, 'index']);
    Route::get('/materi/create', [MateriController::class, 'create']);
    Route::post('/materi/store', [MateriController::class, 'createStore']);
    Route::post('/materi/update', [MateriController::class, 'update']);
    Route::get('/materi/{id}', [MateriController::class, 'detail']);
    Route::get('/materi/delete/{id}', [MateriController::class, 'destroy']);
    Route::get('/materi/delete-video/{id}', [MateriController::class, 'deleteVideo']);
    Route::get('/materi/delete-pdf/{id}', [MateriController::class, 'deletePdf']);

    //hasil
    Route::get('/admin-hasil', [HasilController::class,'index']);
    Route::get('/admin-hasil/{id}', [HasilController::class,'detail']);
    Route::get('/admin-hasil/jawaban/detail/{id}', [HasilController::class,'detailJawaban']);
    Route::get('/admin-hasil/jawaban/{id}/{userId}', [HasilController::class,'detailKategori']);
});
//users
// Route::middleware('auth')->group(function () {
Route::middleware(['auth', 'role:user'])->group(function () {
    Route::get('/kasus', [UserKasus::class, 'index']);
    Route::get('/quiz/{id}', [QuizController::class, 'show']);
    Route::get('/quiz/alternatif-solusi/{id}', [QuizController::class, 'alternatifSolusi']);
    Route::post('/quiz/answer', [QuizController::class, 'answer']);
    Route::post('/quiz/final-evaluation', [QuizController::class, 'finalEvaluation']);
    Route::post('/quiz/alternatif-submit', [QuizController::class, 'alternatifSubmit']);
    Route::get('/quiz/puzzle/{id}', [PuzleController::class, 'index']);
    Route::get('/quiz/result/{id}', [ResultController::class, 'detail']);
    Route::post('/submit-puzzle', [PuzleController::class, 'submitPuzzle']);

    //hasil
    Route::get('/hasil', [ResultController::class, 'all']);
    Route::get('/hasil/{id}', [ResultController::class, 'index']);

    Route::get('/materi', [MateriController::class, 'userIndex']);
    Route::get('/materi/view/{id}', [MateriController::class, 'view']);
});

Route::get('/', function () {
    $user = User::all()->count();
    $case = CaseStudy::all()->count();
    $final = FinalAkhir::all()->count();
    $materi = Materi::all()->count();
    return view('user.index', compact('user', 'case', 'final', 'materi'));

});

Route::get('/login', function () {
    return view('user.login');
})->name('login');
Route::get('/register-page', function () {
    return view('user.register-page');
});

Route::get('/logout', [AuthController::class, 'logout']);

Route::post('/login-process', [AuthController::class, 'loginProcess']);

Route::get('/register', [AuthController::class, 'register']);

Route::post('/register-process', [AuthController::class, 'registerProcess']);
