<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
	if (Auth::check()) {
		return redirect('panel');
	}
    return view('home');
})->name('login');

Route::view('/panel', 'panel')->middleware([ 'auth', 'verified' ])->name('panel');

Route::view('/verify-email',
	'verify-email')->middleware('auth')->name('verification.notice');

Route::get('/verify/{id}/{hash}', function (EmailVerificationRequest $request) {
	$request->fulfill();
	return redirect('/panel');
})->middleware(['auth', 'signed'])->name('verification.verify');

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

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

Route::post('/register', [UserController::class, 'create']);

Route::post('/forgot-password', [UserController::class,
	'forgotPassword'])->middleware('guest')->name('password.email');

Route::get('/reset-password/{token}', function ($token) {
	    return view('reset-password', ['token' => $token]);
})->middleware('guest')->name('password.reset');

Route::post('/reset-passowrd', [UserController::class,
	'resetPassword'])->middleware('guest');

Route::post('/login', [UserController::class,
	'login'])->middleware('guest');

Route::get('/panel/user', function (Request $request) {
	return $request->user();
})->middleware('auth');

Route::get('/panel/orders', [UserController::class,
	'getOrders'])->middleware('auth');

Route::get('/logout', [UserController::class,
	'logout'])->middleware('auth');
