const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vue-email-editor.es-bus-lhNf.js","assets/app-D9-EssCM.js","assets/app-C_9NxaTF.css"])))=>i.map(i=>d[i]);
import{d as I,r as o,m as V,B as _,K as S,o as a,a as i,f as d,q as w,j as H,g as N,a1 as $,e as A,v as O,x as j,am as B,an as X}from"./app-D9-EssCM.js";import{g as K}from"./AppLayout.vue_vue_type_script_setup_true_lang-C-UlPCqH.js";const P={class:"space-y-3"},W={class:"flex items-center gap-2"},q={key:0,class:"h-[680px] overflow-hidden rounded-md border border-gray-200"},G={key:1,class:"flex h-[680px] items-center justify-center text-sm text-gray-500"},J={key:2,class:"flex h-[680px] flex-col items-center justify-center gap-2 p-6 text-center text-sm text-gray-600"},z={key:1},v="<!-- unlayer-design:",y=" -->",te=I({__name:"EmailTemplateUnlayerEditor",props:{modelValue:{},imageUploadUrl:{}},emits:["update:modelValue"],setup(k,{emit:R}){const C=B({loader:async()=>{const e=await X(()=>import("./vue-email-editor.es-bus-lhNf.js"),__vite__mapDeps([0,1,2]));return e.default??e.EmailEditor??e},suspensible:!1}),h=k,x=R,m=o(!1),n=o("designer"),u=o(null),g=o(!1),f=o(!1),c=o(""),p=o(null),D=V(()=>h.imageUploadUrl||"/administration/email-templates/upload-image"),M=(e,t)=>{const r=encodeURIComponent(JSON.stringify(e));return`${v}${r}${y}
${t}`},F=e=>{if(!e?.startsWith(v))return{design:null,html:e||""};const t=e.indexOf(y);if(t===-1)return{design:null,html:e||""};const r=e.slice(v.length,t).trim(),s=e.slice(t+y.length).replace(/^\n/,"");try{const l=decodeURIComponent(r);return{design:JSON.parse(l),html:s}}catch{return{design:null,html:e||""}}},b=()=>{const e=u.value?.editor;!e||!g.value||e.exportHtml(t=>{c.value=t.html||"",x("update:modelValue",M(t.design||{},t.html||""))})},T=e=>{if(!e||typeof e!="object")return null;const t=e.file;if(t instanceof File)return t;const r=e.attachments;if(Array.isArray(r)){const s=r.find(l=>l instanceof File);if(s instanceof File)return s}return null},U=()=>{const e=u.value?.editor;e?.registerCallback&&e.registerCallback("image",async(t,r)=>{const s=T(t);if(!s){r({progress:100,url:""});return}try{const l=new FormData;l.append("image",s);const L=(await(await fetch(D.value,{method:"POST",headers:{"X-CSRF-TOKEN":K(),"X-Requested-With":"XMLHttpRequest"},body:l})).json())?.data?.[0]?.src||"";r({progress:100,url:L})}catch{r({progress:100,url:""})}})},E=()=>{g.value=!0,f.value=!1,U();const e=u.value?.editor;e&&(p.value&&e.loadDesign(p.value),e.addEventListener("design:updated",()=>{b()}))};return _(()=>h.modelValue,e=>{const t=F(e||"");p.value=t.design,c.value=t.html;const r=u.value?.editor;g.value&&r&&t.design&&r.loadDesign(t.design)},{immediate:!0}),_(()=>c.value,e=>{n.value==="html"&&x("update:modelValue",e||"")}),S(()=>{m.value=!0}),(e,t)=>(a(),i("div",P,[d("div",W,[d("button",{type:"button",onClick:t[0]||(t[0]=r=>n.value="designer"),class:w(["rounded-md px-3 py-1.5 text-xs font-medium",n.value==="designer"?"bg-blue-600 text-white":"border border-gray-300 bg-white text-gray-700"])}," Designer ",2),d("button",{type:"button",onClick:t[1]||(t[1]=r=>n.value="html"),class:w(["rounded-md px-3 py-1.5 text-xs font-medium",n.value==="html"?"bg-blue-600 text-white":"border border-gray-300 bg-white text-gray-700"])}," Manual HTML ",2),n.value==="designer"?(a(),i("button",{key:0,type:"button",onClick:b,class:"rounded-md border border-gray-300 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-gray-50"}," Sync Designer HTML ")):H("",!0)]),n.value==="designer"?(a(),i("div",q,[m.value&&!f.value?(a(),N($(A(C)),{key:0,ref_key:"emailEditorRef",ref:u,"min-height":680,class:"h-full",onLoad:E,onReady:E,onError:t[2]||(t[2]=r=>f.value=!0)},null,544)):m.value?(a(),i("div",J,[...t[4]||(t[4]=[d("p",null,"Email designer failed to load.",-1),d("p",{class:"text-xs text-gray-500"},"You can continue using the Manual HTML tab while we retry.",-1)])])):(a(),i("div",G,"Loading editor..."))])):(a(),i("div",z,[O(d("textarea",{"onUpdate:modelValue":t[3]||(t[3]=r=>c.value=r),rows:"24",class:"w-full rounded-md border-gray-300 font-mono text-sm shadow-sm focus:border-blue-500 focus:ring-blue-500",placeholder:"<p>Write your email HTML here...</p>"},null,512),[[j,c.value]])]))]))}});export{te as _};
