import{f as $,aZ as A,o as d,i as M,j,b as s,aq as U,a as i,z as C,M as N,az as P,h as k,c as p,B as y,d as q,F as I,A as L,aI as R,S as G,r,e as Z}from"./vendor-BDR7yMJi.js";import{u as H,s as v,a as K}from"./index-BSaHX2oa.js";const O={class:"flex w-full p-1 gap-1 border-bottom-1 border-gray-200"},Q={class:"flex-1 flex flex-col gap-2"},W={class:"flex gap-2 align-middle justify-center items-center mb-2"},X={class:"p-float-label mb-2 gap-2"},Y={id:"droparea",class:"mb-2"},ee={key:0,class:"ml-1 font-medium"},se={key:0},le={key:0,class:"p-2 text-red-500"},oe={__name:"EnvoieDocumentsMail",props:{show:Boolean,sujet:String,pieceJointe:File,piecesJointes:{type:Array,default:()=>[]},to:{type:String,default:""},contenu:{type:String,default:""}},emits:["close","fermer"],setup(g,{emit:S}){const{showSuccess:D}=H(),a=g,h=S,b=r(!1),m=r(""),o=r(""),u=r(""),f=r(""),c=r([]),n=r(""),V=Z(()=>a.piecesJointes?.length?a.piecesJointes.map(l=>l.name):[]);function E(l){c.value=l.files}$(async()=>{if(o.value=v.state.userCloud.mail,a.piecesJointes&&a.piecesJointes.length>0){const l=new DataTransfer;a.piecesJointes.forEach(e=>l.items.add(e)),c.value=l.files}else if(a.pieceJointe){const l=new DataTransfer;l.items.add(a.pieceJointe),c.value=l.files}});const w=l=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l),F=async()=>{if(n.value="",!o.value||!u.value||!m.value){n.value="Veuillez remplir tous les champs obligatoires.";return}if(!w(u.value)){n.value="L'adresse email du destinataire n'est pas valide.";return}if(o.value&&!w(o.value)){n.value="L'adresse email de l'expéditeur n'est pas valide.";return}const l=new FormData;if(l.append("from",o.value),l.append("to",u.value),l.append("sujet",m.value),l.append("message",f.value||" "),c.value)for(let e=0;e<c.value.length;e++)l.append("PiecesJointes",c.value[e]);try{v.state.afficher_in_progress=!0,await K.post(`${v.lienApi}/envoyerEmail`,l),D("Mail envoyé avec succès"),v.state.afficher_in_progress=!1,h("close")}catch(e){n.value=e.message}};return A(()=>{b.value=a.show,m.value=a.sujet,a.to&&(u.value=a.to),a.contenu&&(f.value=a.contenu)}),(l,e)=>{const J=C,x=N,z=P,B=R,T=G;return d(),M(T,{visible:b.value,"onUpdate:visible":e[5]||(e[5]=t=>b.value=t),style:{width:"1024px",height:"80vh"},modal:!0,closable:!1,class:"email-dialog"},{default:j(()=>[s("form",{onSubmit:U(F,["prevent"]),class:"h-full flex flex-col"},[s("div",O,[i(J,{icon:"pi pi-send",label:"Envoyer",type:"submit",severity:"info",text:""}),i(J,{onClick:e[0]||(e[0]=t=>h("fermer")),icon:"pi pi-times",label:"Fermer",severity:"danger",text:""})]),s("div",Q,[s("div",W,[e[6]||(e[6]=s("label",{class:"mr-1"},"De",-1)),i(x,{size:"small",placeholder:"De",type:"email",modelValue:o.value,"onUpdate:modelValue":e[1]||(e[1]=t=>o.value=t),required:"",class:"w-full"},null,8,["modelValue"]),e[7]||(e[7]=s("label",{class:"ml-2 mr-1"},"A",-1)),i(x,{size:"small",modelValue:u.value,"onUpdate:modelValue":e[2]||(e[2]=t=>u.value=t),placeholder:"mail_1@example.com, mail_2@example.com...",required:"",class:"w-full"},null,8,["modelValue"])]),s("span",X,[e[8]||(e[8]=s("label",{for:"subject"},"Sujet *",-1)),i(x,{size:"small",id:"subject",modelValue:m.value,"onUpdate:modelValue":e[3]||(e[3]=t=>m.value=t),required:"",class:"w-full"},null,8,["modelValue"])]),i(z,{modelValue:f.value,"onUpdate:modelValue":e[4]||(e[4]=t=>f.value=t),editorStyle:"height: 420px",class:"mb-2"},{toolbar:j(()=>[...e[9]||(e[9]=[s("span",{class:"ql-formats"},[s("select",{class:"ql-font"}),s("select",{class:"ql-size"},[s("option",{value:"small"},"Petit"),s("option",{selected:""},"Normal"),s("option",{value:"large"},"Grand"),s("option",{value:"huge"},"Très grand")])],-1),s("span",{class:"ql-formats"},[s("button",{class:"ql-bold"}),s("button",{class:"ql-italic"}),s("button",{class:"ql-underline"}),s("button",{class:"ql-strike"})],-1),s("span",{class:"ql-formats"},[s("select",{class:"ql-color"}),s("select",{class:"ql-background"})],-1),s("span",{class:"ql-formats"},[s("select",{class:"ql-align"})],-1),s("span",{class:"ql-formats"},[s("button",{class:"ql-link"}),s("button",{class:"ql-image"})],-1),s("span",{class:"ql-formats"},[s("button",{class:"ql-clean"})],-1)])]),_:1},8,["modelValue"]),s("div",Y,[e[10]||(e[10]=k(" Pièces Jointes: ",-1)),g.pieceJointe&&!g.piecesJointes?.length?(d(),p("span",ee,y(a.sujet+".pdf"),1)):q("",!0),(d(!0),p(I,null,L(V.value,(t,_)=>(d(),p("span",{key:_,class:"ml-1 font-medium"},[k(y(t),1),_<V.value.length-1?(d(),p("span",se,", ")):q("",!0)]))),128))]),i(B,{mode:"basic",multiple:!0,accept:".pdf,.jpeg,.png,.jpg,.doc,.docx,.xls,.xlsx",maxFileSize:1e7,onSelect:E,chooseLabel:"Ajouter des fichiers",class:"w-full"})]),n.value?(d(),p("div",le,"Message d'erreur : "+y(n.value),1)):q("",!0)],32)]),_:1},8,["visible"])}}};export{oe as _};
