<?php

use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\PasswordController;
use App\Http\Controllers\ReportesController;
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::get('/', function () {
    return view('welcome');
});

Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('login', [LoginController::class, 'login']);
Route::post('logout', [LoginController::class, 'logout'])->name('logout');

// Rutas que requieren estar autenticado pero permiten cambiar la clave
Route::middleware('auth')->group(function () {
    Route::get('change-password', [PasswordController::class, 'showChangeForm'])->name('password.change');
    Route::post('change-password', [PasswordController::class, 'update'])->name('password.update');
});

// Rutas protegidas que requieren cambio de clave obligatorio
Route::middleware(['auth', 'force.pwd'])->group(function () {
    Route::get('dashboard', function () {
        return view('dashboard');
    })->name('dashboard');

    require __DIR__.'/web_crud.php';
    Route::get('reportes', [ReportesController::class, 'index'])->name('reportes.index');
    Route::get('reportes/export', [ReportesController::class, 'export'])->name('reportes.export');
    Route::get('cierres_turno/resumen-ventas', [\App\Http\Controllers\CierresTurnoController::class, 'resumenVentas'])->name('cierres_turno.resumen_ventas');
    // Otras rutas de recursos o CRUD pueden ir aquí o en web_crud.php
});
