<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>BWM XMD Verification Check</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
    }
    .video-bg {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      z-index: -1;
      filter: brightness(0.5);
    }
    .container {
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 100%;
      max-width: 400px;
      padding: 20px;
      border-radius: 15px;
      box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
      background: linear-gradient(145deg, rgba(0,123,255,0.9), rgba(50,205,50,0.9));
      backdrop-filter: blur(10px);
    }
    .input-container input, button {
      width: 100%;
      padding: 10px;
      margin: 10px 0;
      border-radius: 50px;
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    }
    button {
      background: linear-gradient(135deg, #ff7e5f, #feb47b);
      color: #fff;
      cursor: pointer;
      border: none;
      outline: none;
      transition: all 0.3s ease;
    }
    button:disabled {
      cursor: not-allowed;
      background: grey;
    }
    .spinner {
      border: 3px solid rgba(0, 0, 0, 0.1);
      border-left-color: #fff;
      border-radius: 50%;
      width: 20px;
      height: 20px;
      animation: spin 1s linear infinite;
      display: none;
      margin-left: 10px;
    }
    @keyframes spin {
      to { transform: rotate(360deg); }
    }
  </style>
</head>
<body>
  <video class="video-bg" autoplay muted loop>
    <source src="https://files.catbox.moe/ks39u0.mp4" type="video/mp4">
  </video>
  <div class="container">
    <h2>Enter Forked Repo URL</h2>
    <div class="input-container">
      <input type="text" id="repoInput" placeholder="Enter Your Forked Repo URL">
    </div>
    <button id="deployButton" onclick="connectRepo()">Deploy</button>
    <div class="spinner" id="spinner"></div>
  </div>

  <script async src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>
  <script>
    async function connectRepo() {
      const repoURL = document.getElementById('repoInput').value.trim();
      const button = document.getElementById('deployButton');
      const spinner = document.getElementById('spinner');

      button.disabled = true;
      spinner.style.display = "inline-block";
      button.textContent = "Loading...";

      try {
        const blockedURLs = ["https://github.com/devibrah/NORMAL-BOT", "https://github.com/devibraah/BWM-XMD"];
        if (blockedURLs.includes(repoURL) || repoURL.includes("devibraah")) {
          alert("This is the original repo URL. Fork your own repository.");
          window.open('https://github.com/devibrah/NORMAL-BOT/fork', '_blank');
        } else if (!repoURL.startsWith("https://github.com/")) {
          alert("Please enter a valid GitHub repository URL.");
        } else {
          const repoParts = repoURL.replace("https://github.com/", "").split("/");
          if (repoParts.length !== 2) throw new Error("Invalid URL format");

          const [owner, repo] = repoParts;
          const repoResponse = await axios.get(`https://api.github.com/repos/${owner}/${repo}`);

          if (!repoResponse.data.fork) {
            alert("The provided repository is not forked. Tap OK to fork...");
            window.open('https://github.com/devibrah/NORMAL-BOT/fork', '_blank');
          } else {
            const mainCommitResponse = await axios.get("https://api.github.com/repos/devibrah/NORMAL-BOT/commits/main");
            const forkCommitResponse = await axios.get(`https://api.github.com/repos/${owner}/${repo}/commits/main`);
            if (mainCommitResponse.data.sha !== forkCommitResponse.data.sha) {
              alert("Your fork is outdated 🥲. Tap OK to sync...");
              window.open(`https://github.com/${owner}/${repo}`, '_blank');
            } else {
              alert("Your fork is up-to-date ✅. Deploying...");
              window.open(`https://dashboard.heroku.com/new?template=${repoURL}`, '_blank');
            }
          }
        }
      } catch (error) {
        alert("An error occurred. Please check the URL and try again.");
      } finally {
        button.disabled = false;
        spinner.style.display = "none";
        button.textContent = "Deploy";
      }
    }
  </script>
</body>
</html>