
<?php include_once "encabezado1.php"; ?>
<?php include 'conexion1.php'; ?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Crear Presupuesto</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            background-color: #f7f8fa;
            font-family: 'Roboto', sans-serif;
            color: #333;
        }
        .container {
            max-width: 700px;
            margin-top: 50px;
            background-color: #fff;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
            animation: fadeIn 0.8s ease-in-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        h2 {
            color: #004085;
            font-weight: 700;
            font-size: 28px;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 15px;
        }
        h2 .fas {
            color: #004085;
        }
        .form-group label {
            font-weight: 500;
            color: #495057;
            font-size: 16px;
        }
        .form-control {
            border-radius: 8px;
            transition: border-color 0.3s, box-shadow 0.3s;
        }
        .form-control:focus {
            border-color: #004085;
            box-shadow: 0px 4px 10px rgba(0, 64, 133, 0.2);
        }
        .btn-custom {
            background-color: #004085;
            color: #fff;
            border: none;
            padding: 12px 25px;
            font-size: 16px;
            font-weight: 500;
            border-radius: 8px;
            transition: background-color 0.3s, transform 0.3s;
            box-shadow: 0px 4px 10px rgba(0, 64, 133, 0.2);
        }
        .btn-custom:hover {
            background-color: #002752;
            transform: translateY(-2px);
        }
        .btn-add, .btn-delete {
            background-color: #28a745;
            color: #fff;
            border: none;
            padding: 10px 15px;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s, transform 0.3s;
            box-shadow: 0px 4px 10px rgba(40, 167, 69, 0.2);
        }
        .btn-add:hover {
            background-color: #218838;
            transform: translateY(-2px);
        }
        .btn-delete {
            background-color: #dc3545;
            box-shadow: 0px 4px 10px rgba(220, 53, 69, 0.2);
        }
        .btn-delete:hover {
            background-color: #c82333;
            transform: translateY(-2px);
        }
        .producto-row {
            display: flex;
            gap: 10px;
            align-items: center;
            margin-top: 15px;
            padding: 10px 0;
            border-bottom: 1px solid #e9ecef;
        }
        .producto-row:last-child {
            border-bottom: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2><i class="fas fa-file-invoice"></i> Crear Presupuesto</h2>
        <form action="guardar_presupuesto.php" method="POST">
            <div class="form-group">
                <label><i class="fas fa-user"></i> Nombre del Cliente</label>
                <input type="text" name="cliente_nombre" class="form-control" required>
            </div>
            <div class="form-group">
                <label><i class="fas fa-envelope"></i> Email del Cliente</label>
                <input type="email" name="cliente_email" class="form-control">
            </div>
            <h4 class="mt-4"><i class="fas fa-box"></i> Productos</h4>
            <div id="productosContainer">
                <div class="producto-row">
                    <input type="text" name="producto_nombre[]" class="form-control" placeholder="Nombre del Producto" required>
                    <input type="number" name="cantidad[]" class="form-control" placeholder="Cantidad" required min="1">
                    <input type="number" name="precio_unitario[]" class="form-control" placeholder="Precio Unitario" required min="0" step="0.01">
                    <button type="button" class="btn btn-delete" onclick="eliminarProducto(this)"><i class="fas fa-trash"></i></button>
                </div>
            </div>
            <div class="form-group mt-4">
                <button type="button" class="btn btn-add" onclick="agregarProducto()"><i class="fas fa-plus-circle"></i> Agregar Producto</button>
            </div>
            <div class="form-group text-center mt-5">
                <button type="submit" class="btn-custom"><i class="fas fa-save"></i> Guardar Presupuesto</button>
            </div>
        </form>
    </div>

    <script>
        function agregarProducto() {
            const container = document.getElementById('productosContainer');
            const productoRow = document.createElement('div');
            productoRow.classList.add('producto-row');
            productoRow.innerHTML = `
                <input type="text" name="producto_nombre[]" class="form-control" placeholder="Nombre del Producto" required>
                <input type="number" name="cantidad[]" class="form-control" placeholder="Cantidad" required min="1">
                <input type="number" name="precio_unitario[]" class="form-control" placeholder="Precio Unitario" required min="0" step="0.01">
                <button type="button" class="btn btn-delete" onclick="eliminarProducto(this)"><i class="fas fa-trash"></i></button>
            `;
            container.appendChild(productoRow);
        }

        function eliminarProducto(button) {
            button.parentElement.remove();
        }
    </script>
</body>
</html>