<?php include_once "encabezado1.php" ?>

<?php
include 'conexion1.php';
$conexion = new mysqli($servidor, $nombre, $clave, $base);

$result = $conexion->query("SELECT * FROM productos");
?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>📦 Lista de Productos</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f3f5f9;
            font-family: Arial, sans-serif;
            color: #333;
        }
        .container {
            margin-top: 50px;
            background-color: rgba(255, 255, 255, 0.95);
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
            animation: fadeIn 0.8s ease;
        }
        h2 {
            font-weight: bold;
            color: #007bff;
            text-align: center;
            margin-bottom: 20px;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
        }
        h2 i {
            margin-right: 8px;
        }
        .btn-custom {
            background-color: #007bff;
            color: #fff;
            border: none;
            transition: all 0.3s ease;
            font-weight: 600;
            padding: 8px 15px;
            border-radius: 5px;
        }
        .btn-custom:hover {
            background-color: #0056b3;
            transform: translateY(-3px);
        }
        .table-hover tbody tr:hover {
            background-color: rgba(0, 123, 255, 0.1);
            transition: background-color 0.3s ease;
        }
        .btn-warning, .btn-danger {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-radius: 5px;
        }
        .btn-warning:hover {
            transform: scale(1.05);
            box-shadow: 0 6px 8px rgba(255, 193, 7, 0.3);
        }
        .btn-danger:hover {
            transform: scale(1.05);
            box-shadow: 0 6px 8px rgba(220, 53, 69, 0.3);
        }
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h2><i class="fas fa-boxes"></i> Lista de Productos 📦</h2>
        <div class="mb-3 text-right">
            <a href="agregar_producto.php" class="btn btn-custom"><i class="fas fa-plus"></i> Agregar Producto</a>
        </div>
        
        <table class="table table-hover table-bordered">
            <thead class="thead-light">
                <tr>
                    <th>ID</th>
                    <th>Nombre</th>
                    <th>Descripción</th>
                    <th>Precio Unitario 💵</th>
                    <th>Cantidad 🔢</th>
                    <th>Acciones 🛠️</th>
                </tr>
            </thead>
            <tbody>
                <?php while ($producto = $result->fetch_assoc()) { ?>
                    <tr>
                        <td><?php echo $producto['id']; ?></td>
                        <td><?php echo $producto['nombre']; ?></td>
                        <td><?php echo $producto['descripcion']; ?></td>
                        <td><?php echo '$' . number_format($producto['precio_unitario'], 2); ?></td>
                        <td><?php echo $producto['cantidad']; ?></td>
                        <td>
                            <a href="editar_producto.php?id=<?php echo $producto['id']; ?>" class="btn btn-sm btn-warning">
                                <i class="fas fa-edit"></i> Editar
                            </a>
                            <a href="eliminar_producto.php?id=<?php echo $producto['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('¿Estás seguro de eliminar este producto?');">
                                <i class="fas fa-trash"></i> Eliminar
                            </a>
                        </td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
</body>
</html>