<?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('reportes/pdf', [ReportesController::class, 'exportPdf'])->name('reportes.pdf');
    Route::get('cierres_turno/resumen-ventas', [\App\Http\Controllers\CierresTurnoController::class, 'resumenVentas'])->name('cierres_turno.resumen_ventas');
    Route::get('cuadre-caja/obtener-precio', [\App\Http\Controllers\CierresTurnoController::class, 'obtenerPrecio'])->name('cierres_turno.obtener_precio');
    Route::get('cuadre-caja', [\App\Http\Controllers\CierresTurnoController::class, 'cuadreCaja'])->name('cierres_turno.cuadre_caja');
    Route::get('cuadre-caja/lista', [\App\Http\Controllers\CierresTurnoController::class, 'listaCuadres'])->name('cierres_turno.cuadre_caja.lista');
    Route::get('cuadre-caja/{fecha}/{idTurno}/{idUsuario}', [\App\Http\Controllers\CierresTurnoController::class, 'verCuadre'])->name('cierres_turno.cuadre_caja.ver');
    Route::post('cuadre-caja', [\App\Http\Controllers\CierresTurnoController::class, 'storeCuadreCaja'])->name('cierres_turno.cuadre_caja.store');
    // Otras rutas de recursos o CRUD pueden ir aquí o en web_crud.php
});
