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