import { aK as require$$0 } from './wallet-3e4cc9a4.js';

var proxyCompare = require$$0;

var isObject = function isObject(x) {
  return typeof x === 'object' && x !== null;
};
var proxyStateMap = new WeakMap();
var refSet = new WeakSet();
var buildProxyFunction = function buildProxyFunction(objectIs, newProxy, canProxy, defaultHandlePromise, snapCache, createSnapshot, proxyCache, versionHolder, _proxyFunction) {
  if (objectIs === void 0) {
    objectIs = Object.is;
  }
  if (newProxy === void 0) {
    newProxy = function newProxy(target, handler) {
      return new Proxy(target, handler);
    };
  }
  if (canProxy === void 0) {
    canProxy = function canProxy(x) {
      return isObject(x) && !refSet.has(x) && (Array.isArray(x) || !(Symbol.iterator in x)) && !(x instanceof WeakMap) && !(x instanceof WeakSet) && !(x instanceof Error) && !(x instanceof Number) && !(x instanceof Date) && !(x instanceof String) && !(x instanceof RegExp) && !(x instanceof ArrayBuffer);
    };
  }
  if (defaultHandlePromise === void 0) {
    defaultHandlePromise = function defaultHandlePromise(promise) {
      switch (promise.status) {
        case 'fulfilled':
          return promise.value;
        case 'rejected':
          throw promise.reason;
        default:
          throw promise;
      }
    };
  }
  if (snapCache === void 0) {
    snapCache = new WeakMap();
  }
  if (createSnapshot === void 0) {
    createSnapshot = function (_createSnapshot) {
      function createSnapshot(_x, _x2, _x3) {
        return _createSnapshot.apply(this, arguments);
      }
      createSnapshot.toString = function () {
        return _createSnapshot.toString();
      };
      return createSnapshot;
    }(function (target, version, handlePromise) {
      if (handlePromise === void 0) {
        handlePromise = defaultHandlePromise;
      }
      var cache = snapCache.get(target);
      if ((cache == null ? void 0 : cache[0]) === version) {
        return cache[1];
      }
      var snap = Array.isArray(target) ? [] : Object.create(Object.getPrototypeOf(target));
      proxyCompare.markToTrack(snap, true);
      snapCache.set(target, [version, snap]);
      Reflect.ownKeys(target).forEach(function (key) {
        if (Object.getOwnPropertyDescriptor(snap, key)) {
          return;
        }
        var value = Reflect.get(target, key);
        var desc = {
          value: value,
          enumerable: true,
          configurable: true
        };
        if (refSet.has(value)) {
          proxyCompare.markToTrack(value, false);
        } else if (value instanceof Promise) {
          delete desc.value;
          desc.get = function () {
            return handlePromise(value);
          };
        } else if (proxyStateMap.has(value)) {
          var _ref = proxyStateMap.get(value),
            _target = _ref[0],
            _ensureVersion = _ref[1];
          desc.value = createSnapshot(_target, _ensureVersion(), handlePromise);
        }
        Object.defineProperty(snap, key, desc);
      });
      return Object.preventExtensions(snap);
    });
  }
  if (proxyCache === void 0) {
    proxyCache = new WeakMap();
  }
  if (versionHolder === void 0) {
    versionHolder = [1, 1];
  }
  if (_proxyFunction === void 0) {
    _proxyFunction = function proxyFunction(initialObject) {
      if (!isObject(initialObject)) {
        throw new Error('object required');
      }
      var found = proxyCache.get(initialObject);
      if (found) {
        return found;
      }
      var version = versionHolder[0];
      var listeners = new Set();
      var notifyUpdate = function notifyUpdate(op, nextVersion) {
        if (nextVersion === void 0) {
          nextVersion = ++versionHolder[0];
        }
        if (version !== nextVersion) {
          version = nextVersion;
          listeners.forEach(function (listener) {
            return listener(op, nextVersion);
          });
        }
      };
      var checkVersion = versionHolder[1];
      var ensureVersion = function ensureVersion(nextCheckVersion) {
        if (nextCheckVersion === void 0) {
          nextCheckVersion = ++versionHolder[1];
        }
        if (checkVersion !== nextCheckVersion && !listeners.size) {
          checkVersion = nextCheckVersion;
          propProxyStates.forEach(function (_ref2) {
            var propProxyState = _ref2[0];
            var propVersion = propProxyState[1](nextCheckVersion);
            if (propVersion > version) {
              version = propVersion;
            }
          });
        }
        return version;
      };
      var createPropListener = function createPropListener(prop) {
        return function (op, nextVersion) {
          var newOp = [].concat(op);
          newOp[1] = [prop].concat(newOp[1]);
          notifyUpdate(newOp, nextVersion);
        };
      };
      var propProxyStates = new Map();
      var addPropListener = function addPropListener(prop, propProxyState) {
        if (listeners.size) {
          var remove = propProxyState[3](createPropListener(prop));
          propProxyStates.set(prop, [propProxyState, remove]);
        } else {
          propProxyStates.set(prop, [propProxyState]);
        }
      };
      var removePropListener = function removePropListener(prop) {
        var entry = propProxyStates.get(prop);
        if (entry) {
          var _entry$;
          propProxyStates.delete(prop);
          (_entry$ = entry[1]) == null ? void 0 : _entry$.call(entry);
        }
      };
      var addListener = function addListener(listener) {
        listeners.add(listener);
        if (listeners.size === 1) {
          propProxyStates.forEach(function (_ref3, prop) {
            var propProxyState = _ref3[0];
            var remove = propProxyState[3](createPropListener(prop));
            propProxyStates.set(prop, [propProxyState, remove]);
          });
        }
        var removeListener = function removeListener() {
          listeners.delete(listener);
          if (listeners.size === 0) {
            propProxyStates.forEach(function (_ref4, prop) {
              var propProxyState = _ref4[0],
                remove = _ref4[1];
              if (remove) {
                remove();
                propProxyStates.set(prop, [propProxyState]);
              }
            });
          }
        };
        return removeListener;
      };
      var baseObject = Array.isArray(initialObject) ? [] : Object.create(Object.getPrototypeOf(initialObject));
      var handler = {
        deleteProperty: function deleteProperty(target, prop) {
          var prevValue = Reflect.get(target, prop);
          removePropListener(prop);
          var deleted = Reflect.deleteProperty(target, prop);
          if (deleted) {
            notifyUpdate(['delete', [prop], prevValue]);
          }
          return deleted;
        },
        set: function set(target, prop, value, receiver) {
          var hasPrevValue = Reflect.has(target, prop);
          var prevValue = Reflect.get(target, prop, receiver);
          if (hasPrevValue && (objectIs(prevValue, value) || proxyCache.has(value) && objectIs(prevValue, proxyCache.get(value)))) {
            return true;
          }
          removePropListener(prop);
          if (isObject(value)) {
            value = proxyCompare.getUntracked(value) || value;
          }
          var nextValue = value;
          if (value instanceof Promise) {
            value.then(function (v) {
              value.status = 'fulfilled';
              value.value = v;
              notifyUpdate(['resolve', [prop], v]);
            }).catch(function (e) {
              value.status = 'rejected';
              value.reason = e;
              notifyUpdate(['reject', [prop], e]);
            });
          } else {
            if (!proxyStateMap.has(value) && canProxy(value)) {
              nextValue = _proxyFunction(value);
            }
            var childProxyState = !refSet.has(nextValue) && proxyStateMap.get(nextValue);
            if (childProxyState) {
              addPropListener(prop, childProxyState);
            }
          }
          Reflect.set(target, prop, nextValue, receiver);
          notifyUpdate(['set', [prop], value, prevValue]);
          return true;
        }
      };
      var proxyObject = newProxy(baseObject, handler);
      proxyCache.set(initialObject, proxyObject);
      var proxyState = [baseObject, ensureVersion, createSnapshot, addListener];
      proxyStateMap.set(proxyObject, proxyState);
      Reflect.ownKeys(initialObject).forEach(function (key) {
        var desc = Object.getOwnPropertyDescriptor(initialObject, key);
        if ('value' in desc) {
          proxyObject[key] = initialObject[key];
          delete desc.value;
          delete desc.writable;
        }
        Object.defineProperty(baseObject, key, desc);
      });
      return proxyObject;
    };
  }
  return [_proxyFunction, proxyStateMap, refSet, objectIs, newProxy, canProxy, defaultHandlePromise, snapCache, createSnapshot, proxyCache, versionHolder];
};
var _buildProxyFunction = buildProxyFunction(),
  defaultProxyFunction = _buildProxyFunction[0];
