import{j as e,aS as d,al as r,T as m,b4 as p,R as u}from"./vendor-mui-core-CDEc-eG6.js";import{i as x,p as f,j as h}from"./vendor-hooks-BrgYeCrj.js";import{j as c}from"./vendor-react-DX7tU9aY.js";import{W as j,g as y,h as w}from"./index-DGZk149v.js";import{k as C}from"./fallback-DtbVvsNl.js";import{W as v}from"./vendor-ux-bFYdDLNG.js";import{y as M}from"./vendor-utils-_C9URqjS.js";import"./vendor-arcblock-DY2miJjh.js";const k="authorization_response",A=w();function L(){const{t}=v(),[o]=c(),a=()=>{window.close()};return h(()=>{const i=o.get("state"),l=o.get("code"),s={type:k,response:{code:l}};if(window.opener)try{const n=new URL(i);window.opener.postMessage(s,n.origin),setTimeout(()=>{window.close()},2e3)}catch(n){console.error("Invalid login caller",n)}}),e.jsx(p,{severity:"success",children:e.jsxs(r,{sx:{display:"flex",flexDirection:"column",justifyContent:"center",alignContent:"center",gap:1},children:[t("login.needManualClose"),e.jsx(r,{sx:{textAlign:"center"},children:e.jsx(u,{variant:"outlined",size:"small",onClick:a,children:t("login.closeWindow")})})]})})}function W(){const{blocklet:t}=window,[o]=c(),a=o.get("error"),i=o.get("error_description"),l=o.get("state"),s=x({errorMessage:"",loading:!0});f(async()=>{if(a)s.errorMessage=i,s.loading=!1;else try{const g=new URL(l);(await A.federated.getTrustedDomains()).includes(g.hostname)||(s.errorMessage="Invalid login caller",s.loading=!1)}catch{s.errorMessage="Invalid login caller",s.loading=!1}},[a,i,l]);const n=M(j,`/blocklet/logo?&version=${t?.meta?.version||""}`);return e.jsx(d,{sx:{display:"flex",flexDirection:"column",minHeight:"100vh",justifyContent:"center",alignContent:"center"},children:e.jsxs(r,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,minHeight:"100vh",margin:"auto",paddingBottom:{sx:0,md:15}},children:[e.jsxs(r,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:.5},children:[e.jsx(r,{component:"img",src:n,alt:`${t?.appName||"site"} logo`,sx:{width:80}}),e.jsx(m,{variant:"h6",component:"p",children:t?.appName})]}),s.loading?s.errorMessage?e.jsx(C,{error:{message:s.errorMessage}}):e.jsx(L,{}):null,e.jsx(y,{sx:{mt:4}})]})})}export{W as default};
