import{G as K,as as X,u as H,F as J,v as Q,e as h,I as W,j as C,f as p,g as B,h as E,i as Y,r as d,o as $,K as V,w as l,b as v,n as f,t as b,l as e,a,c as x,M as N}from"./main-DYvSVgaj.js";import{u as Z}from"./mail-driver-Ci5A3nxY.js";const ee={class:"flex justify-between w-full"},te={key:0,action:""},ae={class:"px-8 py-8 sm:p-6"},oe={class:"z-0 flex justify-end p-4 border-t border-gray-200 border-solid"},se={key:1},re={class:"my-6 mx-4 border border-gray-200 relative"},le=["src"],ne={class:"z-0 flex justify-end p-4 border-t border-gray-200 border-solid"},me={__name:"SendEstimateModal",emits:["update"],setup(ie,{emit:U}){const m=K(),j=X(),G=H(),S=J();Z();const{t:u}=Q.useI18n(),n=h(!1),I=h(""),y=h(!1),P=h(["customer","customerCustom","estimate","estimateCustom","company"]);let o=W({id:null,from:null,to:null,subject:u("estimates.new_estimate"),body:null});const D=U,F=C(()=>m.active&&m.componentName==="SendEstimateModal"),k=C(()=>m.data),L={from:{required:p.withMessage(u("validation.required"),B),email:p.withMessage(u("validation.email_incorrect"),E)},to:{required:p.withMessage(u("validation.required"),B),email:p.withMessage(u("validation.email_incorrect"),E)},subject:{required:p.withMessage(u("validation.required"),B)},body:{required:p.withMessage(u("validation.required"),B)}},s=Y(L,C(()=>o));function R(){y.value=!1}async function z(){let r=await S.fetchBasicMailConfig();o.id=m.id,r.data&&(o.from=r.data.from_mail),k.value&&(o.to=k.value.customer.email),o.body=S.selectedCompanySettings.estimate_mail_body}async function q(){if(s.value.$touch(),s.value.$invalid)return!0;try{if(n.value=!0,!y.value){const c=await j.previewEstimate(o);n.value=!1,y.value=!0;var r=new Blob([c.data],{type:"text/html"});I.value=URL.createObjectURL(r);return}const t=await j.sendEstimate(o);if(n.value=!1,t.data.success)return D("update"),g(),!0}catch(t){console.error(t),n.value=!1,G.showNotification({type:"error",message:u("estimates.something_went_wrong")})}}function g(){m.closeModal(),setTimeout(()=>{s.value.$reset(),y.value=!1,I.value=null},300)}return(r,t)=>{const c=d("BaseIcon"),M=d("BaseInput"),w=d("BaseInputGroup"),A=d("BaseCustomInput"),O=d("BaseInputGrid"),_=d("BaseButton"),T=d("BaseModal");return $(),V(T,{show:F.value,onClose:g,onOpen:z},{header:l(()=>[v("div",ee,[f(b(e(m).title)+" ",1),a(c,{name:"XIcon",class:"h-6 w-6 text-gray-500 cursor-pointer",onClick:g})])]),default:l(()=>[y.value?($(),x("div",se,[v("div",re,[a(_,{class:"absolute top-4 right-4",disabled:n.value,variant:"primary-outline",onClick:R},{default:l(()=>[a(c,{name:"PencilIcon",class:"h-5 mr-2"}),f(" "+b(r.$t("general.edit")),1)]),_:1},8,["disabled"]),v("iframe",{src:I.value,frameborder:"0",class:"w-full",style:{"min-height":"500px"}},null,8,le)]),v("div",ne,[a(_,{class:"mr-3",variant:"primary-outline",type:"button",onClick:g},{default:l(()=>[f(b(r.$t("general.cancel")),1)]),_:1}),a(_,{loading:n.value,disabled:n.value,variant:"primary",type:"button",onClick:q},{default:l(()=>[n.value?N("",!0):($(),V(c,{key:0,name:"PaperAirplaneIcon",class:"mr-2"})),f(" "+b(r.$t("general.send")),1)]),_:1},8,["loading","disabled"])])])):($(),x("form",te,[v("div",ae,[a(O,{layout:"one-column"},{default:l(()=>[a(w,{label:r.$t("general.from"),required:"",error:e(s).from.$error&&e(s).from.$errors[0].$message},{default:l(()=>[a(M,{modelValue:e(o).from,"onUpdate:modelValue":t[0]||(t[0]=i=>e(o).from=i),type:"text",invalid:e(s).from.$error,onInput:t[1]||(t[1]=i=>e(s).from.$touch())},null,8,["modelValue","invalid"])]),_:1},8,["label","error"]),a(w,{label:r.$t("general.to"),required:"",error:e(s).to.$error&&e(s).to.$errors[0].$message},{default:l(()=>[a(M,{modelValue:e(o).to,"onUpdate:modelValue":t[2]||(t[2]=i=>e(o).to=i),type:"text",invalid:e(s).to.$error,onInput:t[3]||(t[3]=i=>e(s).to.$touch())},null,8,["modelValue","invalid"])]),_:1},8,["label","error"]),a(w,{label:r.$t("general.subject"),required:"",error:e(s).subject.$error&&e(s).subject.$errors[0].$message},{default:l(()=>[a(M,{modelValue:e(o).subject,"onUpdate:modelValue":t[4]||(t[4]=i=>e(o).subject=i),type:"text",invalid:e(s).subject.$error,onInput:t[5]||(t[5]=i=>e(s).subject.$touch())},null,8,["modelValue","invalid"])]),_:1},8,["label","error"]),a(w,{label:r.$t("general.body"),required:""},{default:l(()=>[a(A,{modelValue:e(o).body,"onUpdate:modelValue":t[6]||(t[6]=i=>e(o).body=i),fields:P.value},null,8,["modelValue","fields"])]),_:1},8,["label"])]),_:1})]),v("div",oe,[a(_,{class:"mr-3",variant:"primary-outline",type:"button",onClick:g},{default:l(()=>[f(b(r.$t("general.cancel")),1)]),_:1}),a(_,{loading:n.value,disabled:n.value,variant:"primary",type:"button",class:"mr-3",onClick:q},{default:l(()=>[n.value?N("",!0):($(),V(c,{key:0,name:"PhotographIcon",class:"h-5 mr-2"})),f(" "+b(r.$t("general.preview")),1)]),_:1},8,["loading","disabled"])])]))]),_:1},8,["show"])}}};export{me as _};
