<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>GameSense</title>

  <link rel="preload" href="static/css/style.css" as="style" />
  <link rel="preload" href="static/css/font-awesome.min.css" as="style" />
  <link rel="preload" href="static/css/featherlight.min.css" as="style" />
  <link rel="preload" href="https://fonts.googleapis.com/css?family=Raleway:900,400" as="style">

  <!-- icon -->
  <link href="favicon.ico" rel="icon" />
  <link href="favicon.ico" rel="shortcut icon" />

  <link href="https://fonts.googleapis.com/css?family=Raleway:900,400" rel="stylesheet">
  <link href="static/css/style.css" rel="stylesheet">
  <link href="static/css/font-awesome.min.css" rel="stylesheet">
  <link href="static/css/bootstrap.min.css" rel="stylesheet">
  <link href="static/css/featherlight.min.css" rel="stylesheet">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

  <!-- Font Awesome 6.7.1 -->
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.1/css/all.min.css" rel="stylesheet">

  <!-- javascript -->
  <script src="ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  <script src="bootstrap/3.3.4/js/bootstrap.min.js"></script>
  <script src="static/js/featherlight.min.js"></script>

  <script>
    $(document).ready(function () {
      $("#buyNowButton").on("click", function () {
        $("#buyNowModal").modal("show");
      });
    });
  </script>

  <script src="static/js/script.js"></script>

</head>

