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