//! add object called __clubEmbed with all the variables inside
let t = null, s = !1, m = null, n = null;
const g = () => {
  const e = document.createElement("style");
  e.textContent = `
    .club-badge {
      display: flex;
      align-items: center;
      gap: 4px;
      padding: 12px;
      border-radius: 8px;
      cursor: pointer;
      font-weight: 500;
      transition: background-color 0.3s ease;
      border:none;
      width: 100%;
    }

    .club-badge-text {
      flex: 1;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .club-badge.dark {
      background-color: black;
      color: white;
    }
    .club-badge.light {
      background-color: white;
      color: black;
      border: 1px solid #ddd;
    }
    .club-badge.xSmall {
      height: 28px;
      font-size: 12px;
    }
    .club-badge.small {
      height: 32px;
      font-size: 14px;
    }
    .club-badge.medium {
      height: 40px;
      font-size: 14px;
    }
    .club-badge.large {
      height: 48px;
      font-size: 16px;
    }
    .club-drawer-backdrop {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(16, 24, 40, 0.50);
      z-index: 2147483647;
      transition: opacity 0.3s ease;
      opacity: 0;
      display: none;
    }
    .club-drawer-backdrop.open {
      display: block;
    }
    .club-drawer-backdrop.open.slide-in {
      opacity: 1;
    }
    .club-drawer {
      position: fixed;
      border-radius: 24px;
      overflow: hidden;
      top: 24px;
      right: 24px;
      width: 450px;
      height: calc(100% - 48px);
      background: white;
      box-shadow: -4px 0 6px rgba(0, 0, 0, 0.1);
      transition: transform 0.3s ease;
      z-index: 1;
      transform: translateX(100%);
      display: flex;
      flex-direction: column;

      @media (max-width: 540px) {
        top: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
      }
    }
    .club-drawer-backdrop.open.slide-in .club-drawer {
      transform: translateX(0);
    }
    .club-close-drawer {
      position: absolute;
      top: 43px;
      right: calc(24px + 19px + 450px);
      width: 40px;
      height: 40px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 24px;
      background: rgba(255, 255, 255, 0.60);
      border: none;
      color: black;
      cursor: pointer;
      z-index: 2;
      padding: 0 !important;

      @media (max-width: 540px) {
        display: none;
      }

    }

    .club-drawer-header {
      height: 44px;
      display: none;
      align-items: center;
      justify-content: center;
      background-color: white;
      color: #060708;
      position: relative;      

      @media (max-width: 540px) {
        display: flex;
      }
    }

    .club-close-drawer-header {
      position: absolute;
      width: 40px;
      height: 40px;
      top: 0px;
      right: 5px;
      font-size: 24px;
      border: none;
      color: #060708;
      cursor: pointer;
      background: transparent;
    }

    #club-iframe-container {
      flex: 1;      
    }
  `, document.head.appendChild(e);
}, w = (e) => {
  switch (e) {
    case "xSmall":
    case "small":
      return "16px";
    case "medium":
      return "18px";
    case "large":
      return "20px";
    default:
      return "18px";
  }
}, x = (e) => {
  const a = (e == null ? void 0 : e.getAttribute("data-brand-name")) || "", o = e == null ? void 0 : e.getAttribute(
    "data-badge-size"
  ), r = e == null ? void 0 : e.getAttribute(
    "data-badge-color"
  ), i = (e == null ? void 0 : e.getAttribute("data-badge-text")) || "Join our community", d = w(o), h = `
    <svg width="${d}" height="${d}" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="min-width: ${d};">
      <path d="M12.9504 8.91661L12.9307 9.02483L12.9143 9.10354C12.406 11.4287 10.235 13.1799 7.85737 13.1799C7.51302 13.1799 7.16868 13.1438 6.82106 13.0717C5.49944 12.8388 4.2762 12.0124 3.46618 10.8089C2.63975 9.57578 2.33149 8.08363 2.62336 6.70954C3.06936 4.15484 5.42729 2.23308 8.11316 2.23308C9.18227 2.23308 10.2055 2.55119 11.0647 3.15461C12.1698 3.89577 12.6946 5.10261 12.406 6.22418C12.1338 6.97845 11.2188 7.37199 10.4514 7.37199C9.32328 7.37199 8.36896 6.32912 8.36896 5.09605C8.36896 4.83697 8.16236 4.62708 7.90984 4.62708C7.65732 4.62708 7.45071 4.83697 7.45071 5.09605C7.45071 6.35864 6.43736 7.38183 5.19445 7.38183C4.94193 7.38183 4.73533 7.59171 4.73533 7.85079C4.73533 8.10987 4.94193 8.31975 5.19445 8.31975C6.44064 8.31975 7.45071 9.34294 7.45071 10.6383C7.45071 10.8974 7.65732 11.1073 7.90984 11.1073C8.16236 11.1073 8.36896 10.8974 8.36896 10.6088C8.36896 9.34622 9.38231 8.32303 10.6252 8.32303C11.8681 8.32303 13.2717 7.52284 13.4685 6.18483C13.9244 3.68588 11.6648 1.6231 9.31344 1.1443C8.86088 1.04592 8.39192 1.00001 7.92624 1.00001C5.67653 0.996728 3.50881 2.1183 2.26918 3.92856C0.744229 6.24058 0.586815 8.89693 1.83301 11.2188C3.06608 13.5177 5.48304 15 7.99838 15C9.29705 15 10.5662 14.6229 11.773 13.8883C13.4357 12.8454 14.6262 11.0745 14.9607 9.14617L14.9803 9.02811L15 8.91989H12.9504V8.91661Z" fill="#9667F7"/>
    </svg>
  `;
  return { brandName: a, badgeText: i, badgeSize: o, badgeColor: r, badgeIcon: h };
}, c = (e, a) => {
  if (!s || m !== e) {
    const o = t == null ? void 0 : t.querySelector("#club-iframe-container");
    if (o) {
      const r = document.createElement("iframe");
      r.src = `https://f659b.club.co?func=embed&alias=${encodeURIComponent(e)}${a ? `&intent_id=${encodeURIComponent(a)}` : ""}`, r.style.cssText = "width: 100%; height: 100%; border: none;", r.allow = "clipboard-read; clipboard-write", o.innerHTML = "", o.appendChild(r), s = !0;
    }
  }
}, f = () => {
  var a;
  n = document.querySelector('meta[name="viewport"]');
  const e = document.createElement("meta");
  e.name = "viewport", e.content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no", e.id = "club-viewport-meta-tag", document.head.appendChild(e), n && ((a = n.parentNode) == null || a.removeChild(n));
}, C = () => {
  var a;
  const e = document.querySelector(
    'meta[name="viewport"]'
  );
  e && ((a = e.parentNode) == null || a.removeChild(e)), n && document.head.appendChild(n);
}, v = (e) => {
  const a = e.getAttribute("data-custom") === "true", o = x(e);
  let r;
  if (a) {
    if (r = e.querySelector(":first-child"), !r) {
      console.error("Embed Script: Missing custom button element.");
      return;
    }
  } else
    r = document.createElement("button"), r.className = `club-badge ${o.badgeColor} ${o.badgeSize}`, r.innerHTML = `${o.badgeIcon} <span class="club-badge-text">${o.badgeText}</span>`, r.setAttribute("title", o.badgeText), e.appendChild(r);
  r.addEventListener("click", () => {
    u(o.brandName), b();
    const i = new URL(window.location.href);
    i.searchParams.set("club", o.brandName), window.history.pushState({}, "", i), c(o.brandName);
  });
}, u = (e) => t || (t = document.createElement("div"), t.className = "club-drawer-backdrop", t.innerHTML = `
    <button id="club-close-drawer" class="club-close-drawer">
      <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M15.8334 4.16675L10 10.0001M10 10.0001L4.16669 15.8334M10 10.0001L4.16669 4.16675M10 10.0001L15.8334 15.8334" stroke="#060708" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
      </svg>
    </button>
    <div class="club-drawer">
      <div class="club-drawer-header">
        <span>${e.replace(
  /^./,
  e[0].toUpperCase()
)} on Club</span>
        <button id="club-close-drawer-header" class="club-close-drawer-header">
          <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path d="M15.8334 4.16675L10 10.0001M10 10.0001L4.16669 15.8334M10 10.0001L4.16669 4.16675M10 10.0001L15.8334 15.8334" stroke="#060708" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
          </svg>
      </button>
      </div>

      <div id="club-iframe-container"></div>
    </div>
  `, document.body.appendChild(t), t.querySelector(
  "#club-close-drawer"
).addEventListener("click", l), t.querySelector(
  "#club-close-drawer-header"
).addEventListener("click", l), t), l = () => {
  t == null || t.classList.remove("slide-in");
  const e = new URL(window.location.href);
  e.searchParams.delete("club"), window.history.pushState({}, "", e), window.innerWidth < 540 && C(), setTimeout(() => {
    t && t.classList.remove("open");
  }, 300);
}, b = () => {
  t && (window.innerWidth < 540 && f(), t.classList.add("open"), setTimeout(() => {
    t == null || t.classList.add("slide-in");
  }, 100));
}, p = () => {
  g(), document.querySelectorAll('[data-club-embed="true"]').forEach((i) => {
    if (!i.getAttribute("data-brand-name")) {
      console.error(
        'Embed Script: Missing "data-brand-name" attribute on container.'
      );
      return;
    }
    v(i);
  });
  const a = new URL(window.location.href), o = a.searchParams.get("club"), r = a.searchParams.get("intentid");
  o && (u(o), b(), c(o, r));
};
window.setupClubEmbed = p;
document.addEventListener("DOMContentLoaded", p);
export {
  p as setupClubEmbed
};
