<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Venta</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- SweetAlert2 CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
    <style>
        body {
            font-family: 'Raleway', sans-serif;
            padding: 20px;
        }
        .sticky-top-container {
            position: sticky;
            top: 0;
            background-color: white;
            z-index: 1000;
            padding: 10px 0;
            border-bottom: 1px solid #ddd;
        }
        .btn-categoria {
            margin-right: 8px;
            margin-bottom: 8px;
        }
    </style>
</head>
<body>
    <!-- Incluir el menú desde index.php -->
    <?php include('index.php'); ?>

    <div class="container">
        <h1 class="text-center">Venta</h1>

        <!-- Contenedor sticky para los elementos superiores -->
        <div class="sticky-top-container">
            <!-- Primer renglón: Total Cobrado, F de Pago, Comentario, Botón Guardar Venta, Total Real y Total Costo -->
            <div class="row mb-3">
                <div class="col">
                    <label for="total_cobrado" class="form-label">Total Cobrado:</label>
                    <input type="number" class="form-control" id="total_cobrado" name="total_cobrado" required>
                </div>
                <div class="col">
                    <label for="forma_pago" class="form-label">F de Pago:</label>
                    <select class="form-select" id="forma_pago" name="forma_pago" required>
                        <?php foreach ($formasPago as $formaPago): ?>
                            <option value="<?php echo $formaPago['IdPago']; ?>"><?php echo $formaPago['FormaPago']; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="col">
                    <label for="comentario" class="form-label">Comentario:</label>
                    <textarea class="form-control" id="comentario" name="comentario"></textarea>
                </div>
                <div class="col d-flex align-items-end">
                    <button type="submit" class="btn btn-primary" name="guardar_venta">Guardar Venta</button>
                </div>
                <div class="col">
                    <label class="form-label">Total Real:</label>
                    <span id="total_real_label" class="total-label">0.00</span>
                </div>
                <div class="col">
                    <label class="form-label">Total Costo:</label>
                    <span id="total_costo_label" class="total-label">0.00</span>
                </div>
            </div>

            <!-- Filtro por categoría (botones) -->
            <div class="filtro-categoria">
                <label for="categoria" class="form-label">Filtrar por Categoría:</label>
                <div class="btn-group" role="group">
                    <?php if (!empty($categorias)): ?>
                        <?php foreach ($categorias as $categoria): ?>
                            <a href="?categoria=<?php echo $categoria['Id']; ?>" class="btn btn-primary btn-categoria">
                                <?php echo $categoria['Nombre']; ?>
                            </a>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <p>No hay categorías disponibles.</p>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <!-- Resto del contenido -->
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <!-- SweetAlert2 JS -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</body>
</html>