<?php

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\Auth\GoogleController;
use App\Http\Controllers\Backend\ProfileController;
use App\Http\Controllers\Backend\MateriController;
use App\Http\Controllers\AdminBackend\AdminMateriController;
use App\Http\Controllers\Backend\ResumeController;
use App\Http\Controllers\Backend\KuesionerLSController;
use App\Http\Controllers\Backend\KuesionerMetaController;
use App\Http\Controllers\Backend\InstruksiController;
use App\Http\Controllers\Auth\RegisterController;



/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

// ------------------------
// 🌐 Frontend (Landing)
// ------------------------
Route::get('register', [RegisterController::class, 'showRegistrationForm'])->name('register');
Route::post('register', [RegisterController::class, 'register']);
Route::group(['namespace' => 'Frontend'], function () {
    Route::resource('/', 'HomeController');
});

// ------------------------
// 🔐 Auth Google
// ------------------------
Route::get('auth/google', [GoogleController::class, 'redirectToGoogle'])->name('google.login');
Route::get('auth/google/callback', [GoogleController::class, 'handleGoogleCallback']);

// ------------------------
// 👩 Mahasiswa Routes
// ------------------------
Route::middleware(['class:3'])->group(function () {
    Route::group(['namespace' => 'Backend'], function () {
        Route::resource('dashboard', 'DashboardController');
        Route::resource('profile', 'ProfileController');
        Route::resource('questionnaire', 'QuestionnaireController')->names('userQuestionnaire');
        Route::resource('user-result', 'DashboardController')->names('userResult');
        Route::resource('history_quis', 'HistoryController')->names('history_quis');

        Route::get('/materi', 'MateriController@index')->name('materi.index');

        // Route::get('/materi/{style}', [MateriController::class, 'showByStyle'])->name('materi.learningStyle');
         Route::middleware(['check.questionnaire'])->group(function () {
            Route::get('/materi/{style}', [MateriController::class, 'showByStyle'])->name('materi.learningStyle');
        });
        Route::get('/materi/visual/{id_materi}', [MateriController::class, 'visual'])->name('materi.visual');
        Route::get('/materi/auditory/{id_materi}', [MateriController::class, 'auditory'])->name('materi.auditory');
        Route::get('/materi/readwrite/{id_materi}', [MateriController::class, 'readwrite'])->name('materi.readwrite');
        Route::post('/materi/{id_style}/{id_materi}/rangkuman', [MateriController::class, 'submitRangkuman'])->name('materi.rangkuman.submit');
        Route::post('/materi/readwrite/rangkuman', [MateriController::class, 'submitRangkuman'])->name('materi.rangkuman.submit');
        // Tampilkan halaman materi kinesthetic per id_materi
        Route::get('/materi/kinesthetic/{id_materi}', [MateriController::class, 'kinesthetic'])->name('materi.kinesthetic');
        Route::post('/materi/kinesthetic/{id_materi}/submit', [MateriController::class, 'submitKinesthetic'])->name('materi.kinesthetic.submit');



        

        Route::get('/kuisioner', 'KuisionerController@form')->name('kuisioner.form');

        Route::get('/user-hasil/cetak-pdf', 'DashboardController@cetak_pdf')->name('userQuestionnaire.cetak');
        Route::get('instruction', 'UiController@instruction')->name('user.questionnaire.instruction');
        Route::get('check-questionnaire', 'UiController@checkQuestionnaire')->name('user.questionnaire.check');
        Route::get('closed-questionnaire', 'UiController@closedQuestionnaire')->name('user.questionnaire.closed');

        Route::post('/profil/update', 'ProfileController@update')->name('profil.update');
        Route::post('/profil/reset-foto', 'ProfileController@resetFoto')->name('profil.resetFoto');
        Route::post('/profile/update', 'ProfileController@update'); 
        Route::get('/profile/change-password', 'ProfileController@changePasswordForm')->name('profile.changePasswordForm');
        Route::post('/profile/change-password', 'ProfileController@changePassword')->name('profile.changePassword');
        Route::get('/resume-pembelajaran', [ResumeController::class, 'index'])
            ->middleware('auth')
            ->name('resume.pembelajaran');

        Route::get('/kuesioner-panduan', function () {
            return view('backend.main.kuesioner.kuesioner_panduan');
        })->middleware('auth')->name('kuesioner.show');

        // Route::get('/kuesioner-ls', function () {
        //     return view('backend.main.kuesioner.kuesioner_learning_style');
        // })->middleware('auth')->name('kuesioner.show');

        Route::get('/kuesioner-mai', [KuesionerMetaController::class, 'index'])
        ->middleware('auth')
        ->name('kuesioner-mai');

        Route::post('/send-kuesioner-learning-style', [KuesionerLSController::class, 'store'])->name('send-kuesioner-learning-style');
        Route::post('/send-kuesioner-metakognitif', [KuesionerMetaController::class, 'store'])->name('send-kuesioner-metacognitive');
        Route::get('/kuesioner-ls', fn() => view('backend.main.kuesioner.kuesioner_learning_style'))->name('kuesioner-ls');
        Route::get('/kuesioner-mai', [KuesionerMetaController::class, 'showquestion'])->name('kuesioner-mai'); 
        Route::get('/kuesioner-hasil', fn() => view('backend.main.kuesioner.kuesioner_hasil'))->name('kuesioner-hasil');
        // Route::get('/instruksi/visual', [InstruksiController::class, 'instruksiVisual']);
        // Route::get('/instruksi/auditory', [InstruksiController::class, 'instruksiAuditory']);
        // Route::get('/instruksi/readwrite', [InstruksiController::class, 'instruksiReadWrite']);
        // Route::get('/instruksi/kinesthetic', [InstruksiController::class, 'instruksiKinesthetic']); 



    });
});

