import{F as J,E as K,u as X,aq as Q,v as W,f as I,H as Y,k as B,g as v,h,i as N,j as Z,r as c,o as _,m as V,w as n,b as p,p as f,t as $,a,c as x,l as e,J as ee,K as U}from"./main-B9dpPbRR.js";import{u as oe}from"./mail-driver-L7_iQECX.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:P}){const u=J(),j=K(),D=X(),k=Q();oe();const{t:d}=W.useI18n();let i=I(!1);const C=I(""),b=I(!1),F=P,G=I(["customer","customerCustom","invoice","invoiceCustom","company"]),r=Y({id:null,from:null,to:null,subject:"New Invoice",body:null}),z=B(()=>u.active&&u.componentName==="SendInvoiceModal"),E=B(()=>u.title),q=B(()=>u.data),L={from:{required:v.withMessage(d("validation.required"),h),email:v.withMessage(d("validation.email_incorrect"),N)},to:{required:v.withMessage(d("validation.required"),h),email:v.withMessage(d("validation.email_incorrect"),N)},subject:{required:v.withMessage(d("validation.required"),h)},body:{required:v.withMessage(d("validation.required"),h)}},t=Z(L,B(()=>r));function R(){b.value=!1}async function T(){let s=await j.fetchBasicMailConfig();r.id=u.id,s.data&&(r.from=s.data.from_mail),q.value&&(r.to=q.value.customer.email),r.body=j.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 F("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"),M=c("BaseInput"),w=c("BaseInputGroup"),A=c("BaseCustomInput"),O=c("BaseInputGrid"),g=c("BaseButton"),H=c("BaseModal");return _(),V(H,{show:z.value,onClose:y,onOpen:T},{header:n(()=>[p("div",te,[f($(E.value)+" ",1),a(m,{name:"XIcon",class:"w-6 h-6 text-gray-500 cursor-pointer",onClick:y})])]),default:n(()=>[b.value?(_(),x("div",le,[p("div",ne,[a(g,{class:"absolute top-4 right-4",disabled:e(i),variant:"primary-outline",onClick:R},{default:n(()=>[a(m,{name:"PencilIcon",class:"h-5 mr-2"}),f(" Edit ")]),_:1},8,["disabled"]),p("iframe",{src:C.value,frameborder:"0",class:"w-full",style:{"min-height":"500px"}},null,8,ie)]),p("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):(_(),V(m,{key:0,name:"PaperAirplaneIcon",class:"h-5 mr-2"})),f(" "+$(s.$t("general.send")),1)]),_:1},8,["loading","disabled"])])])):(_(),x("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(A,{modelValue:r.body,"onUpdate:modelValue":o[6]||(o[6]=l=>r.body=l),fields:G.value},null,8,["modelValue","fields"])]),_:1},8,["label","error"])]),_:1})]),p("div",se,[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):(_(),V(m,{key:0,class:ee(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 _};
