const fe = Symbol(), Z = Object.getPrototypeOf, F = /* @__PURE__ */ new WeakMap(), pe = (e) => e && (F.has(e) ? F.get(e) : Z(e) === Object.prototype || Z(e) === Array.prototype), me = (e) => pe(e) && e[fe] || null, ee = (e, t = !0) => {
  F.set(e, t);
}, J = (e) => typeof e == "object" && e !== null, A = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakSet(), ge = (e = Object.is, t = (n, h) => new Proxy(n, h), s = (n) => J(n) && !B.has(n) && (Array.isArray(n) || !(Symbol.iterator in n)) && !(n instanceof WeakMap) && !(n instanceof WeakSet) && !(n instanceof Error) && !(n instanceof Number) && !(n instanceof Date) && !(n instanceof String) && !(n instanceof RegExp) && !(n instanceof ArrayBuffer), o = (n) => {
  switch (n.status) {
    case "fulfilled":
      return n.value;
    case "rejected":
      throw n.reason;
    default:
      throw n;
  }
}, l = /* @__PURE__ */ new WeakMap(), c = (n, h, L = o) => {
  const b = l.get(n);
  if ((b == null ? void 0 : b[0]) === h)
    return b[1];
  const y = Array.isArray(n) ? [] : Object.create(Object.getPrototypeOf(n));
  return ee(y, !0), l.set(n, [h, y]), Reflect.ownKeys(n).forEach((P) => {
    if (Object.getOwnPropertyDescriptor(y, P))
      return;
    const v = Reflect.get(n, P), M = {
      value: v,
      enumerable: !0,
      // This is intentional to avoid copying with proxy-compare.
      // It's still non-writable, so it avoids assigning a value.
      configurable: !0
    };
    if (B.has(v))
      ee(v, !1);
    else if (v instanceof Promise)
      delete M.value, M.get = () => L(v);
    else if (A.has(v)) {
      const [I, z] = A.get(
        v
      );
      M.value = c(
        I,
        z(),
        L
      );
    }
    Object.defineProperty(y, P, M);
  }), Object.preventExtensions(y);
}, m = /* @__PURE__ */ new WeakMap(), p = [1, 1], E = (n) => {
  if (!J(n))
    throw new Error("object required");
  const h = m.get(n);
  if (h)
    return h;
  let L = p[0];
  const b = /* @__PURE__ */ new Set(), y = (i, a = ++p[0]) => {
    L !== a && (L = a, b.forEach((r) => r(i, a)));
  };
  let P = p[1];
  const v = (i = ++p[1]) => (P !== i && !b.size && (P = i, I.forEach(([a]) => {
    const r = a[1](i);
    r > L && (L = r);
  })), L), M = (i) => (a, r) => {
    const g = [...a];
    g[1] = [i, ...g[1]], y(g, r);
  }, I = /* @__PURE__ */ new Map(), z = (i, a) => {
    if (b.size) {
      const r = a[3](M(i));
      I.set(i, [a, r]);
    } else
      I.set(i, [a]);
  }, Y = (i) => {
    var a;
    const r = I.get(i);
    r && (I.delete(i), (a = r[1]) == null || a.call(r));
  }, de = (i) => (b.add(i), b.size === 1 && I.forEach(([r, g], k) => {
    const R = r[3](M(k));
    I.set(k, [r, R]);
  }), () => {
    b.delete(i), b.size === 0 && I.forEach(([r, g], k) => {
      g && (g(), I.set(k, [r]));
    });
  }), H = Array.isArray(n) ? [] : Object.create(Object.getPrototypeOf(n)), $ = t(H, {
    deleteProperty(i, a) {
      const r = Reflect.get(i, a);
      Y(a);
      const g = Reflect.deleteProperty(i, a);
      return g && y(["delete", [a], r]), g;
    },
    set(i, a, r, g) {
      const k = Reflect.has(i, a), R = Reflect.get(i, a, g);
      if (k && (e(R, r) || m.has(r) && e(R, m.get(r))))
        return !0;
      Y(a), J(r) && (r = me(r) || r);
      let V = r;
      if (r instanceof Promise)
        r.then((C) => {
          r.status = "fulfilled", r.value = C, y(["resolve", [a], C]);
        }).catch((C) => {
          r.status = "rejected", r.reason = C, y(["reject", [a], C]);
        });
      else {
        !A.has(r) && s(r) && (V = E(r));
        const C = !B.has(V) && A.get(V);
        C && z(a, C);
      }
      return Reflect.set(i, a, V, g), y(["set", [a], r, R]), !0;
    }
  });
  m.set(n, $);
  const ue = [
    H,
    v,
    c,
    de
  ];
  return A.set($, ue), Reflect.ownKeys(n).forEach((i) => {
    const a = Object.getOwnPropertyDescriptor(
      n,
      i
    );
    "value" in a && ($[i] = n[i], delete a.value, delete a.writable), Object.defineProperty(H, i, a);
  }), $;
}) => [
  // public functions
  E,
  // shared state
  A,
  B,
  // internal things
  e,
  t,
  s,
  o,
  l,
  c,
  m,
  p
], [he] = ge();
function j(e = {}) {
  return he(e);
}
function D(e, t, s) {
  const o = A.get(e);
  let l;
  const c = [], m = o[3];
  let p = !1;
  const n = m((h) => {
    c.push(h), l || (l = Promise.resolve().then(() => {
      l = void 0, p && t(c.splice(0));
    }));
  });
  return p = !0, () => {
    p = !1, n();
  };
}
function be(e, t) {
  const s = A.get(e), [o, l, c] = s;
  return c(o, l(), t);
}
const d = j({ history: ["ConnectWallet"], view: "ConnectWallet", data: void 0 }), ce = { state: d, subscribe(e) {
  return D(d, () => e(d));
}, push(e, t) {
  e !== d.view && (d.view = e, t && (d.data = t), d.history.push(e));
}, reset(e) {
  d.view = e, d.history = [e];
}, replace(e) {
  d.history.length > 1 && (d.history[d.history.length - 1] = e, d.view = e);
}, goBack() {
  if (d.history.length > 1) {
    d.history.pop();
    const [e] = d.history.slice(-1);
    d.view = e;
  }
}, setData(e) {
  d.data = e;
} }, f = { WALLETCONNECT_DEEPLINK_CHOICE: "WALLETCONNECT_DEEPLINK_CHOICE", WCM_VERSION: "WCM_VERSION", RECOMMENDED_WALLET_AMOUNT: 9, isMobile() {
  return typeof window < "u" ? !!(window.matchMedia("(pointer:coarse)").matches || /Android|webOS|iPhone|iPad|iPod|BlackBerry|Opera Mini/u.test(navigator.userAgent)) : !1;
}, isAndroid() {
  return f.isMobile() && navigator.userAgent.toLowerCase().includes("android");
}, isIos() {
  const e = navigator.userAgent.toLowerCase();
  return f.isMobile() && (e.includes("iphone") || e.includes("ipad"));
}, isHttpUrl(e) {
  return e.startsWith("http://") || e.startsWith("https://");
}, isArray(e) {
  return Array.isArray(e) && e.length > 0;
}, formatNativeUrl(e, t, s) {
  if (f.isHttpUrl(e)) return this.formatUniversalUrl(e, t, s);
  let o = e;
  o.includes("://") || (o = e.replaceAll("/", "").replaceAll(":", ""), o = `${o}://`), o.endsWith("/") || (o = `${o}/`), this.setWalletConnectDeepLink(o, s);
  const l = encodeURIComponent(t);
  return `${o}wc?uri=${l}`;
}, formatUniversalUrl(e, t, s) {
  if (!f.isHttpUrl(e)) return this.formatNativeUrl(e, t, s);
  let o = e;
  o.endsWith("/") || (o = `${o}/`), this.setWalletConnectDeepLink(o, s);
  const l = encodeURIComponent(t);
  return `${o}wc?uri=${l}`;
}, async wait(e) {
  return new Promise((t) => {
    setTimeout(t, e);
  });
}, openHref(e, t) {
  window.open(e, t, "noreferrer noopener");
}, setWalletConnectDeepLink(e, t) {
  try {
    localStorage.setItem(f.WALLETCONNECT_DEEPLINK_CHOICE, JSON.stringify({ href: e, name: t }));
  } catch {
    console.info("Unable to set WalletConnect deep link");
  }
}, setWalletConnectAndroidDeepLink(e) {
  try {
    const [t] = e.split("?");
    localStorage.setItem(f.WALLETCONNECT_DEEPLINK_CHOICE, JSON.stringify({ href: t, name: "Android" }));
  } catch {
    console.info("Unable to set WalletConnect android deep link");
  }
}, removeWalletConnectDeepLink() {
  try {
    localStorage.removeItem(f.WALLETCONNECT_DEEPLINK_CHOICE);
  } catch {
    console.info("Unable to remove WalletConnect deep link");
  }
}, setModalVersionInStorage() {
  try {
    typeof localStorage < "u" && localStorage.setItem(f.WCM_VERSION, "2.6.2");
  } catch {
    console.info("Unable to set Web3Modal version in storage");
  }
}, getWalletRouterData() {
  var e;
  const t = (e = ce.state.data) == null ? void 0 : e.Wallet;
  if (!t) throw new Error('Missing "Wallet" view data');
  return t;
} }, ye = typeof location < "u" && (location.hostname.includes("localhost") || location.protocol.includes("https")), u = j({ enabled: ye, userSessionId: "", events: [], connectedWalletId: void 0 }), Ie = { state: u, subscribe(e) {
  return D(u.events, () => e(be(u.events[u.events.length - 1])));
}, initialize() {
  u.enabled && typeof (crypto == null ? void 0 : crypto.randomUUID) < "u" && (u.userSessionId = crypto.randomUUID());
}, setConnectedWalletId(e) {
  u.connectedWalletId = e;
}, click(e) {
  if (u.enabled) {
    const t = { type: "CLICK", name: e.name, userSessionId: u.userSessionId, timestamp: Date.now(), data: e };
    u.events.push(t);
  }
}, track(e) {
  if (u.enabled) {
    const t = { type: "TRACK", name: e.name, userSessionId: u.userSessionId, timestamp: Date.now(), data: e };
    u.events.push(t);
  }
}, view(e) {
  if (u.enabled) {
    const t = { type: "VIEW", name: e.name, userSessionId: u.userSessionId, timestamp: Date.now(), data: e };
    u.events.push(t);
  }
} }, W = j({ chains: void 0, walletConnectUri: void 0, isAuth: !1, isCustomDesktop: !1, isCustomMobile: !1, isDataLoaded: !1, isUiLoaded: !1 }), w = { state: W, subscribe(e) {
  return D(W, () => e(W));
}, setChains(e) {
  W.chains = e;
}, setWalletConnectUri(e) {
  W.walletConnectUri = e;
}, setIsCustomDesktop(e) {
  W.isCustomDesktop = e;
}, setIsCustomMobile(e) {
  W.isCustomMobile = e;
}, setIsDataLoaded(e) {
  W.isDataLoaded = e;
}, setIsUiLoaded(e) {
  W.isUiLoaded = e;
}, setIsAuth(e) {
  W.isAuth = e;
} }, K = j({ projectId: "", mobileWallets: void 0, desktopWallets: void 0, walletImages: void 0, chains: void 0, enableAuthMode: !1, enableExplorer: !0, explorerExcludedWalletIds: void 0, explorerRecommendedWalletIds: void 0, termsOfServiceUrl: void 0, privacyPolicyUrl: void 0 }), T = { state: K, subscribe(e) {
  return D(K, () => e(K));
}, setConfig(e) {
  var t, s;
  Ie.initialize(), w.setChains(e.chains), w.setIsAuth(!!e.enableAuthMode), w.setIsCustomMobile(!!((t = e.mobileWallets) != null && t.length)), w.setIsCustomDesktop(!!((s = e.desktopWallets) != null && s.length)), f.setModalVersionInStorage(), Object.assign(K, e);
} };
var we = Object.defineProperty, te = Object.getOwnPropertySymbols, Le = Object.prototype.hasOwnProperty, We = Object.prototype.propertyIsEnumerable, se = (e, t, s) => t in e ? we(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, Oe = (e, t) => {
  for (var s in t || (t = {})) Le.call(t, s) && se(e, s, t[s]);
  if (te) for (var s of te(t)) We.call(t, s) && se(e, s, t[s]);
  return e;
};
const G = "https://explorer-api.walletconnect.com", Q = "wcm", X = "js-2.6.2";
async function x(e, t) {
  const s = Oe({ sdkType: Q, sdkVersion: X }, t), o = new URL(e, G);
  return o.searchParams.append("projectId", T.state.projectId), Object.entries(s).forEach(([l, c]) => {
    c && o.searchParams.append(l, String(c));
  }), (await fetch(o)).json();
}
const U = { async getDesktopListings(e) {
  return x("/w3m/v1/getDesktopListings", e);
}, async getMobileListings(e) {
  return x("/w3m/v1/getMobileListings", e);
}, async getInjectedListings(e) {
  return x("/w3m/v1/getInjectedListings", e);
}, async getAllListings(e) {
  return x("/w3m/v1/getAllListings", e);
}, getWalletImageUrl(e) {
  return `${G}/w3m/v1/getWalletImage/${e}?projectId=${T.state.projectId}&sdkType=${Q}&sdkVersion=${X}`;
}, getAssetImageUrl(e) {
  return `${G}/w3m/v1/getAssetImage/${e}?projectId=${T.state.projectId}&sdkType=${Q}&sdkVersion=${X}`;
} };
var ve = Object.defineProperty, ne = Object.getOwnPropertySymbols, Ee = Object.prototype.hasOwnProperty, Ce = Object.prototype.propertyIsEnumerable, re = (e, t, s) => t in e ? ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, Ae = (e, t) => {
  for (var s in t || (t = {})) Ee.call(t, s) && re(e, s, t[s]);
  if (ne) for (var s of ne(t)) Ce.call(t, s) && re(e, s, t[s]);
  return e;
};
const oe = f.isMobile(), O = j({ wallets: { listings: [], total: 0, page: 1 }, search: { listings: [], total: 0, page: 1 }, recomendedWallets: [] }), Ne = { state: O, async getRecomendedWallets() {
  const { explorerRecommendedWalletIds: e, explorerExcludedWalletIds: t } = T.state;
  if (e === "NONE" || t === "ALL" && !e) return O.recomendedWallets;
  if (f.isArray(e)) {
    const s = { recommendedIds: e.join(",") }, { listings: o } = await U.getAllListings(s), l = Object.values(o);
    l.sort((c, m) => {
      const p = e.indexOf(c.id), E = e.indexOf(m.id);
      return p - E;
    }), O.recomendedWallets = l;
  } else {
    const { chains: s, isAuth: o } = w.state, l = s == null ? void 0 : s.join(","), c = f.isArray(t), m = { page: 1, sdks: o ? "auth_v1" : void 0, entries: f.RECOMMENDED_WALLET_AMOUNT, chains: l, version: 2, excludedIds: c ? t.join(",") : void 0 }, { listings: p } = oe ? await U.getMobileListings(m) : await U.getDesktopListings(m);
    O.recomendedWallets = Object.values(p);
  }
  return O.recomendedWallets;
}, async getWallets(e) {
  const t = Ae({}, e), { explorerRecommendedWalletIds: s, explorerExcludedWalletIds: o } = T.state, { recomendedWallets: l } = O;
  if (o === "ALL") return O.wallets;
  l.length ? t.excludedIds = l.map((L) => L.id).join(",") : f.isArray(s) && (t.excludedIds = s.join(",")), f.isArray(o) && (t.excludedIds = [t.excludedIds, o].filter(Boolean).join(",")), w.state.isAuth && (t.sdks = "auth_v1");
  const { page: c, search: m } = e, { listings: p, total: E } = oe ? await U.getMobileListings(t) : await U.getDesktopListings(t), n = Object.values(p), h = m ? "search" : "wallets";
  return O[h] = { listings: [...O[h].listings, ...n], total: E, page: c ?? 1 }, { listings: n, total: E };
}, getWalletImageUrl(e) {
  return U.getWalletImageUrl(e);
}, getAssetImageUrl(e) {
  return U.getAssetImageUrl(e);
}, resetSearch() {
  O.search = { listings: [], total: 0, page: 1 };
} }, N = j({ open: !1 }), q = { state: N, subscribe(e) {
  return D(N, () => e(N));
}, async open(e) {
  return new Promise((t) => {
    const { isUiLoaded: s, isDataLoaded: o } = w.state;
    if (f.removeWalletConnectDeepLink(), w.setWalletConnectUri(e == null ? void 0 : e.uri), w.setChains(e == null ? void 0 : e.chains), ce.reset("ConnectWallet"), s && o) N.open = !0, t();
    else {
      const l = setInterval(() => {
        const c = w.state;
        c.isUiLoaded && c.isDataLoaded && (clearInterval(l), N.open = !0, t());
      }, 200);
    }
  });
}, close() {
  N.open = !1;
} };
var je = Object.defineProperty, ae = Object.getOwnPropertySymbols, Me = Object.prototype.hasOwnProperty, Ue = Object.prototype.propertyIsEnumerable, ie = (e, t, s) => t in e ? je(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, Se = (e, t) => {
  for (var s in t || (t = {})) Me.call(t, s) && ie(e, s, t[s]);
  if (ae) for (var s of ae(t)) Ue.call(t, s) && ie(e, s, t[s]);
  return e;
};
function De() {
  return typeof matchMedia < "u" && matchMedia("(prefers-color-scheme: dark)").matches;
}
const _ = j({ themeMode: De() ? "dark" : "light" }), le = { state: _, subscribe(e) {
  return D(_, () => e(_));
}, setThemeConfig(e) {
  const { themeMode: t, themeVariables: s } = e;
  t && (_.themeMode = t), s && (_.themeVariables = Se({}, s));
} }, S = j({ open: !1, message: "", variant: "success" }), Te = { state: S, subscribe(e) {
  return D(S, () => e(S));
}, openToast(e, t) {
  S.open = !0, S.message = e, S.variant = t;
}, closeToast() {
  S.open = !1;
} };
class Pe {
  constructor(t) {
    this.openModal = q.open, this.closeModal = q.close, this.subscribeModal = q.subscribe, this.setTheme = le.setThemeConfig, le.setThemeConfig(t), T.setConfig(t), this.initUi();
  }
  async initUi() {
    if (typeof window < "u") {
      await import("./index-ByaJFPk7.mjs");
      const t = document.createElement("wcm-modal");
      document.body.insertAdjacentElement("beforeend", t), w.setIsUiLoaded(!0);
    }
  }
}
const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  WalletConnectModal: Pe
}, Symbol.toStringTag, { value: "Module" }));
export {
  Ie as R,
  ce as T,
  f as a,
  Re as i,
  le as n,
  Te as o,
  w as p,
  q as s,
  Ne as t,
  T as y
};
