<?php

use App\Livewire\Auth\Login as LoginComponent;
use App\Livewire\Auth\Logout as LogoutComponent;
use App\Livewire\Auth\Register as RegisterComponent;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::middleware('guest')
    ->prefix('auth')
    ->group(function () {
        Route::get('login', LoginComponent::class)->name('login');
        Route::get('register', RegisterComponent::class)->name('register');
    });

Route::post('logout', LogoutComponent::class)->name('logout')->middleware('auth');

Route::get('/email/verify', function () {
    return view('auth.verify-email');
})->middleware('auth')->name('verification.notice');

Route::get('/email/verify/{id}/{hash}', function (EmailVerificationRequest $request) {
    $request->fulfill();

    return redirect('/');
})->middleware(['auth', 'signed'])->name('verification.verify');

Route::post('/email/verification-notification', function (Request $request) {
    $request->user()->sendEmailVerificationNotification();

    return back()->with('message', 'Verification link sent!');
})->middleware(['auth', 'throttle:6,1'])->name('verification.send');
