<?php

use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\TwoStepVerifyController;
use App\Http\Controllers\DashboardController;
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::middleware('guest')->group(function () {

    Route::name('auth.')->group(function () {

        Route::controller(AuthenticatedSessionController::class)->group(function () {
            Route::get('/', 'create')->name('login');
            Route::post('/', 'store')->name('login_post');
        });

        Route::controller(RegisteredUserController::class)->group(function () {
            Route::get('/registrasi', 'create')->name('register');
            Route::post('/registrasi', 'store')->name('register_post');
        });

        Route::controller(TwoStepVerifyController::class)->group(function () {
            Route::get('/verifikasi-akun/{email}', 'create')->name('two_step_verify');
            Route::post('/verifikasi-akun', 'store')->name('two_step_verify_post');
            Route::post('/verifikasi-akun/resend', 'resendEmail')->name('two_step_verify_resend');
        });

        Route::controller(PasswordResetLinkController::class)->group(function () {
            Route::get('/forgot-password', 'create')->name('forgot_password');
            Route::post('/reset-password', 'store')->name('reset_password');

            Route::get('/validasi-lupa-password/{token}', 'createNewPasswordForm')->name('create_new_password_form');
            Route::post('/validasi-lupa-password', 'storeNewPasswordForm')->name('store_new_password_form');
        });
    });
});

Route::middleware(['auth', 'verifiedAcount'])->group(function () {
    Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])->name('auth.logout');

    Route::controller(DashboardController::class)->name('dashboard.')->group(function () {
        Route::get('/dashboard-admin', 'admin')->name('admin');
        Route::get('/dashboard-petugas', 'petugas')->name('petugas');
    });
});
