<?php session_start(); ?>
<!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>TSGJ | Registro de Grifos</title>
    <link rel="icon" href="../../Modelo/Archivos_Media/Color_LogoTipo.png" type="image/png" />

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" />
</head>

<body>

<div class="container my-5">
    <a href="Adm_Gestion_Grifos.php" class="btn btn-outline-primary mb-3">
        <i class="bi bi-arrow-left"></i> Volver a gestión de grifos
    </a>

    <div class="card shadow">
        <div class="card-header bg-primary text-white text-center">
            <h4>Registrar Nuevo Grifo</h4>
        </div>

        <div class="card-body">
            <form action="../../Controlador/Ctrl_Administrador/MySQL_Agregar_Grifo.php" method="post" id="Registrar_Grifo" novalidate>
                <div class="row g-3">

                    <div class="col-md-6">
                        <label for="nombre" class="form-label">Nombre del Grifo</label>
                        <input type="text" class="form-control text-uppercase" id="nombre" name="nombre"
                               oninput="this.value = this.value.toUpperCase()" />
                        <div class="invalid-feedback"></div>
                    </div>

                    <div class="col-md-6">
                        <label for="ruc" class="form-label">RUC</label>
                        <input type="text" class="form-control" id="ruc" name="ruc" maxlength="11"
                               oninput="this.value = this.value.replace(/\D/g,'');" />
                        <div class="invalid-feedback"></div>
                    </div>

                    <div class="col-md-6">
                        <label for="telefono" class="form-label">Teléfono</label>
                        <input type="text" class="form-control" id="telefono" name="telefono" maxlength="9"
                               oninput="this.value = this.value.replace(/\D/g,'');" />
                        <div class="invalid-feedback"></div>
                    </div>

                    <div class="col-md-6">
                        <label for="lugar" class="form-label">Lugar</label>
                        <input type="text" class="form-control text-uppercase" id="lugar" name="lugar"
                               oninput="this.value = this.value.toUpperCase()" />
                        <div class="invalid-feedback"></div>
                    </div>

                    <div class="col-12 text-center mt-4">
                        <div class="d-flex justify-content-center gap-3 flex-wrap">
                            <button type="submit" class="btn btn-success px-4">Agregar Grifo</button>
                            <button type="reset" class="btn btn-outline-danger px-4">Borrar Datos</button>
                        </div>
                    </div>

                </div>
            </form>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="../../Modelo/Archivos_JS/Validacion_Agregar_Grifo.js"></script>

<?php if (isset($_SESSION['error_grifo'])): ?>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
Swal.fire({
    icon: 'error',
    title: 'Registro fallido',
    text: '<?= $_SESSION['error_grifo'] ?>',
    confirmButtonText: 'Aceptar'
});
</script>
<?php unset($_SESSION['error_grifo']); ?>
<?php endif; ?>

</body>
</html>
