import{d as h,u as w,B as p,o as n,a as d,f as s,t as a,s as j,v as y,A as k,e as r,F as S,n as E,x as M,j as m,b as V}from"./app-D9-EssCM.js";import{_ as C}from"./EmailTemplateUnlayerEditor.vue_vue_type_script_setup_true_lang-D_CVi-LM.js";const U={key:0,class:"fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50"},B={class:"mx-4 max-h-[90vh] w-full max-w-7xl overflow-y-auto rounded-lg bg-white p-6"},F={class:"mb-4 flex items-center justify-between"},D={class:"text-lg font-semibold text-gray-900"},N={class:"mb-4 grid grid-cols-1 gap-4 md:grid-cols-2"},R=["value"],I={key:0,class:"mt-1 text-sm text-red-600"},A={class:"grid grid-cols-1 gap-4"},T={key:0,class:"mt-1 text-sm text-red-600"},G={key:1,class:"mt-1 text-sm text-red-600"},K={class:"mt-6 flex items-center justify-end gap-3"},L=["disabled"],X="<!-- unlayer-design:",g=" -->",H=h({__name:"EmailComposerModal",props:{open:{type:Boolean},title:{},sendUrl:{},templates:{},previewContext:{}},emits:["close","sent"],setup(f,{emit:x}){const i=f,u=x,t=w({template_id:null,subject:"",body:""}),c=()=>t.errors.message,v=o=>{if(!o?.startsWith(X))return{html:o||""};const e=o.indexOf(g);return e===-1?{html:o||""}:{html:o.slice(e+g.length).replace(/^\n/,"")}};p(()=>i.open,o=>{o&&(t.reset(),t.clearErrors(),t.template_id=null,t.subject="",t.body="")}),p(()=>t.template_id,o=>{if(!o)return;const e=i.templates.find(l=>l.id===o);e&&(t.subject=e.subject||"",t.body=e.html_template||"")});const b=()=>{u("close")},_=()=>{i.sendUrl&&t.transform(o=>({...o,body:v(o.body||"").html})).post(i.sendUrl,{preserveScroll:!0,onSuccess:()=>{u("sent"),u("close")}})};return(o,e)=>o.open?(n(),d("div",U,[s("div",B,[s("div",F,[s("h3",D,a(o.title),1),s("button",{type:"button",class:"text-gray-500 hover:text-gray-700",onClick:b},"Close")]),s("form",{onSubmit:j(_,["prevent"])},[s("div",N,[s("div",null,[e[4]||(e[4]=s("label",{class:"mb-1 block text-sm font-medium text-gray-700"},"Template (optional)",-1)),y(s("select",{"onUpdate:modelValue":e[0]||(e[0]=l=>r(t).template_id=l),class:"w-full rounded border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"},[e[3]||(e[3]=s("option",{value:null},"Manual (no template)",-1)),(n(!0),d(S,null,E(o.templates,l=>(n(),d("option",{key:l.id,value:l.id},a(l.name),9,R))),128))],512),[[k,r(t).template_id]]),e[5]||(e[5]=s("p",{class:"mt-1 text-xs text-gray-500"},"Select a template to prefill subject/body, or compose manually.",-1))]),s("div",null,[e[6]||(e[6]=s("label",{class:"mb-1 block text-sm font-medium text-gray-700"},"Subject",-1)),y(s("input",{"onUpdate:modelValue":e[1]||(e[1]=l=>r(t).subject=l),type:"text",class:"w-full rounded border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500",placeholder:"Email subject",required:""},null,512),[[M,r(t).subject]]),r(t).errors.subject?(n(),d("div",I,a(r(t).errors.subject),1)):m("",!0)])]),s("div",A,[s("div",null,[e[7]||(e[7]=s("label",{class:"mb-1 block text-sm font-medium text-gray-700"},"Body (Visual editor + HTML)",-1)),V(C,{modelValue:r(t).body,"onUpdate:modelValue":e[2]||(e[2]=l=>r(t).body=l),"image-upload-url":"/administration/email-templates/upload-image"},null,8,["modelValue"]),r(t).errors.body?(n(),d("div",T,a(r(t).errors.body),1)):m("",!0),c()?(n(),d("div",G,a(c()),1)):m("",!0)])]),s("div",K,[s("button",{type:"button",onClick:b,class:"rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50"}," Cancel "),s("button",{type:"submit",disabled:r(t).processing,class:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50"},a(r(t).processing?"Sending...":"Send Email"),9,L)])],32)])])):m("",!0)}});export{H as _};
