import{i as a,p as g,k as h,c as d,o as u,e as b,f as s,q as _}from"./vue.esm-bundler-DZdE0M9V.js";import{u as E}from"./useElementor-CLTCC9L5.js";/* empty css                                                                          */import{_ as k}from"./_plugin-vue_export-helper-DlAUqK2U.js";import{a as L}from"./add-query-args-COp5A_Oq.js";const S={style:{position:"relative",width:"100%",height:"600px"}},T={key:0,style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",background:"rgba(255, 255, 255, 0.8)",display:"flex","align-items":"center","justify-content":"center","z-index":"20"}},x=["src"],P={__name:"ServerSidePreview",props:{block:{type:String,required:!0},attributes:{type:Object,required:!0}},setup(f){const n=f;E();const o=a(null),r=a(!1),p=a({...n.attributes}),l=(e=n.attributes)=>window.location.origin+L("",{"fluent-cart":"block-render",block:n.block,context:"edit",attributes:e}),m=async e=>{if(o.value&&o.value.contentWindow)try{o.value.contentWindow.postMessage({type:"UPDATE_ATTRIBUTES",attributes:e,block:n.block},window.location.origin)}catch(t){console.error("Failed to update iframe via postMessage:",t),await v()}},v=async()=>{if(!o.value)return;r.value=!0;const e=await w();o.value.src=l(),await new Promise(t=>{const i=()=>{o.value.removeEventListener("load",i),t()};o.value.addEventListener("load",i)}),e&&await y(e),r.value=!1},w=async()=>{var e;try{if((e=o.value)!=null&&e.contentWindow)return{scrollTop:o.value.contentDocument.documentElement.scrollTop,scrollLeft:o.value.contentDocument.documentElement.scrollLeft}}catch{return null}},y=async e=>{var t;try{await _(),(t=o.value)!=null&&t.contentWindow&&e&&o.value.contentWindow.scrollTo(e.scrollLeft,e.scrollTop)}catch{}};g(()=>n.attributes,async(e,t)=>{JSON.stringify(e)!==JSON.stringify(t)&&(p.value={...e},await m(e))},{deep:!0});const c=e=>{e.origin===window.location.origin&&(e.data.type==="IFRAME_READY"?console.log("Iframe ready"):e.data.type==="UPDATE_COMPLETE"&&(r.value=!1))};return typeof window<"u"&&window.addEventListener("message",c),h(()=>{typeof window<"u"&&window.removeEventListener("message",c)}),(e,t)=>(u(),d("div",S,[r.value?(u(),d("div",T,t[0]||(t[0]=[s("div",null,"Loading...",-1)]))):b("",!0),s("iframe",{class:"nuhel",ref_key:"iframeRef",ref:o,src:l(),style:{width:"100%",height:"100%",border:"none",transition:"opacity 0.3s ease"}},null,8,x),t[1]||(t[1]=s("div",{style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",cursor:"pointer",background:"transparent","z-index":"10"}},null,-1))]))}},B=k(P,[["__scopeId","data-v-e73ce754"]]);export{B as S};