function proxy(initialObject) {
  if (initialObject === void 0) {
    initialObject = {};
  }
  return defaultProxyFunction(initialObject);
}
function subscribe(proxyObject, callback, notifyInSync) {
  var proxyState = proxyStateMap.get(proxyObject);
  var promise;
  var ops = [];
  var addListener = proxyState[3];
  var isListenerActive = false;
  var listener = function listener(op) {
    ops.push(op);
    if (notifyInSync) {
      callback(ops.splice(0));
      return;
    }
    if (!promise) {
      promise = Promise.resolve().then(function () {
        promise = undefined;
        if (isListenerActive) {
          callback(ops.splice(0));
        }
      });
    }
  };
  var removeListener = addListener(listener);
  isListenerActive = true;
  return function () {
    isListenerActive = false;
    removeListener();
  };
}
function snapshot(proxyObject, handlePromise) {
  var proxyState = proxyStateMap.get(proxyObject);
  var _ref5 = proxyState,
    target = _ref5[0],
    ensureVersion = _ref5[1],
    createSnapshot = _ref5[2];
  return createSnapshot(target, ensureVersion(), handlePromise);
}
var proxy_1 = proxy;
var snapshot_1 = snapshot;
var subscribe_1 = subscribe;

const o=proxy_1({history:["ConnectWallet"],view:"ConnectWallet",data:void 0}),T={state:o,subscribe(e){return subscribe_1(o,()=>e(o))},push(e,t){e!==o.view&&(o.view=e,t&&(o.data=t),o.history.push(e));},reset(e){o.view=e,o.history=[e];},replace(e){o.history.length>1&&(o.history[o.history.length-1]=e,o.view=e);},goBack(){if(o.history.length>1){o.history.pop();const[e]=o.history.slice(-1);o.view=e;}},setData(e){o.data=e;}},a={WALLETCONNECT_DEEPLINK_CHOICE:"WALLETCONNECT_DEEPLINK_CHOICE",WCM_VERSION:"WCM_VERSION",RECOMMENDED_WALLET_AMOUNT:9,isMobile(){return typeof window<"u"?Boolean(window.matchMedia("(pointer:coarse)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|Opera Mini/u.test(navigator.userAgent)):!1},isAndroid(){return a.isMobile()&&navigator.userAgent.toLowerCase().includes("android")},isIos(){const e=navigator.userAgent.toLowerCase();return a.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(a.isHttpUrl(e))return this.formatUniversalUrl(e,t,s);let n=e;n.includes("://")||(n=e.replaceAll("/","").replaceAll(":",""),n=`${n}://`),n.endsWith("/")||(n=`${n}/`),this.setWalletConnectDeepLink(n,s);const i=encodeURIComponent(t);return `${n}wc?uri=${i}`},formatUniversalUrl(e,t,s){if(!a.isHttpUrl(e))return this.formatNativeUrl(e,t,s);let n=e;n.endsWith("/")||(n=`${n}/`),this.setWalletConnectDeepLink(n,s);const i=encodeURIComponent(t);return `${n}wc?uri=${i}`},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(a.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(a.WALLETCONNECT_DEEPLINK_CHOICE,JSON.stringify({href:t,name:"Android"}));}catch{console.info("Unable to set WalletConnect android deep link");}},removeWalletConnectDeepLink(){try{localStorage.removeItem(a.WALLETCONNECT_DEEPLINK_CHOICE);}catch{console.info("Unable to remove WalletConnect deep link");}},setModalVersionInStorage(){try{typeof localStorage<"u"&&localStorage.setItem(a.WCM_VERSION,"2.6.2");}catch{console.info("Unable to set Web3Modal version in storage");}},getWalletRouterData(){var e;const t=(e=T.state.data)==null?void 0:e.Wallet;if(!t)throw new Error('Missing "Wallet" view data');return t}},_=typeof location<"u"&&(location.hostname.includes("localhost")||location.protocol.includes("https")),r=proxy_1({enabled:_,userSessionId:"",events:[],connectedWalletId:void 0}),R={state:r,subscribe(e){return subscribe_1(r.events,()=>e(snapshot_1(r.events[r.events.length-1])))},initialize(){r.enabled&&typeof(crypto==null?void 0:crypto.randomUUID)<"u"&&(r.userSessionId=crypto.randomUUID());},setConnectedWalletId(e){r.connectedWalletId=e;},click(e){if(r.enabled){const t={type:"CLICK",name:e.name,userSessionId:r.userSessionId,timestamp:Date.now(),data:e};r.events.push(t);}},track(e){if(r.enabled){const t={type:"TRACK",name:e.name,userSessionId:r.userSessionId,timestamp:Date.now(),data:e};r.events.push(t);}},view(e){if(r.enabled){const t={type:"VIEW",name:e.name,userSessionId:r.userSessionId,timestamp:Date.now(),data:e};r.events.push(t);}}},c=proxy_1({chains:void 0,walletConnectUri:void 0,isAuth:!1,isCustomDesktop:!1,isCustomMobile:!1,isDataLoaded:!1,isUiLoaded:!1}),p={state:c,subscribe(e){return subscribe_1(c,()=>e(c))},setChains(e){c.chains=e;},setWalletConnectUri(e){c.walletConnectUri=e;},setIsCustomDesktop(e){c.isCustomDesktop=e;},setIsCustomMobile(e){c.isCustomMobile=e;},setIsDataLoaded(e){c.isDataLoaded=e;},setIsUiLoaded(e){c.isUiLoaded=e;},setIsAuth(e){c.isAuth=e;}},W=proxy_1({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}),y={state:W,subscribe(e){return subscribe_1(W,()=>e(W))},setConfig(e){var t,s;R.initialize(),p.setChains(e.chains),p.setIsAuth(Boolean(e.enableAuthMode)),p.setIsCustomMobile(Boolean((t=e.mobileWallets)==null?void 0:t.length)),p.setIsCustomDesktop(Boolean((s=e.desktopWallets)==null?void 0:s.length)),a.setModalVersionInStorage(),Object.assign(W,e);}};var V=Object.defineProperty,D=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,M=(e,t,s)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,K=(e,t)=>{for(var s in t||(t={}))H.call(t,s)&&M(e,s,t[s]);if(D)for(var s of D(t))B.call(t,s)&&M(e,s,t[s]);return e};const L="https://explorer-api.walletconnect.com",E="wcm",O="js-2.6.2";async function w(e,t){const s=K({sdkType:E,sdkVersion:O},t),n=new URL(e,L);return n.searchParams.append("projectId",y.state.projectId),Object.entries(s).forEach(([i,l])=>{l&&n.searchParams.append(i,String(l));}),(await fetch(n)).json()}const m={async getDesktopListings(e){return w("/w3m/v1/getDesktopListings",e)},async getMobileListings(e){return w("/w3m/v1/getMobileListings",e)},async getInjectedListings(e){return w("/w3m/v1/getInjectedListings",e)},async getAllListings(e){return w("/w3m/v1/getAllListings",e)},getWalletImageUrl(e){return `${L}/w3m/v1/getWalletImage/${e}?projectId=${y.state.projectId}&sdkType=${E}&sdkVersion=${O}`},getAssetImageUrl(e){return `${L}/w3m/v1/getAssetImage/${e}?projectId=${y.state.projectId}&sdkType=${E}&sdkVersion=${O}`}};var z=Object.defineProperty,j=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable,k=(e,t,s)=>t in e?z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,F=(e,t)=>{for(var s in t||(t={}))J.call(t,s)&&k(e,s,t[s]);if(j)for(var s of j(t))q.call(t,s)&&k(e,s,t[s]);return e};const N=a.isMobile(),d$1=proxy_1({wallets:{listings:[],total:0,page:1},search:{listings:[],total:0,page:1},recomendedWallets:[]}),te={state:d$1,async getRecomendedWallets(){const{explorerRecommendedWalletIds:e,explorerExcludedWalletIds:t}=y.state;if(e==="NONE"||t==="ALL"&&!e)return d$1.recomendedWallets;if(a.isArray(e)){const s={recommendedIds:e.join(",")},{listings:n}=await m.getAllListings(s),i=Object.values(n);i.sort((l,v)=>{const b=e.indexOf(l.id),f=e.indexOf(v.id);return b-f}),d$1.recomendedWallets=i;}else {const{chains:s,isAuth:n}=p.state,i=s?.join(","),l=a.isArray(t),v={page:1,sdks:n?"auth_v1":void 0,entries:a.RECOMMENDED_WALLET_AMOUNT,chains:i,version:2,excludedIds:l?t.join(","):void 0},{listings:b}=N?await m.getMobileListings(v):await m.getDesktopListings(v);d$1.recomendedWallets=Object.values(b);}return d$1.recomendedWallets},async getWallets(e){const t=F({},e),{explorerRecommendedWalletIds:s,explorerExcludedWalletIds:n}=y.state,{recomendedWallets:i}=d$1;if(n==="ALL")return d$1.wallets;i.length?t.excludedIds=i.map(x=>x.id).join(","):a.isArray(s)&&(t.excludedIds=s.join(",")),a.isArray(n)&&(t.excludedIds=[t.excludedIds,n].filter(Boolean).join(",")),p.state.isAuth&&(t.sdks="auth_v1");const{page:l,search:v}=e,{listings:b,total:f}=N?await m.getMobileListings(t):await m.getDesktopListings(t),A=Object.values(b),U=v?"search":"wallets";return d$1[U]={listings:[...d$1[U].listings,...A],total:f,page:l??1},{listings:A,total:f}},getWalletImageUrl(e){return m.getWalletImageUrl(e)},getAssetImageUrl(e){return m.getAssetImageUrl(e)},resetSearch(){d$1.search={listings:[],total:0,page:1};}},I=proxy_1({open:!1}),se={state:I,subscribe(e){return subscribe_1(I,()=>e(I))},async open(e){return new Promise(t=>{const{isUiLoaded:s,isDataLoaded:n}=p.state;if(a.removeWalletConnectDeepLink(),p.setWalletConnectUri(e?.uri),p.setChains(e?.chains),T.reset("ConnectWallet"),s&&n)I.open=!0,t();else {const i=setInterval(()=>{const l=p.state;l.isUiLoaded&&l.isDataLoaded&&(clearInterval(i),I.open=!0,t());},200);}})},close(){I.open=!1;}};var G=Object.defineProperty,$=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,S=(e,t,s)=>t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,Y=(e,t)=>{for(var s in t||(t={}))Q.call(t,s)&&S(e,s,t[s]);if($)for(var s of $(t))X.call(t,s)&&S(e,s,t[s]);return e};function Z(){return typeof matchMedia<"u"&&matchMedia("(prefers-color-scheme: dark)").matches}const C=proxy_1({themeMode:Z()?"dark":"light"}),ne={state:C,subscribe(e){return subscribe_1(C,()=>e(C))},setThemeConfig(e){const{themeMode:t,themeVariables:s}=e;t&&(C.themeMode=t),s&&(C.themeVariables=Y({},s));}},g=proxy_1({open:!1,message:"",variant:"success"}),oe={state:g,subscribe(e){return subscribe_1(g,()=>e(g))},openToast(e,t){g.open=!0,g.message=e,g.variant=t;},closeToast(){g.open=!1;}};

class d{constructor(e){this.openModal=se.open,this.closeModal=se.close,this.subscribeModal=se.subscribe,this.setTheme=ne.setThemeConfig,ne.setThemeConfig(e),y.setConfig(e),this.initUi();}async initUi(){if(typeof window<"u"){await import('./index-bbe82299.js');const e=document.createElement("wcm-modal");document.body.insertAdjacentElement("beforeend",e),p.setIsUiLoaded(!0);}}}

const index = /*#__PURE__*/Object.freeze({
  __proto__: null,
  WalletConnectModal: d
});

export { R, T, a, index as i, ne as n, oe as o, p, se as s, te as t, y };

//# sourceMappingURL=index-af949b6a.js.map