import{r as o,w as I,f as U,o as m,c as _,a as r,j as L,b as i,ax as P,aw as z,d as y,ay as H,z as J,S as K,i as j,F as W}from"./vendor-BDR7yMJi.js";import{R as q}from"./ReportViewer-Cmd4kpyP.js";import{_ as G}from"./EnvoieDocumentsMail-P3u1QAl1.js";import{u as Q,s,a as X}from"./index-BSaHX2oa.js";const Y={key:0,class:"p-0 pa-2 pb-4 bg-gray-100"},Z={class:"mt-4 ml-3 flex flex-col gap-4"},ee={key:0,class:"flex items-center"},te={key:1,class:"flex gap-6"},oe={class:"flex items-center"},le={class:"flex items-center"},ae={class:"flex w-full gap-3 mt-3"},ue={__name:"Imprimer",props:{show:Boolean,document_:String,isEnvoiMail:{type:Boolean,default:!1},sujet:{type:String,default:"Document"},data:[Array,Object],RapportName:String,modeList:Boolean,titre:String,showModelSelector:{type:Boolean,default:!1},listeModelType:String,autoPrint:{type:Boolean,default:!1},showHtTtcOption:{type:Boolean,default:!0},showEnteteOption:{type:Boolean,default:!0},nomFichier:String},emits:["close","savePdf"],setup(x,{emit:C}){const{showError:M,showWarn:O}=Q(),w=o([]),p=o(s.state.enreg_option_comm.saisie_prix),d=o(!1),R=o(!1),n=o(""),$=o(!0),g=o(!1),S=o(),h=o(""),v=o(!1),E=C,t=x,c=o(t.show),B=o(t.data),b=o(t.showModelSelector),A=o(t.showHtTtcOption),D=o(t.showEnteteOption);I(()=>t.show,a=>{c.value=a}),I(()=>t.data,a=>{B.value=a},{immediate:!0}),U(async()=>{v.value=!!t.modeList||!!t.data&&!t.showModelSelector,s.state.afficher_in_progress=!0;try{const a=t.listeModelType||t.document_||"default",e=`${s.lienApi}/affichierRapportsPourImprimer/${s.db}`,V=(await X.post(e,{IdClient:s.cloudId,document:a,id_societe:s.id_societe},{headers:{"Content-Type":"application/json"}})).data;if(w.value=V.map(f=>{const u={value:f.chemin,text:f.name.replace(".mrt","")};return u.value.includes("default_")&&(n.value=u.value),u}),n.value=n.value===""&&w.value.length>0?w.value[0].value:n.value,t.autoPrint&&n.value){c.value=!1,await F();return}v.value&&!b.value&&t.RapportName&&(h.value=`${s.lienApi}/commun/rapports${t.RapportName}.mrt`,d.value=!0)}catch(a){M(`Une erreur est survenue lors de l'affichage des rapports: ${a}`)}finally{s.state.afficher_in_progress=!1}});const F=async()=>{try{if(!n.value){O("Veuillez sélectionner un modèle d'impression");return}s.state.afficher_in_progress=!0,v.value&&b.value?h.value=`${s.lienApi}/${n.value}`:v.value||(h.value=`${s.lienApi}/${n.value}`),d.value=!0}catch(a){M(`Impossible de générer le rapport: ${a}`)}finally{c.value=!1,s.state.afficher_in_progress=!1}},T=a=>{S.value=a,g.value=!0};return(a,e)=>{const k=P,V=z,f=H,u=J,N=K;return m(),_(W,null,[r(N,{visible:c.value,"onUpdate:visible":e[6]||(e[6]=l=>c.value=l),modal:"",closable:!1,style:{width:"35rem"}},{default:L(()=>[!R.value&&(!v.value||b.value)?(m(),_("div",Y,[e[13]||(e[13]=i("div",{class:"mb-1 text-xl font-medium"},"Modèle d'impression",-1)),e[14]||(e[14]=i("div",{class:"mb-4 text-sm text-gray-600"},"Sélectionnez un modèle d'impression",-1)),i("div",Z,[r(k,{size:"small",modelValue:n.value,"onUpdate:modelValue":e[0]||(e[0]=l=>n.value=l),options:w.value,optionLabel:"text",optionValue:"value",class:"w-56"},null,8,["modelValue","options"]),D.value?(m(),_("div",ee,[r(V,{modelValue:$.value,"onUpdate:modelValue":e[1]||(e[1]=l=>$.value=l),binary:"",inputId:"entete"},null,8,["modelValue"]),e[10]||(e[10]=i("label",{for:"entete",style:{"margin-left":"0.5rem"}},"Avec Entête",-1))])):y("",!0),A.value?(m(),_("div",te,[i("div",oe,[r(f,{modelValue:p.value,"onUpdate:modelValue":e[2]||(e[2]=l=>p.value=l),inputId:"ht",name:"price_format",value:"ht"},null,8,["modelValue"]),e[11]||(e[11]=i("label",{for:"ht",style:{"margin-left":"0.5rem"}},"Impression en ht",-1))]),i("div",le,[r(f,{modelValue:p.value,"onUpdate:modelValue":e[3]||(e[3]=l=>p.value=l),inputId:"ttc",name:"price_format",value:"ttc"},null,8,["modelValue"]),e[12]||(e[12]=i("label",{for:"ttc",style:{"margin-left":"0.5rem"}},"Impression en ttc",-1))])])):y("",!0),i("div",ae,[r(u,{icon:"pi pi-print",label:"OK",text:"",severity:"success",onClick:e[4]||(e[4]=l=>F())}),r(u,{icon:"pi pi-times-circle",label:"Annuler",text:"",severity:"danger",onClick:e[5]||(e[5]=l=>a.$emit("close"))})])])])):y("",!0)]),_:1},8,["visible"]),g.value?(m(),j(G,{key:0,sujet:x.sujet,show:g.value,onClose:e[7]||(e[7]=l=>E("close")),onFermer:e[8]||(e[8]=l=>g.value=!1),"piece-jointe":S.value},null,8,["sujet","show","piece-jointe"])):y("",!0),d.value?(m(),j(q,{key:1,show:d.value,onClose:e[9]||(e[9]=l=>(d.value=!1,E("close"))),onSaveFichierPDF:T,ttc_ht:p.value,avecEntete:$.value,urlFichier:h.value,isEnvoiMail:x.isEnvoiMail,data:B.value,nomFichier:t.nomFichier},null,8,["show","ttc_ht","avecEntete","urlFichier","isEnvoiMail","data","nomFichier"])):y("",!0)],64)}}};export{ue as _};
