import{j as n,a7 as w,T as g,s as k,X as l}from"./vendor-mui-core-D7t4vMS5.js";import{r as j}from"./vendor-react-DX7tU9aY.js";import{z as A,n as T}from"./vendor-utils-BzQg432x.js";import{u as E}from"./useAsync-CkKfnulP.js";import{W as b,ar as m,b2 as C,Q as U}from"./vendor-ux-Dl3wVbv_.js";import{u as I,z as M,b as P,w as S}from"./index-Ca33rdd_.js";import{o as d}from"./vendor-arcblock-ivFYo5vP.js";import{U as L}from"./actions-Ng-YRTer.js";import"./useAsync-DfiOQMQ_.js";import"./vendor-hooks-DAZ1H6Va.js";import"./passkey-rounded-_WDHIZVd.js";import"./login-method-item-KhJ672kA.js";import"./isEmail-BwGDo3Ws.js";import"./isIP-BBY240SU.js";function R({children:f,skipBindAccount:a=!1}){const{t:c,locale:y}=b(),{api:u,session:s}=I(),{encryptKey:h,decrypt:x}=M(),r=j.useMemo(()=>{if(a||!s.user)return!1;const{sourceProvider:e,connectedAccounts:o=[]}=s.user,i=o.every(v=>v.provider===m.EMAIL);return e===m.EMAIL&&i},[s.user,a]),t=E(async()=>{if(r)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},[r]),p=async e=>{const o=Array.isArray(e)?e.find(i=>i.sessionToken):e;o.sessionToken&&P(x(o.sessionToken));try{await s.refresh()}catch(i){U.error(i.message)}};return!r&&(!t.value||t.loading||s.loading)?n.jsx(d,{relative:"parent",children:n.jsx(w,{})}):!r&&t.error?n.jsx(d,{relative:"parent",children:n.jsx(g,{children:t.error.message})}):s.user&&!r?f:n.jsx(W,{popup:!0,open:!0,hideCloseButton:!0,action:r?"bind-wallet":"pre-setup",checkFn:u.get,checkTimeout:600*1e3,webWalletUrl:C(),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:r?[n.jsx(L,{behavior:"only-new",action:"connect",createMode:"connect",onSuccess:p,onError:T,dense:!0},"passkey")]:[],extraParams:r?{previousUserDid:s.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(S)`
  .action-info-desc {
    padding: 0 72px;
  }
`;export{R as default};
