import{j as o,a6 as g,T as j,s as w,W as l}from"./vendor-mui-core-DnR6WYuU.js";import{r as k}from"./vendor-react-CTtPmzVP.js";import{C as A,n as T}from"./vendor-utils-CxWN1dT3.js";import{u as C}from"./useAsync-DVl73fmG.js";import{V as E,aj as d,as as I,H as M}from"./vendor-ux-DTEmWsko.js";import{u as P,z as S,aF as U,a as b,j as L}from"./index-BZxsCCR_.js";import{o as m}from"./vendor-arcblock-CIBaEWEy.js";import"./useAsync-Dotoxibi.js";import"./vendor-hooks-qxhUUbW5.js";import"./lottie-web-4koyQiv_.js";function R({children:f,skipBindAccount:i=!1}){const{t:c,locale:y}=E(),{api:u,session:r}=P(),{encryptKey:h,decrypt:x}=S(),s=k.useMemo(()=>{if(i||!r.user)return!1;const{sourceProvider:e,connectedAccounts:n=[]}=r.user,a=n.every(v=>v.provider===d.EMAIL);return e===d.EMAIL&&a},[r.user,i]),t=C(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:n}=await u.get(e.href);return n},[s]),p=async e=>{const n=Array.isArray(e)?e.find(a=>a.sessionToken):e;n.sessionToken&&b(x(n.sessionToken));try{await r.refresh()}catch(a){M.error(a.message)}};return!s&&(!t.value||t.loading||r.loading)?o.jsx(m,{relative:"parent",children:o.jsx(g,{})}):!s&&t.error?o.jsx(m,{relative:"parent",children:o.jsx(j,{children:t.error.message})}):r.user&&!s?f:o.jsx(W,{popup:!0,open:!0,hideCloseButton:!0,action:s?"bind-wallet":"pre-setup",checkFn:u.get,checkTimeout:10*60*1e3,webWalletUrl:I(),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?[o.jsx(U,{behavior:"only-new",action:"connect",createMode:"connect",onSuccess:p,onError:T,dense:!0},"passkey")]:[],extraParams:s?{previousUserDid:r.user?.did,visitorId:t.value?.visitorId,skipMigrateAccount:!0,isService:!0}:{setup:!0,nw:t.value.url}})}R.propTypes={children:l.any.isRequired,skipBindAccount:l.bool};const W=w(L)`
  .action-info-desc {
    padding: 0 72px;
  }
`;export{R as default};
