import{aS as T,V as j,r as e,ab as k,x as E,aT as B,j as o,B as w,C as M,W as H}from"./index-DR3HTfO6.js";import{u as I}from"./blocklet-DX83Lnjp.js";import{u as N}from"./use-mobile-C6Z4Z4Vr.js";function v(){const{info:x,inService:g}=T(),{blocklet:y}=I(),{locale:u}=j(),f=e.useRef(null),a=k(),[L,R]=e.useState(0),p=N(),[t,S]=e.useState(!0),s=e.useRef(null);let r="";g?r=H:r=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,r,`/api/theme?id=${encodeURIComponent(y.meta.did)}`));const l=e.useCallback(()=>{if(s.current){const n=B(JSON.parse(JSON.stringify(a)),["palette","typography","shape","direction","breakpoints","mixins","shadows","transitions","zIndex"]);s.current.contentWindow.postMessage({type:"SEND_THEME",payload:n},window.location.origin)}},[a]),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()},[a,t,l]),e.useEffect(()=>{t===!1&&d()},[u,t,d]),e.useEffect(()=>{const n=document.querySelector("#arc__dashboard-main"),i=document.querySelector(".dashboard-content"),h=()=>{if(f.current){const{height:b}=n.getBoundingClientRect(),{top:C}=i.getBoundingClientRect(),{top:_}=f.current.getBoundingClientRect();let m=b-_+C-(p?108:164);p&&(m=Math.min(m,600)),R(m)}};return h(),window.addEventListener("resize",h),()=>{window.removeEventListener("resize",h)}},[p,a]),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(M,{})}),o.jsx("iframe",{title:"Theme Builder",ref:s,src:`${E(window.location.origin,r,"/hosted/theme-builder/")}?${c.toString()}`,style:{border:0,width:"100%",height:`${L}px`,display:t?"none":"block"}})]})}export{v as default};
