const gameList = [
  {
    banner: "  https://js.analyticpro.online/regis-done/mahjong-ways.png",
    link: "/slots/pgsoft",
    utmContent: "regisdone-pg",
  },
  {
    banner: "https://js.analyticpro.online/regis-done/lucky-neko.png",
    link: "/slots/pgsoft",
    utmContent: "regisdone-pg",
  },
  {
    banner:
      "https://js.analyticpro.online/regis-done/wanted-dead-or-a-wild.png",
    link: "/slots/hacksaw",
    utmContent: "regisdone-hacksaw",
  },
  {
    banner: "https://js.analyticpro.online/regis-done/gate-of-olympus.png",
    link: "/slots/pragmatic",
    utmContent: "regisdone-pp",
  },
  {
    banner: "https://js.analyticpro.online/regis-done/sweet-bonanza.png",
    link: "/slots/pragmatic",
    utmContent: "regisdone-pp",
  },
];
// SLICING UI REGISTER DONE
$(document).ready(function () {
  const regisDoneScriptTag = document.querySelector(
    '[data-script="regis-done"]'
  );
  const siteName = regisDoneScriptTag
    ? regisDoneScriptTag.dataset.siteName
    : "";
  url = new URL(window.location.href);
  const isRegisterDonePage = window.location.href.indexOf("register-done") >= 0;
  const isTesting = url.searchParams.has("test");
  if (isRegisterDonePage) {
    const gameListHtml = gameList.map(
      (game, index) => ` <div class="thumbnail-item">
          <a onclick="sendEvent('${game.utmContent}')" href="${
        game.link
      }" class="top-banner top-${index + 1}"
            ><img
              src="${game.banner}"
              alt=""
          /></a>
        </div>`
    );
    const customHtml = `<div class="toast-winner"><p><span class="name">moll****a</span>baru saja menang<br />IDR<span class="nominal" >9366500.00</span >Lucky Neko </p></div><div class="container"><div class="register-done-wrapper"><div class="banner-wrapper"><div class="image"><img src="https://js.analyticpro.online/regis-done/banner-mobile.png" alt="" /></div><div class="text"><h1>Selamat Bergabung di ${siteName}!</h1><p>Deposit hari ini untuk dapatkan bonus menarik dan nikmati keseruan bermain di ${siteName} </p><a onclick="sendEvent('regisdone-ftd')" href="/deposit" class="btn-red" >DEPOSIT SEKARANG</a ></div></div><div class="info-wrapper"><div class="title"><h2>Promo Eksklusif Hari Ini</h2></div><div class="thumbnail-wrapper"><div class="thumbnail-item purple"><a onclick="sendEvent('regisdone-promo')" href="/promotion" ><img src="https://js.analyticpro.online/regis-done/slot.png" alt="" /><h5>CASHBACK<br /><span>5%</span> SLOT</h5></a ></div><div class="thumbnail-item pink"><a onclick="sendEvent('regisdone-promo')" href="/promotion" ><img src="https://js.analyticpro.online/regis-done/casino.png" alt="" /><h5>CASHBACK<br /><span>5%</span> JUDI BOLA</h5></a ></div><div class="thumbnail-item blue"><a onclick="sendEvent('regisdone-promo')" href="/promotion" ><img src="https://js.analyticpro.online/regis-done/komisi-slot.png" alt="" /><h5>KOMISI<br /><span>0,5%</span> SLOT</h5></a ></div><div class="thumbnail-item green"><a onclick="sendEvent('regisdone-promo')" href="/promotion" ><img src="https://js.analyticpro.online/regis-done/komisi-casino.png" alt="" /><h5>KOMISI<br /><span>0,8%</span> CASINO</h5></a ></div></div></div><div class="games-wrapper"><div class="title"><h2>Game Tergacor Hari Ini</h2></div><div class="thumbnail-wrapper">${gameListHtml.join(
      ""
    )}</div></div></div></div>`;
    if (
      window.location.href.indexOf("mobile") >= 0 ||
      $(window).width() < 768
    ) {
      const originalContainer = $(".register-done-container");
      originalContainer.hide();

      originalContainer.after(customHtml);
    } else {
      const originalContainer = $(".site-content-container");

      originalContainer.html(customHtml);
    }
  }
});

function sendEvent(utmContent) {
  const existingQueryParams = window.localStorage.getItem("queryParams");
  let queryParams = new URLSearchParams(existingQueryParams);
  if (!existingQueryParams) {
    queryParams = new URLSearchParams();
  }
  queryParams.set("utm_regisdone", utmContent);
  window.localStorage.setItem("queryParams", queryParams.toString());
  registerEvent("clickRegisterDone");
}
