import{useState as e,useEffect as t,createContext as r,useContext as o,useMemo as i,useCallback as n}from"react";import{styled as a,css as l}from"styled-components";import{jsx as s,jsxs as c}from"react/jsx-runtime";import{toHex as d}from"viem/utils";import{f as p,c as u,s as f}from"./wallet-connect-58EobR5U.mjs";import{u as m}from"./context-BKnOUECq.mjs";import{u as h}from"./events-context-BJ75xIIf.mjs";import{u as g}from"./internal-context-dfitw7Ot.mjs";import{P as v}from"./privy-context-Bi6vqCPc.mjs";import{d as y}from"./index-BtwxknTg.mjs";import{u as b}from"./get-entropy-details-for-user-BIWg0YxF.mjs";import{create as x}from"zustand";const w=r=>{let[o,i]=e("auto");return t((()=>{let e=new ResizeObserver((e=>{i(e[0]?.contentRect.height??"auto")}));return r.current&&e.observe(r.current),()=>{r.current&&e.unobserve(r.current)}}),[r.current]),o},k=a.div`
  text-align: left;
  flex-grow: 1;
`,$=a.div`
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  flex-grow: 1;
`,S=a.div`
  display: flex;
  flex-direction: column;
  gap: 8px;

  /* for Internet Explorer, Edge */
  -ms-overflow-style: none;

  /* for Firefox */
  scrollbar-width: none;

  /* for Chrome, Safari, and Opera */
  &::-webkit-scrollbar {
    display: none;
  }
`,C=a(S)`
  ${e=>"light"===e.$colorScheme?"background: linear-gradient(var(--privy-color-background), var(--privy-color-background) 70%) bottom, linear-gradient(rgba(0, 0, 0, 0) 20%, rgba(0, 0, 0, 0.06)) bottom;":"dark"===e.$colorScheme?"background: linear-gradient(var(--privy-color-background), var(--privy-color-background) 70%) bottom, linear-gradient(rgba(255, 255, 255, 0) 20%, rgba(255, 255, 255, 0.06)) bottom;":void 0}

  background-repeat: no-repeat;
  background-size:
    100% 32px,
    100% 16px;
  background-attachment: local, scroll;
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 3px;
`;let T=l`
  && {
    width: 100%;
    font-size: 16px;
    line-height: 24px;
    min-height: 56px;

    /* Tablet and Up */
    @media (min-width: 440px) {
      font-size: 14px;
    }

    display: flex;
    gap: 12px;
    align-items: center;
    color: var(--privy-color-foreground);

    padding: 10px 12px;
    border: 1px solid var(--privy-color-foreground-4) !important;
    border-radius: var(--privy-border-radius-md);
    transition: background-color 200ms ease;

    cursor: pointer;

    &:hover {
      background-color: var(--privy-color-background-2);
    }

    &:disabled {
      cursor: pointer;
      background-color: var(--privy-color-background-2);
    }
  }
`;const z=a.div`
  text-align: center;
  font-size: 14px;
  margin-bottom: 24px;
`,j=a.button.attrs({className:"login-method-button"})`
  ${T}
`;a.a`
  ${T}
`;const I=a.div`
  width: 32px;
  height: 32px;
  border-radius: ${e=>e.$fullSize?"0":"4px"};
  background: ${e=>e.$fullSize?"transparent":"var(--privy-color-background-2)"};
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;

  svg {
    width: ${e=>e.$fullSize?"32px":"18px"};
    height: ${e=>e.$fullSize?"32px":"18px"};
    color: ${e=>e.$fullSize?"inherit":"var(--privy-color-icon-muted)"};
  }
`,O=a.div`
  width: 100%;
  height: 100%;
  min-height: inherit;
  display: flex;
  flex-direction: column;
  ${e=>e.$if?"display: none;":""}
`,W=a.div`
  width: 100%;
  height: 100%;
  padding: ${e=>e.$withPadding?"64px 0px":"0px"};
`,M=a.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
  gap: 12px;
  & h3 {
    font-size: 18px;
    font-style: normal;
    font-weight: 600;
    line-height: 24px;
  }
  & p {
    max-width: 300px;
    font-size: 14px;
    font-style: normal;
    font-weight: 400;
    line-height: 20px;
  }
`,A=({success:e,fail:t})=>/*#__PURE__*/c(N,{children:[/*#__PURE__*/s(E,{children:/*#__PURE__*/s(R,{className:e?"success":t?"fail":""})}),/*#__PURE__*/s(E,{children:/*#__PURE__*/s(P,{className:e?"success":t?"fail":""})})]});let E=a.span`
  && {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
  }
`,N=a.span`
  position: relative;
  width: 82px;
  height: 82px;
  display: inline-block;
`;const P=a.span`
  && {
    width: 82px;
    height: 82px;
    border-width: 4px;
    border-style: solid;
    border-color: ${e=>e.color??"var(--privy-color-icon-subtle)"};
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1.2s linear infinite;
    transition: border-color 800ms;
  }

  @keyframes rotation {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }

  &&&.success {
    border-color: var(--privy-color-icon-success);
    border-bottom-color: var(--privy-color-icon-success);
  }

  &&&.fail {
    border-color: var(--privy-color-icon-error);
    border-bottom-color: var(--privy-color-icon-error);
  }
