<?php

use App\Http\Controllers\AuthController;
use App\Http\Controllers\CatalogoController;
use App\Http\Controllers\SaleController;
use App\Http\Controllers\ClientController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\LoginController;
use App\Http\Controllers\ProductosController;
use App\Http\Controllers\RegisterController;
use App\Models\Product;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

Route::get('/',HomeController::class);

Route::get('login', function(){
    return view('login');
})->name('login');

Route::post('login', LoginController::class)
->middleware('throttle:5,1')
->name('login.attempt');

Route::view('dashboard', 'dashboard')
->middleware('auth')
->name('dashboard');

Route::post('logout', function(){
    Auth::guard('web')->logout();

    Session::invalidate();
    Session::regenerateToken();

    return redirect('/');
})->name('logout');

Route::view('register', 'register')->name('register');
Route::post('register', RegisterController::class)->name('register.store');

Route::middleware(['auth'])->group(function () {
    Route::resource('productos', ProductosController::class)->parameters([
        'productos' => 'producto' 
    ]);
    Route::get('/productos/{id}', [ProductosController::class,'show'])->name('productos.show');
    Route::get('/productos/{id}/edit', [ProductosController::class,'edit'])->name('productos.edit');
    Route::get('/checker', [ProductosController::class, 'checker'])->name('productos.checker');
    //Route::get('/sales', [SaleController::class, 'index'])->name('sales.index');
    Route::get('/sales/create', [SaleController::class, 'create'])->name('sales.create');
    Route::resource('clients', ClientController::class);
});


Route::get('/catalogo', [CatalogoController::class,'catalogo'])->name('catalogo');
Route::get('/productos/{id}/vistaUsuario', [ProductosController::class,'vistaUsuario'])->name('productos.vistaUsuario');