import{b as k,j as o,C as N,h as W,t as b,u as U,V as E,z as _,r,v as D,w as d,x,y as P,s as R,A as O,W as A,D as $,E as K,l as V,q}from"./index-DR3HTfO6.js";import{I as z}from"./invitation-CIinv2Of.js";import"./index-6zqs-c3t.js";import"./index-aa4ujRU0.js";import"./emotion-cache.browser.esm-DHWVBIJA.js";import"./sdk-ByxTU3LQ.js";import"./wrap-locale-C0doVwDy.js";import"./index-DxwXPhQP.js";function H(p){const{api:i,session:f}=W(),{info:s}=k(),c=b(),v=U(),{t:l,locale:m}=E(),{encryptKey:y,decrypt:C}=_(),[I,g]=r.useState(!1),h=r.useMemo(()=>new URLSearchParams(c.search).get("inviteId"),[c]),a=D(async()=>{if(!h)return null;let e;const{data:n}=await i.get("/api/invitation",{params:{inviteId:h}}),t=!!d(s,"ownerNft.did")&&n.role.name==="owner";if(t){const u=new URL(window.location.href);u.pathname=x(P(),"/api/did/invite/token"),u.searchParams.set("_ek_",y),u.searchParams.set("inviteId",h);const{data:F}=await i.get(u.href);e=F}return{invitation:n,nextWorkflow:e,needReceiveNFT:t}}),L=r.useCallback(()=>{g(!0)},[]),S=r.useCallback(()=>{if(a.error)throw a.error;return a.value.invitation},[a]),w=r.useCallback(async e=>{e&&(Object.prototype.hasOwnProperty.call(e,"encrypted")&&!e.encrypted?R(e.sessionToken):R(C(e.sessionToken)));const n=new URLSearchParams(c.search);n.delete("inviteId");const t=n.toString();await f.refresh(),v(`/${t&&`?${t}`}`,{replace:!0})},[c,v,f]);if(a.loading)return o.jsx(N,{});const T=()=>{const e=new URL(window.location.href);e.pathname=x(P(),"/api/did/invite/status"),e.searchParams.set("_t_",a.value.nextWorkflow.token),e.searchParams.set("locale",m);const n=setInterval(async()=>{const{data:t}=await i.get(e.href);t.status==="succeed"&&(clearInterval(n),f.updateConnectedInfo(t),w(t))},2e3)},j=()=>{g(!1)};return o.jsxs(M,{className:"page-invite",children:[d(a,"value.needReceiveNFT")&&o.jsx(O,{action:"login",popup:!0,className:"connect",open:I,locale:m,baseUrl:s.launcher.url,checkFn:K.create({baseURL:s.launcher.url}).get,onSuccess:T,onClose:j,checkTimeout:300*1e3,webWalletUrl:$(s),extraParams:{nw:d(a,"value.nextWorkflow.url")},messages:{title:l("invite.transferNFTDialog.title",{name:s.name}),scan:l("invite.transferNFTDialog.scan"),confirm:l("invite.transferNFTDialog.confirm"),success:l("invite.transferNFTDialog.success")},prefix:`${A}/api/did`}),o.jsx(z,{...p,getDataFn:S,createPassportSvg:e=>V(e,s),checkFn:i.get,onLoginSuccess:w,passportColor:"default",onReceive:d(a,"value.needReceiveNFT")?L:null})]})}const M=q.div`
  width: 100vw;
  height: 100%;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f6f8fa;
  overflow: auto;
  padding: 20px;
`;function te(){return k().loading?o.jsx(N,{}):o.jsx(H,{})}export{te as default};
