import{C as E,A as k}from"./vendor-utils-CxWN1dT3.js";import{Z as T,Y as j,c as M}from"./index-BZxsCCR_.js";import{r as e}from"./vendor-react-CTtPmzVP.js";import{V as B}from"./vendor-ux-DTEmWsko.js";import{u as D}from"./use-mobile-BINJTzMb.js";import{D as H,j as o,ak as w,a6 as I}from"./vendor-mui-core-DnR6WYuU.js";import"./vendor-arcblock-CIBaEWEy.js";import"./vendor-hooks-qxhUUbW5.js";import"./lottie-web-4koyQiv_.js";function K(){const{info:x,inService:g}=T(),{blocklet:y}=j(),{locale:u}=B(),f=e.useRef(null),r=H(),[L,R]=e.useState(0),m=D(),[t,S]=e.useState(!0),s=e.useRef(null);let a="";g?a=M.WELLKNOWN_SERVICE_PATH_PREFIX:a=x.routing.adminPath;const c=new URLSearchParams;g?c.set("appUrl",window.location.origin):c.set("authKey","__sst"),c.set("schemaKey",E(window.location.origin,a,`/api/theme?id=${encodeURIComponent(y.meta.did)}`));const l=e.useCallback(()=>{if(s.current){const n=k(JSON.parse(JSON.stringify(r)),["palette","typography","shape","direction","breakpoints","mixins","shadows","transitions","zIndex"]);s.current.contentWindow.postMessage({type:"SEND_THEME",payload:n},window.location.origin)}},[r]),d=e.useCallback(()=>{s.current&&s.current.contentWindow.postMessage({type:"SEND_LOCALE",payload:u},window.location.origin)},[u]);return e.useEffect(()=>{const n=i=>{i.origin===window.location.origin&&(i.data.type==="REQUEST_THEME"&&l(),i.data.type==="THEME_BUILDER_LOADED"&&(d(),S(!1)))};return window.addEventListener("message",n),()=>{window.removeEventListener("message",n)}},[l,d]),e.useEffect(()=>{t===!1&&l()},[r,t,l]),e.useEffect(()=>{t===!1&&d()},[u,t,d]),e.useEffect(()=>{const n=document.querySelector("#arc__dashboard-main"),i=document.querySelector(".dashboard-content"),p=()=>{if(f.current){const{height:C}=n.getBoundingClientRect(),{top:b}=i.getBoundingClientRect(),{top:_}=f.current.getBoundingClientRect();let h=C-_+b-(m?108:164);m&&(h=Math.min(h,600)),R(h)}};return p(),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",p)}},[m,r]),o.jsxs(o.Fragment,{children:[o.jsx(w,{ref:f}),t&&o.jsx(w,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"500px"},children:o.jsx(I,{})}),o.jsx("iframe",{title:"Theme Builder",ref:s,src:`${E(window.location.origin,a,"/hosted/theme-builder/")}?${c.toString()}`,style:{border:0,width:"100%",height:`${L}px`,display:t?"none":"block"}})]})}export{K as default};