`,R=a(P)`
  && {
    border-bottom-color: ${e=>e.color??"var(--privy-color-border-default)"};
    border-color: ${e=>e.color??"var(--privy-color-border-default)"};
    animation: none;
    opacity: 0.5;
  }
`,_=e=>/*#__PURE__*/s(L,{color:e.color||"var(--privy-color-foreground-3)"});let L=a(P)`
  && {
    height: 1rem;
    width: 1rem;
    margin: 2px 0;
    border-width: 1.5px;

    /* Override default Loader to match button transitions */
    transition: border-color 200ms ease;
  }
`;async function U(e,t,r){if(!t.shouldEnforceDefaultChainOnConnect)return;let o=Number(e.chainId.replace("eip155:",""));if(!t.chains.find((e=>e.id===o))&&("wallet_connect_v2"!==e.connectorType||"metamask"!==e.walletClientType)){r?.();try{await e.switchChain(t.defaultChain.id),e.chainId=p(d(t.defaultChain.id))}catch{u.warn("Unable to switch to default chain after connect",{chainId:t.defaultChain.id})}}}let q=/*#__PURE__*/r({});const B=({children:r})=>{let o=m(),[i,n]=e({});return h("login",{onComplete:({loginAccount:e})=>{e&&"passkey"!==e.type&&"cross_app"!==e.type&&("wallet"!==e.type||"privy"!==e.walletClientType)&&(f.put(D(o.id),e.type),"wallet"===e.type?(f.put(F(o.id),e.walletClientType),f.put(G(o.id),e.chainType),n({accountType:e.type,walletClientType:e.walletClientType,chainType:e.chainType})):(f.del(F(o.id)),f.del(G(o.id)),n({accountType:e.type})))}}),t((()=>{if(!o.id)return;let e=f.get(D(o.id)),t=f.get(F(o.id)),r=f.get(G(o.id));e&&n("wallet"===e?{accountType:e,walletClientType:t,chainType:r}:{accountType:e})}),[o.id]),/*#__PURE__*/s(q.Provider,{value:i,children:r})};let D=e=>`privy:${e}:recent-login-method`,F=e=>`privy:${e}:recent-login-wallet-client`,G=e=>`privy:${e}:recent-login-chain-type`;const H=()=>o(q),J=e=>{h("fundWallet",e);let{fundWallet:t}=g();return{fundWallet:({address:e,options:r})=>t(e,r)}};function K(e){let{login:t}=o(v);return h("login",e),{login:t}}function Q(e){let{logout:t}=o(v);return h("logout",e),{logout:t}}function V(e){let{connectWallet:t}=o(v);return h("connectWallet",e),{connectWallet:t}}const X=x((()=>({isModalOpen:!1,resolvers:null})));let Y=x((()=>({})));const Z=(e,t)=>Y((r=>r[e]?.[t])),ee=(e,t,r)=>{Y.setState((o=>({[e]:{...o[e],[t]:r}})))},te=async()=>{let e,t,r=new Promise(((r,o)=>{e=r,t=o}));return Y.setState({}),X.setState({isModalOpen:!0,resolvers:{resolve:e,reject:t}}),await r},re=()=>{let e=X.getState().resolvers;e||console.warn("useActiveWalletStore: Called close while modal was not open"),X.setState({isModalOpen:!1}),e?.resolve({wallet:X.getState().wallet})},oe=({address:e,client:t,appId:r})=>{let o=`${t}:${e}`;r&&f.put(ne(r),o),X.setState({wallet:o})},ie=()=>X((e=>e.isModalOpen)),ne=e=>`privy:${e}:active-wallet-connection`,ae=()=>{let e=m(),{wallets:r}=b(),{connectors:o}=g(),a=i((()=>o.filter(y).flatMap((e=>e.wallets))),[o]),l=X((e=>e.wallet));t((()=>{if(!e.id)return;let t=f.get(ne(e.id));X.setState({wallet:t})}),[e.id]);let s=i((()=>{if(!l)return;let[,e]=l.split(":");return r.find((t=>t.address===e))||a.find((t=>t.address===e))}),[l,r,a]),c=i((()=>s?"ethereum"===s.type?s.chainId:"solana":void 0),[s]);return{connect:async t=>{t?.reset&&(f.del(ne(e.id)),X.setState({wallet:void 0}));let{wallet:o}=await te();if(!o)return{};let[,i]=o.split(":"),n=r.find((e=>e.address===i));if(n)return{wallet:n,network:n.chainId};let l=a.find((e=>e.address===i));return l?{wallet:l,network:"solana"}:{}},setActiveWallet:n((t=>{oe({address:t.address,client:t.walletClientType,appId:e.id})}),[e.id]),wallet:s,network:c}};export{$ as A,_ as B,A as C,W as E,k as G,O as H,P as L,B as R,z as S,J as a,ae as b,V as c,K as d,U as e,Q as f,H as g,Z as h,ee as i,ie as j,re as k,j as l,I as m,M as n,C as o,R as p,S as q,oe as s,w as u};
//# sourceMappingURL=useActiveWallet-BEfvREjE.mjs.map
