import{j as o,a6 as w,T as g,s as k,W as l}from"./vendor-mui-core-CKKG_1TN.js";import{r as j}from"./vendor-react-CTtPmzVP.js";import{z as A,n as T}from"./vendor-utils-CUs2ebe7.js";import{u as C}from"./useAsync-D0xh4Var.js";import{V as E,ay as d,b8 as b,W as U}from"./vendor-ux-DjXlxcvL.js";import{u as I,z as M,aC as P,b as S,w as L}from"./index-BEfIUbZC.js";import{o as m}from"./vendor-arcblock-BCP2x3BR.js";import"./useAsync-D6IP8T2e.js";import"./vendor-hooks-DQAdyHrE.js";import"./lottie-web-4koyQiv_.js";function R({children:f,skipBindAccount:i=!1}){const{t:c,locale:y}=E(),{api:u,session:r}=I(),{encryptKey:h,decrypt:x}=M(),s=j.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&&S(x(n.sessionToken));try{await r.refresh()}catch(a){U.error(a.message)}};return!s&&(!t.value||t.loading||r.loading)?o.jsx(m,{relative:"parent",children:o.jsx(w,{})}):!s&&t.error?o.jsx(m,{relative:"parent",children:o.jsx(g,{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:b(),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(P,{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=k(L)`
  .action-info-desc {
    padding: 0 72px;
  }
`;export{R as default};
