<?php
session_start();
if (!isset($_SESSION['user_id'])) {
    header("Location: ../auth/login.php");
    exit();
}

require_once __DIR__ . '/../../controllers/CashClosureController.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $cashClosureController = new CashClosureController();
    if ($cashClosureController->createClosure($_SESSION['user_id'])) {
        $success = "Cierre de caja realizado con éxito.";
    } else {
        $error = "Error al realizar el cierre de caja.";
    }
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Cierre de Caja</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <h1 class="mt-3">Cierre de Caja</h1>
        <?php if (isset($success)): ?>
            <div class="alert alert-success"><?php echo $success; ?></div>
        <?php endif; ?>
        <?php if (isset($error)): ?>
            <div class="alert alert-danger"><?php echo $error; ?></div>
        <?php endif; ?>
        <form method="POST">
            <button type="submit" class="btn btn-primary">Realizar Cierre de Caja</button>
        </form>
        <a href="index.php" class="btn btn-secondary mt-2">Volver al POS</a>
    </div>
</body>
</html>