import{u as k,j as o,C as y,az as b,c_ as U,A as W,V as _,cO as E,r,aY as D,h as d,y as x,am as P,ag as R,w as O,aI as A,x as $,ay as z,bD as K,s as V}from"./index-Y-QvttbJ.js";import{I as H}from"./invitation--cbaLA7C.js";import"./index-RvLFbIq0.js";import"./index-BJDBjriy.js";import"./emotion-cache.browser.esm-CaLvcLFC.js";import"./sdk-vbwSpYyc.js";import"./wrap-locale-D8L6OQkL.js";import"./index-B9IBU_20.js";function M(h){const{api:i,session:p}=b(),{info:s}=k(),c=U(),v=W(),{t:l,locale:m}=_(),{encryptKey:N,decrypt:C}=E(),[I,g]=r.useState(!1),f=r.useMemo(()=>new URLSearchParams(c.search).get("inviteId"),[c]),a=D(async()=>{if(!f)return null;let e;const{data:n}=await i.get("/api/invitation",{params:{inviteId:f}}),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_",N),u.searchParams.set("inviteId",f);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 p.refresh(),v(`/${t&&`?${t}`}`,{replace:!0})},[c,v,p]);if(a.loading)return o.jsx(y,{});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),p.updateConnectedInfo(t),w(t))},2e3)},j=()=>{g(!1)};return o.jsxs(X,{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:z.create({baseURL:s.launcher.url}).get,onSuccess:T,onClose:j,checkTimeout:5*60*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.WELLKNOWN_SERVICE_PATH_PREFIX}/api/did`}),o.jsx(H,{...h,getDataFn:S,createPassportSvg:e=>K(e,s),checkFn:i.get,onLoginSuccess:w,passportColor:"default",onReceive:d(a,"value.needReceiveNFT")?L:null})]})}const X=V.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(y,{}):o.jsx(M,{})}export{te as default};
