<?php
    include_once 'conexion.php';

    $sql = "SELECT id_flor, nombre_flor, color, precio_unitario, stock FROM flor";
    $result = $conn->query($sql);
?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Florería - Inventario</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #fff9f0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        .card-custom {
            border-radius: 15px;
            box-shadow: 0 4px 15px rgba(244, 187, 210, 0.3);
            border: none;
            overflow: hidden;
        }
        .header-custom {
            background-color: #f7a8b8; /* Rosa Pastel */
            color: #ffffff;
            padding: 20px;
        }
        .btn-pastel-yellow {
            background-color: #fce38a; /* Amarillo Pastel */
            color: #5a4a1d;
            border: none;
            font-weight: 600;
        }
        .btn-pastel-yellow:hover {
            background-color: #f3d465;
            color: #3f3312;
        }
        .btn-pastel-pink {
            background-color: #f7a8b8; /* Rosa Pastel */
            color: #ffffff;
            border: none;
        }
        .btn-pastel-pink:hover {
            background-color: #e590a2;
            color: #ffffff;
        }
        .table-custom thead {
            background-color: #fff2b2; /* Amarillo Pastel Claro */
            color: #6b5828;
        }
        .badge-color {
            background-color: #ffd3e2;
            color: #8c3f58;
        }
        .badge-stock {
            background-color: #fce38a;
            color: #5a4a1d;
        }
    </style>
</head>
<body>

    <div class="container my-5">
        <div class="card card-custom">
            <div class="header-custom d-flex justify-content-between align-items-center">
                <h2 class="h3 mb-0 font-weight-bold">🌸 Inventario de Florería</h2>
                <a href="insertar.php" class="btn btn-pastel-yellow px-4 py-2 rounded-pill">+ Registrar Flor</a>
            </div>
            <div class="card-body p-4 bg-white">
                <?php if ($result && $result->num_rows > 0): ?>
                    <div class="table-responsive">
                        <table class="table table-hover align-middle table-custom">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Nombre</th>
                                    <th>Color</th>
                                    <th>Precio</th>
                                    <th>Stock</th>
                                    <th class="text-center">Acciones</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php while($row = $result->fetch_assoc()): ?>
                                    <tr>
                                        <td><strong>#<?php echo $row['id_flor']; ?></strong></td>
                                        <td><?php echo htmlspecialchars($row['nombre_flor']); ?></td>
                                        <td><span class="badge badge-color px-3 py-2 rounded-pill"><?php echo htmlspecialchars($row['color']); ?></span></td>
                                        <td><strong>$<?php echo number_format($row['precio_unitario'], 2); ?></strong></td>
                                        <td><span class="badge badge-stock px-3 py-2 rounded-pill"><?php echo $row['stock']; ?> unidades</span></td>
                                        <td class="text-center">
                                            <a href="editar.php?id=<?php echo $row['id_flor']; ?>" class="btn btn-sm btn-pastel-yellow me-1 rounded-pill px-3">Editar</a>
                                            <a href="eliminar.php?id=<?php echo $row['id_flor']; ?>" class="btn btn-sm btn-pastel-pink rounded-pill px-3" onclick="return confirm('¿Deseas eliminar esta flor?');">Eliminar</a>
                                        </td>
                                    </tr>
                                <?php endwhile; ?>
                            </tbody>
                        </table>
                    </div>
                <?php else: ?>
                    <div class="alert text-center my-3" style="background-color: #fff2b2; color: #6b5828;">No hay productos registrados en el inventario.</div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <?php $conn->close(); ?>
</body>
</html>