import{y as E,x as T}from"./vendor-utils-_C9URqjS.js";import{X as j,V as k,W as M}from"./index-DGZk149v.js";import{r as e}from"./vendor-react-DX7tU9aY.js";import{W as B}from"./vendor-ux-bFYdDLNG.js";import{u as H}from"./use-mobile-CnCzXOEv.js";import{G as I,j as o,al as w,a7 as N}from"./vendor-mui-core-CDEc-eG6.js";import"./vendor-arcblock-DY2miJjh.js";import"./vendor-hooks-BrgYeCrj.js";function z(){const{info:x,inService:g}=j(),{blocklet:y}=k(),{locale:u}=B(),f=e.useRef(null),r=I(),[L,R]=e.useState(0),m=H(),[t,S]=e.useState(!0),s=e.useRef(null);let a="";g?a=M: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=T(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:b}=n.getBoundingClientRect(),{top:C}=i.getBoundingClientRect(),{top:_}=f.current.getBoundingClientRect();let h=b-_+C-(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(N,{})}),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{z as default};