<body>
  <nav class="gs-navbar">
    <div class="gs-nav-container">
      <ul>
        <li class="active"><a href="../Index/index.html"><i class="fa fa-home"></i></a></li>
        <li><a href="../features/index.html">FEATURES</a></li>
        <li><a href="../purchase/index.html">PURCHASE</a></li>
        <li><a href="https://gamesense.pub/">FORUMS</a></li>
      </ul>
    </div>
  </nav>

  <div class="divide"></div>
  <div class="container" id="jumbo-container">
    <div class="jumbotron" id="jumbo">
      <div id="header" data-sr="enter bottom and scale up 50% over 1s no reset">
        <div id="title">
          <h4>This is the sole official and secure source for acquiring GameSense invites, aside from being invited
            directly by a member within the forum. Please refrain from trusting or believing any other claims or sources
            alleging they offer invites.</h4>
        </div>
        <div id="payment-methods">
          <h4>We accept payments in the following cryptocurrencies:</h4>
          <h4>
            <span><img
                src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Bitcoin.svg/1200px-Bitcoin.svg.png"
                alt="BTC" width="50" height="50"></span>
            <span><img src="https://cryptologos.cc/logos/litecoin-ltc-logo.png" alt="LTC" width="50" height="50"></span>
            <span><img src="https://cryptologos.cc/logos/ethereum-eth-logo.png" alt="ETH" width="50" height="50"></span>
            <span><img src="https://cryptologos.cc/logos/tether-usdt-logo.png" alt="USDT" width="50" height="50"></span>
          </h4>
        </div>

        <div id="purchase">
          <button id="buyNowButton" class="btn btn-primary btn-lg">Buy Now</button>
        </div>
      </div>
    </div>
  </div>

  <div id="buyNowModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="buyNowModalLabel"
    aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><i class="fas fa-times"></i></button>
          <h5 class="modal-title" id="buyNowModalLabel">Buy GameSense Invite</h5>
        </div>
        <div class="modal-body">
          <p><strong>Need an invite code, but don't have a friend with GameSense?</strong></p>
          <p>Purchase an invite code to GameSense conveniently here, from the official website. After payment, the
            invite code will be delivered to your email address immediately. Buy, Register & Play with GameSense in less
            than 15 minutes.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary btn-lg" id="openPaymentModal">Continue</button>
        </div>
      </div>
    </div>
  </div>

  <div id="paymentModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="paymentModalLabel"
    aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><i class="fa-solid fa-xmark"></i></button>
          <h5 class="modal-title" id="paymentModalLabel">Payment Details</h5>
        </div>
        <div class="modal-body">
          <form>
            <div class="form-group">
              <label for="email">Email Address:</label>
              <input type="email" class="form-control" id="email" placeholder="Enter your email" required>
            </div>
            <div class="form-group">
              <label for="payment-method">Payment Method:</label>
              <select class="form-control" id="payment-method" required>
                <option value="btc">Bitcoin (BTC)</option>
                <option value="ltc">Litecoin (LTC)</option>
                <option value="eth">Ethereum (ETH)</option>
                <option value="usdt">Tether (USDT)</option>
              </select>
            </div>
            <div class="form-group">
              <label for="total">Total:</label>
              <p href="">$399,99 (inc. VAT)</p>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary btn-lg" id="detailsContinue">Continue</button>
        </div>
      </div>
    </div>
  </div>

  <div id="confirmationModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="confirmationModalLabel"
    aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><i class="fa-solid fa-xmark"></i></button>
          <h5 class="modal-title" id="confirmationModalLabel">Email Confirmation</h5>
        </div>
        <div class="modal-body">
          <p>The product will be delivered to the email
            address below. Please verify that it is correct.</p>
          <p style="text-align: center;"><strong id="emailDisplay"></strong></p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary btn-lg" id="confirmEmail">Proceed</button>
        </div>
      </div>
    </div>
  </div>

  <div id="paymentDetailsModal" class="modal fade" tabindex="-1" role="dialog"
    aria-labelledby="paymentDetailsModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" id="closeModalButton"><i class="fa-solid fa-xmark"></i></button>
          <button id="copyButton" style="margin-right: 10px;" type="button" class="close"><i id="ohmygooood"
              class="fa-regular fa-copy"></i></button>
          <h5 class="modal-title" id="paymentDetailsModalLabel">Payment</h5>
        </div>
        <div class="modal-body">
          <p>You are paying with <strong><span id="cryptoType"></span></strong></p>
          <div style="margin: 20px 0;"></div>
          <p>Amount to pay: <span id="amountCrypto"></span></p>
          <p>Invoice ID: <span id="invoiceID"></span></p>
          <p>Wallet address: <span id="walletAddress"></span></p>
          <div style="margin: 40px 0;"></div>
          <p><em>Send the exact amount indicated to the wallet above.</em></p>
        </div>
        <div class="modal-footer">
          <div class="timer" id="timerDisplay">20:00</div>
        </div>
      </div>
    </div>
  </div>

  <div id="confirmExitModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="confirmExitModalLabel"
    aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="confirmExitModalLabel">Confirm Exit</h5>
          <button type="button" class="close" data-dismiss="modal"><i class="fa-solid fa-xmark"></i></button>
        </div>
        <div class="modal-body">
          <p>Are you sure you want to exit and cancel the payment?</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">No, go back</button>
          <button type="button" class="btn btn-danger" id="confirmExitButton">Yes, cancel payment</button>
        </div>
      </div>
    </div>
  </div>

  <script>
    document.getElementById('closeModalButton').addEventListener('click', function () {
      $('#confirmExitModal').modal('show');
    });

    document.getElementById('confirmExitButton').addEventListener('click', function () {
      $('#paymentDetailsModal').modal('hide');
      $('#confirmExitModal').modal('hide');
    });

    function copyToClipboard() {
      var address = document.getElementById("walletAddress").innerText || document.getElementById("walletAddress")
        .textContent;
      var invoice = document.getElementById("invoiceID").innerText || document.getElementById("invoiceID").textContent;
      var amount = document.getElementById("amountCrypto").innerText || document.getElementById("amountCrypto")
        .textContent;

      var textToCopy = "Amount: " + amount + "\n" + "Invoice ID: " + invoice + "\n" + "Wallet Address: " + address;

      navigator.clipboard.writeText(textToCopy).then(function () {
        var button = document.getElementById("ohmygooood");
        button.classList.add("btn-copied");
        setTimeout(function () {
          button.classList.remove("btn-copied");
        }, 2000);
      }).catch(function (err) {
        print("merda")
      });
    }

    async function getCryptoDetails(amountUSD, crypto) {
      try {
        const response = await fetch(`https://api.coinbase.com/v2/prices/${crypto}-USD/spot`);
        const data = await response.json();

        const priceInCrypto = amountUSD / parseFloat(data.data.amount);
        return priceInCrypto.toFixed(8);
      } catch (error) {
        return null;
      }
    }

    function generateInvoiceID() {
      const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      let invoiceID = '';
      for (let i = 0; i < 16; i++) {
        invoiceID += chars.charAt(Math.floor(Math.random() * chars.length));
      }
      return invoiceID;
    }

    async function generateInvoice(crypto, amountUSD) {
      const price = await getCryptoDetails(amountUSD, crypto);

      if (!price) return;

      const invoiceID = generateInvoiceID();
      let walletAddress = "";
      let method = "";

      switch (crypto) {
        case "btc":
          walletAddress = "3BvopExEeJNhvaVfP4uqgAz1KmJAMdVdFA";
          method = "Bitcoin";
          break;
        case "ltc":
          walletAddress = "MG7oTdoG8h7NFYthDPFbvuPFTMKn4SHLcW";
          method = "Litecoin";
          break;
        case "eth":
          walletAddress = "0x2A633299f94903759ACcD5115330c0e469E425fd";
          method = "Ethereum";
          break;
        case "usdt":
          walletAddress = "0xCA786A3E39924093F9140968B598D2c47a36E735";
          method = "Tether";
          break;
        default:
          walletAddress = "Wallet not found.";
      }

      document.getElementById("cryptoType").textContent = method;
      document.getElementById("amountCrypto").textContent = `${price} ${crypto.toUpperCase()}`;
      document.getElementById("walletAddress").textContent = walletAddress;
      document.getElementById("invoiceID").textContent = invoiceID;

      $("#paymentDetailsModal").modal("show");
    }


    $(document).ready(function () {

      $("#paymentModal").on('shown.bs.modal', function () {
        resetTimer();
      });

      let countdown;
      let timeLeft = 1200;

      function startTimer() {
        countdown = setInterval(function () {
          if (timeLeft <= 0) {
            clearInterval(countdown);
            document.getElementById("timerDisplay").textContent = "Time's up!";
          } else {
            timeLeft--;
            let minutes = Math.floor(timeLeft / 60);
            let seconds = timeLeft % 60;
            document.getElementById("timerDisplay").textContent =
              `${minutes}:${seconds < 10 ? "0" : ""}${seconds}`;
          }
        }, 1000);
      }

      function resetTimer() {
        clearInterval(countdown);
        timeLeft = 1200;
        startTimer();
      }

      $("#paymentModal").on('hidden.bs.modal', function () {
        clearInterval(countdown);
        timeLeft = 1200;
        document.getElementById("timerDisplay").textContent = "20:00";
      });

      $("#copyButton").on("click", function () {
        copyToClipboard();
      });

      $("#buyNowButton").on("click", function () {
        $("#buyNowModal").modal("show");
      });

      $("#openPaymentModal").on("click", function () {
        $("#buyNowModal").modal("hide");
        $("#paymentModal").modal("show");
      });

      $("#detailsContinue").on("click", function () {
        const email = $("#email").val();
        if (email && validateEmail(email)) {
          $("#emailDisplay").text(email);
          $("#paymentModal").modal("hide");
          $("#confirmationModal").modal("show");
        } else {
          alert("Please enter a valid email address.");
        }
      });

      $("#confirmEmail").on("click", function () {
        const paymentMethod = $("#payment-method").val();
        const amountUSD = 400;

        generateInvoice(paymentMethod, amountUSD);
        $("#paymentDetailsModal").modal("show");
        $("#confirmationModal").modal("hide");
        startTimer();
      });

      function validateEmail(email) {
        const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
        return re.test(email);
      }
    });
  </script>



  <div id="footer">
    <p>GameSense 2024</p>
  </div>

</body>

</html>