import{h as a,v as g,j as b,e as d,o as u,b as h,d as s,x as _}from"./vue.esm-bundler.js?ver=1.6.0";import{u as E}from"./useElementor.js?ver=1.6.0";import"./ServerSidePreview.vue_vue_type_style_index_0_scoped_42048dbb_lang.js?ver=1.6.0";import{_ as k}from"./_plugin-vue_export-helper.js?ver=1.6.0";import{a as L}from"./add-query-args.js?ver=1.6.0";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 t=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(t.value&&t.value.contentWindow)try{t.value.contentWindow.postMessage({type:"UPDATE_ATTRIBUTES",attributes:e,block:n.block},window.location.origin)}catch{await v()}},v=async()=>{if(!t.value)return;r.value=!0;const e=await w();t.value.src=l(),await new Promise(o=>{const i=()=>{t.value.removeEventListener("load",i),o()};t.value.addEventListener("load",i)}),e&&await y(e),r.value=!1},w=async()=>{var e;try{if((e=t.value)!=null&&e.contentWindow)return{scrollTop:t.value.contentDocument.documentElement.scrollTop,scrollLeft:t.value.contentDocument.documentElement.scrollLeft}}catch{return null}},y=async e=>{var o;try{await _(),(o=t.value)!=null&&o.contentWindow&&e&&t.value.contentWindow.scrollTo(e.scrollLeft,e.scrollTop)}catch{}};g(()=>n.attributes,async(e,o)=>{JSON.stringify(e)!==JSON.stringify(o)&&(p.value={...e},await m(e))},{deep:!0});const c=e=>{e.origin===window.location.origin&&(e.data.type==="IFRAME_READY"||e.data.type==="UPDATE_COMPLETE"&&(r.value=!1))};return typeof window<"u"&&window.addEventListener("message",c),b(()=>{typeof window<"u"&&window.removeEventListener("message",c)}),(e,o)=>(u(),d("div",S,[r.value?(u(),d("div",T,o[0]||(o[0]=[s("div",null,"Loading...",-1)]))):h("",!0),s("iframe",{class:"nuhel",ref_key:"iframeRef",ref:t,src:l(),style:{width:"100%",height:"100%",border:"none",transition:"opacity 0.3s ease"}},null,8,x),o[1]||(o[1]=s("div",{style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",cursor:"pointer",background:"transparent","z-index":"10"}},null,-1))]))}},M=k(P,[["__scopeId","data-v-42048dbb"]]);export{M as S};