// ------------------------
// 👨‍🏫 Admin Routes
// ------------------------
Route::middleware(['class:1,2'])->group(function () {
    Route::group(['namespace' => 'AdminBackend'], function () {
        Route::resource('admin', 'AdminDashboardController')->names('adminDashboard');
        Route::resource('listuser', 'ListUserController')->names('adminListUser');
        Route::resource('listadmin', 'ListAdminController')->names('adminListAdmin');
        Route::resource('admin-questionnaire', 'AdminQuestionnaireController')->names('adminQuestionnaire');
        Route::resource('admin-period', 'AdminPeriodController')->names('adminPeriod');
        Route::resource('admin-result', 'AdminResultController')->names('adminResult');
        Route::resource('admin-profile', 'AdminProfileController')->names('adminProfile');

       // Custom route untuk Materi (karena pakai composite key)
        Route::get('admin-materi', [AdminMateriController::class, 'index'])->name('adminmateri.index');
        Route::post('admin-materi', [AdminMateriController::class, 'store'])->name('adminmateri.store');
        Route::get('admin-materi/{id_style}/{id_materi}/edit', [AdminMateriController::class, 'edit'])->name('adminmateri.edit');
        Route::put('admin-materi/{id_style}/{id_materi}', [AdminMateriController::class, 'update'])->name('adminmateri.update');
        // Route::delete('admin-materi/{id_style}/{id_materi}', [AdminMateriController::class, 'destroy'])->name('adminmateri.destroy');
        Route::delete('/admin-materi/{id_style}/{id_materi}', [AdminMateriController::class, 'destroy'])->name('adminmateri.destroy');



        Route::get('/hasil/cetak-pdf', 'AdminResultController@cetak_pdf')->name('userQuestionnaire.cetak');
        Route::post('/select-period', 'SelectPeriodController@update')->name('adminSelectPeriod');
        Route::post('/select-period/active', 'SelectPeriodController@active')->name('adminSelectPeriod.active');
        Route::post('/admin-profile/update', 'AdminProfileController@update'); 
        Route::get('/admin-profile/change-password', 'AdminProfileController@changePasswordForm')->name('admin-profile.changePasswordForm');
        Route::post('/admin-profile/change-password', 'AdminProfileController@changePassword')->name('admin-profile.changePassword');
        Route::post('/listadmin/add', 'ListAdminController@create'); 
    });
});

Auth::routes();
