import{G as S,j as e,R as E,ci as P,bg as R,al as r,T as c,a7 as _}from"./vendor-mui-core-CDEc-eG6.js";import{u as U,s as W,W as I,U as p,i as L,aU as N}from"./index-CgSpL7jz.js";import{o as A}from"./vendor-arcblock-BVQTtbN-.js";import{bj as T}from"./vendor-ux-PO0jFgJf.js";import{i as z,b as j}from"./vendor-hooks-Ca2cSNuD.js";import{u as D,r as i,j as F}from"./vendor-react-DX7tU9aY.js";import{K as a}from"./landing-page-BvgQ3gcP.js";import{y as K}from"./vendor-utils-_C9URqjS.js";import{u as M}from"./use-window-close-2AAHFroZ.js";import"./use-blocklet-logo-nVOJALp0.js";function Z(){const m=D(),l=i.useRef(null),{t:s,locale:d}=i.useContext(T),{api:x,connectApi:f}=U(),[h]=F(),w=S(),b=M(),n=z({ready:!1,success:!1,error:null,invalidSession:!1}),k=()=>{try{const o=new URL(window.location.href);if(o.hash.includes("invalid")){n.invalidSession=!0;return}const u=o.searchParams.get("__connect_url__"),v=L(u);if(!N(v))throw new Error("No token");n.ready=!0}catch{n.invalidSession=!0,m("#invalid",{replace:!0})}};i.useLayoutEffect(()=>k(),[]);const C=j(o=>{n.error=o.message,window.opener?.postMessage({type:"connect-endpoint-message",error:n.error},"*"),m("#invalid",{replace:!0})}),y=j(()=>{window.opener?.postMessage({type:"connect-endpoint-message",success:!0},"*"),n.success=!0}),t=h.get("source")||"Generate Access Key";i.useEffect(()=>{l.current&&n.ready&&f.open({locale:d,containerEl:l.current,action:"gen-access-key",extraParams:{remark:t},checkFn:x.get,saveConnect:!1,forceConnected:!1,className:"connect",popup:!1,baseUrl:window.location.origin,prefix:K(window.location.origin,I,W),messages:{title:s("connectCli.title"),scan:s("connectCli.scan"),confirm:s("auth.confirm"),success:s("connectCli.success")},onSuccess:y,onError:C},{locale:d})},[f,n.ready,x,C,y,d,s,t]);const g=e.jsx(E,{variant:"outlined",color:"primary",size:"small",startIcon:e.jsx(P,{}),href:"/",style:{borderRadius:4},children:s("connectCli.home")});if(n.invalidSession)return e.jsx(a,{did:window.blocklet?.appPid,standalone:!0,children:e.jsx(p,{style:{backgroundColor:"transparent"},status:"error",title:s("connectCli.invalidSession"),description:s("connectCli.invalidSessionDesc"),extra:g})},"invalid");if(n.error){const o=n.error,u=g;return e.jsx(a,{did:window.blocklet?.appPid,standalone:!0,children:e.jsx(p,{style:{backgroundColor:"transparent"},status:"error",title:s("connectCli.connectionError"),description:o,extra:u})},"error")}return n.success?(h.has("closeOnSuccess")&&b(),e.jsx(a,{did:window.blocklet?.appPid,standalone:!0,children:e.jsx(p,{style:{backgroundColor:"transparent"},status:"info",icon:e.jsx(R,{style:{color:w.palette.success.main,fontSize:72}}),title:s("connectCli.success",{source:t}),description:`${s("connectCli.successDesc",{source:t})} ${s("connectCli.upload")}`})},"success")):n.ready?e.jsx(a,{did:window.blocklet?.appPid,standalone:!0,children:e.jsxs(r,{sx:{maxWidth:"100%",height:"100%"},children:[e.jsxs(r,{sx:{mb:5},children:[e.jsx(c,{variant:"h4",component:"h1",sx:{mb:1,fontWeight:"bold",textAlign:"center"},children:s("connectCli.tips.title")}),e.jsxs(r,{sx:{display:"flex",flexDirection:"column",gap:1,alignItems:"center"},children:[e.jsx(c,{sx:{color:"text.secondary"},children:s("connectCli.tips.item1")}),e.jsx(c,{sx:{color:"text.secondary"},children:s("connectCli.tips.item2")}),e.jsx(c,{sx:{color:"text.secondary"},children:s("connectCli.tips.item3")})]})]}),e.jsx(r,{sx:{display:"inline-block"},ref:l})]})},"ready"):e.jsx(A,{children:e.jsx(_,{})})}export{Z as default};
