import{j as n,a6 as g,T as w,s as k,W as l}from"./vendor-mui-core-BPQ6AEW_.js";import{r as j}from"./vendor-react-CUXIiAnY.js";import{C as A,n as E}from"./vendor-utils-BgSaqjGx.js";import{u as I}from"./useAsync-P_Velqz1.js";import{a as R,a8 as T,Y as d,a9 as C,s as P,v as L}from"./index-DY2wgD65.js";import{V as M,s as S,H as U}from"./vendor-ux-r9bApERu.js";import{o as m}from"./vendor-arcblock-D8WYBDYe.js";import"./useAsync-BCC9JxQR.js";import"./vendor-hooks-PN9SWiQm.js";import"./lottie-web-4koyQiv_.js";function b({children:f,skipBindAccount:i=!1}){const{t:c,locale:y}=M(),{api:u,session:r}=R(),{encryptKey:h,decrypt:x}=T(),s=j.useMemo(()=>{if(i||!r.user)return!1;const{sourceProvider:e,connectedAccounts:o=[]}=r.user,a=o.every(v=>v.provider===d.LOGIN_PROVIDER.EMAIL);return e===d.LOGIN_PROVIDER.EMAIL&&a},[r.user,i]),t=I(async()=>{if(s)return null;const e=new URL(window.location.href);e.pathname=A(window?.env?.apiPrefix??"/","/api/did/setup/token"),e.searchParams.set("_ek_",h);const{data:o}=await u.get(e.href);return o},[s]),p=async e=>{const o=Array.isArray(e)?e.find(a=>a.sessionToken):e;o.sessionToken&&P(x(o.sessionToken));try{await r.refresh()}catch(a){U.error(a.message)}};return!s&&(!t.value||t.loading||r.loading)?n.jsx(m,{relative:"parent",children:n.jsx(g,{})}):!s&&t.error?n.jsx(m,{relative:"parent",children:n.jsx(w,{children:t.error.message})}):r.user&&!s?f:n.jsx(O,{popup:!0,open:!0,hideCloseButton:!0,action:s?"bind-wallet":"pre-setup",checkFn:u.get,checkTimeout:10*60*1e3,webWalletUrl:S(),onSuccess:p,locale:y,messages:{title:c("setup.connect.title"),scan:c("setup.connect.scan"),confirm:c("setup.connect.confirm"),success:c("setup.connect.success")},customItems:s?[n.jsx(C,{behavior:"only-new",action:"connect",createMode:"connect",onSuccess:p,onError:E,dense:!0},"passkey")]:[],extraParams:s?{previousUserDid:r.user?.did,visitorId:t.value?.visitorId,skipMigrateAccount:!0,isService:!0}:{setup:!0,nw:t.value.url}})}b.propTypes={children:l.any.isRequired,skipBindAccount:l.bool};const O=k(L)`
  .action-info-desc {
    padding: 0 72px;
  }
`;export{b as default};
