import{j as e,av as d,ak as r,T as m,aZ as p,Q as u}from"./vendor-mui-core-DnR6WYuU.js";import{g as x,l as f,h}from"./vendor-hooks-cYMUGE4V.js";import{j as c}from"./vendor-react-CTtPmzVP.js";import{g as j,c as y,k as w,f as C}from"./index-BHa1_Bjz.js";import{V as v}from"./vendor-ux-DfSgTRg5.js";import{C as k}from"./vendor-utils-drLlzTVq.js";import"./vendor-arcblock-CPCSE54a.js";import"./lottie-web-4koyQiv_.js";const M="authorization_response",A=j();function L(){const{t}=v(),[n]=c(),a=()=>{window.close()};return h(()=>{const i=n.get("state"),l=n.get("code"),s={type:M,response:{code:l}};if(window.opener)try{const o=new URL(i);window.opener.postMessage(s,o.origin),setTimeout(()=>{window.close()},2e3)}catch(o){console.error("Invalid login caller",o)}}),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 b(){const{blocklet:t}=window,[n]=c(),a=n.get("error"),i=n.get("error_description"),l=n.get("state"),s=x({errorMesage:"",loading:!0});f(async()=>{if(a)s.errorMesage=i,s.loading=!1;else try{const g=new URL(l);(await A.federated.getTrustedDomains()).includes(g.hostname)||(s.errorMesage="Invalid login caller")}catch{s.errorMesage="Invalid login caller"}finally{s.loading=!1}},[a,i,l]);const o=k(y.WELLKNOWN_SERVICE_PATH_PREFIX,`/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:o,alt:`${t?.appName||"site"} logo`,sx:{width:80}}),e.jsx(m,{variant:"h6",component:"p",children:t?.appName})]}),s.loading?s.errorMesage?e.jsx(w,{error:{message:s.errorMesage}}):e.jsx(L,{}):null,e.jsx(C,{sx:{mt:4}})]})})}export{b as default};
