<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ProductoController;
use App\Http\Controllers\CategoriaController;
use App\Http\Controllers\BackendController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\AdminRoleController;

/*
|--------------------------------------------------------------------------
| 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 () {
    return view('frontend/index');
});

Auth::routes();

// Route::get('/', [HomeController::class, 'index']);

// Rutas para usuarios autenticados
Route::middleware(['auth'])->group(function () {
    Route::get('/home', [HomeController::class, 'index'])->name('home.index');

    Route::middleware(['role:admin'])->group(function () {
        Route::get('/admin/index', [AdminController::class, 'index'])->name('admin.index');
        Route::get('/admin/roles', [AdminRoleController::class, 'index'])->name('admin.roles.index');
        Route::post('/admin/roles/{user}', [AdminRoleController::class, 'assignRole'])->name('admin.roles.assign');
    });
    Route::middleware(['role:usuario'])->group(function () {
        Route::get('backend/index', [BackendController::class, 'index'])->name('backend.index');
        Route::get('/frontend/index', [AdminRoleController::class, 'index'])->name('frontend.index');

    });
});

// // Ruta pública que no requiere autenticación
// Route::get('/about', function () {
//     return view('about');
// });

// // Ruta de redireccionamiento
// Route::redirect('/old-link', '/new-link');

// // Ruta con parámetros opcionales
// Route::get('/user/{name?}', function ($name = null) {
//     return 'Hola, ' . ($name ?: 'invitado');
// });

// // Ruta de vista básica
// Route::view('/contact', 'contact');

// // Ruta de fallback para manejo de rutas no encontradas
// Route::fallback(function () {
//     return view('404');
// });
