<?php include_once "encabezado1.php"; ?>

<?php include 'conexion1.php'; ?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Gestión de Clientes y Proveedores</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">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        /* Estilos generales */
        body {
            font-family: 'Roboto', sans-serif;
            background-color: #f4f6f9;
        }
        .container {
            margin-top: 40px;
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            animation: fadeIn 1s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        h2 {
            color: #004085;
            font-size: 24px;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        h2 i {
            color: #004085;
        }
        
        /* Botón personalizado */
        .btn-custom {
            background-color: #004085;
            color: #fff;
            border-radius: 5px;
            transition: background-color 0.3s, transform 0.3s;
            position: relative;
            overflow: hidden;
        }
        .btn-custom:hover {
            background-color: #002752;
            transform: scale(1.05);
        }

        /* Efecto de onda al hacer clic en los botones */
        .btn-custom:active::after {
            content: "";
            position: absolute;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.3);
            top: 0;
            left: 0;
            animation: clickWave 0.4s ease;
        }
        @keyframes clickWave {
            0% { transform: scale(0); opacity: 1; }
            100% { transform: scale(2); opacity: 0; }
        }

        /* Estilos de tabla con animación */
        .table th, .table td {
            text-align: center;
            opacity: 0;
            transform: translateY(20px);
            animation: tableFadeIn 0.6s forwards;
        }
        .table thead {
            background-color: #007bff;
            color: #fff;
        }
        .table tbody tr:hover {
            background-color: #f1f3f5;
            transition: background-color 0.3s;
        }

        /* Animación en cascada para las filas de la tabla */
        .table-striped tbody tr:nth-child(odd) { animation-delay: 0.1s; }
        .table-striped tbody tr:nth-child(even) { animation-delay: 0.2s; }

        @keyframes tableFadeIn {
            0% { opacity: 0; transform: translateY(20px); }
            100% { opacity: 1; transform: translateY(0); }
        }

        /* Botones de acción */
        .btn-warning, .btn-danger {
            font-size: 14px;
            font-weight: 500;
            transition: transform 0.3s, box-shadow 0.3s;
        }
        .btn-warning:hover, .btn-danger:hover {
            transform: scale(1.1);
            box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
        }
        .btn-warning i, .btn-danger i {
            color: #fff;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2><i class="fas fa-users"></i> Gestión de Clientes</h2>
        <div class="text-right mb-3">
            <a href="crear_cliente.php" class="btn btn-custom"><i class="fas fa-plus"></i> Agregar Cliente</a>
        </div>
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Nombre</th>
                    <th>Email</th>
                    <th>Teléfono</th>
                    <th>Empresa</th>
                    <th>Acciones</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $conexion = new mysqli($servidor, $nombre, $clave, $base);
                $result = $conexion->query("SELECT * FROM clientes");
                while ($cliente = $result->fetch_assoc()) {
                    echo "<tr>
                        <td>{$cliente['id']}</td>
                        <td>{$cliente['nombre']}</td>
                        <td>{$cliente['email']}</td>
                        <td>{$cliente['telefono']}</td>
                        <td>{$cliente['empresa']}</td>
                        <td>
                            <a href='editar_cliente.php?id={$cliente['id']}' class='btn btn-sm btn-warning'><i class='fas fa-edit'></i></a>
                            <a href='eliminar_cliente.php?id={$cliente['id']}' class='btn btn-sm btn-danger'><i class='fas fa-trash'></i></a>
                        </td>
                    </tr>";
                }
                ?>
            </tbody>
        </table>
        
        <h2><i class="fas fa-truck"></i> Gestión de Proveedores</h2>
        <div class="text-right mb-3">
            <a href="crear_proveedor.php" class="btn btn-custom"><i class="fas fa-plus"></i> Agregar Proveedor</a>
        </div>
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Nombre</th>
                    <th>Email</th>
                    <th>Teléfono</th>
                    <th>Empresa</th>
                    <th>Acciones</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $result = $conexion->query("SELECT * FROM proveedores");
                while ($proveedor = $result->fetch_assoc()) {
                    echo "<tr>
                        <td>{$proveedor['id']}</td>
                        <td>{$proveedor['nombre']}</td>
                        <td>{$proveedor['email']}</td>
                        <td>{$proveedor['telefono']}</td>
                        <td>{$proveedor['empresa']}</td>
                        <td>
                            <a href='editar_proveedor.php?id={$proveedor['id']}' class='btn btn-sm btn-warning'><i class='fas fa-edit'></i></a>
                            <a href='eliminar_proveedor.php?id={$proveedor['id']}' class='btn btn-sm btn-danger'><i class='fas fa-trash'></i></a>
                        </td>
                    </tr>";
                }
                ?>
            </tbody>
        </table>
    </div>
    
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</body>
</html>