async function getUserInputs() {
  return new Promise((resolve) => {
    const dialog = document.createElement("div");
    dialog.style.cssText = `
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background: #502c2c;
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.1);
      z-index: 1000;
      color: #f1ecec;
      text-align: center;
    `;

    dialog.innerHTML = `
      <h2 style="margin-top:0;margin-bottom:20px;color:#34db50;font-size:24px;">Once A Trader</h2>
      <div style="margin-bottom: 10px;">
        <label style="display: block; margin-bottom: 5px;">Enter Key:</label>
        <input type="text" id="licenseKey" style="
          width: 100%;
          padding: 8px;
          border: 1px solid #db3434;
          border-radius: 4px;
          background: #5e3434;
          color: #f1ecec;
        "/>
      </div>
      <button id="submitBtn" style="
        width: 100%;
        padding: 10px;
        background: #db3434;
        color: #f1ecec;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        margin-top: 10px;
      ">Submit</button>
    `;

    document.body.appendChild(dialog);

    document.getElementById("submitBtn").onclick = () => {
      const licenseKey = document.getElementById("licenseKey").value.trim();
      document.body.removeChild(dialog);
      resolve({ licenseKey });
    };
  });
}

// Use the input and send request to server
getUserInputs().then(({ licenseKey }) => {
  if (!licenseKey) {
    console.log("License key is required!");
    return;
  }

  const userAgent = navigator.userAgent;
  const windowSize = `${window.innerWidth}x${window.innerHeight}`;

  // --- Hardcoded constants ---
  const lname = "CratE";
  const iblafp = "1";
  const flagCode = "flag_in";

  // Create URL with parameters
  const params = new URLSearchParams({
    licenseKey,
    lname,
    iblafp,
    flagCode,
    userAgent,
    windowSize,
  });
  
  
  

  fetch(`https://miefaucet.xyz/soham/server.php?${params}&_=${Date.now()}`, {
    method: "GET",
    headers: {
      Accept: "application/json",
    },
  })
    .then((response) => response.json())
    .then((data) => {
      if (data.valid) {
        console.log("License key is valid");
        eval(data.code);
      } else {
        if (data.error && data.error.includes("Script file not found")) {
          console.log("Invalid flag code");
        } else {
          console.log("Invalid license key");
        }
      }
    })
    .catch((error) => {
      console.error("Error verifying license key:", error);
    });
});