import{b as S,y as V}from"./primevue-CfIk0_DY.js";import{a as r,o as B,j as E,H as G,b as N,c as P,d as s,v as d,a7 as _,t as g,E as j,y as w}from"./vue-core-Di3IuVqe.js";import{u as z,s as n,S as y,o as F,b as h}from"./index-BxIwIJfy.js";import{D as H}from"./DataGrid-CoMfrBJA.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const O={class:"flex flex-col min-w-full p-1 gap-2"},R={class:"flex flex-col lg:flex-row lg:items-center lg:justify-between gap-2"},U={class:"flex items-center gap-2"},Y={class:"flex items-center gap-3"},L={class:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-1"},M={class:"rounded-lg bg-blue-50 px-4 py-3"},W={class:"mt-1 text-2xl font-semibold text-blue-700"},q={class:"rounded-lg bg-green-50 px-4 py-3"},J={class:"mt-1 text-2xl font-semibold text-green-700"},K={class:"rounded-lg bg-orange-50 px-4 py-3"},Q={class:"mt-1 flex items-baseline gap-1"},X={class:"text-2xl font-semibold text-orange-700"},Z={style:{height:"calc(100vh - 280px)"}},de={__name:"InterventionsParConducteur",setup(ee){const{showError:x,showInfo:f,showWarn:C}=z(),c=r(!1),o=r([]),a=r(parseInt(n.state.annee_fiscale,10)||new Date().getFullYear()),b=r([a.value]),p=r(),D=r(),I=w(()=>o.value.reduce((t,e)=>t+(Number(e["Total interventions"])||0),0)),$=w(()=>o.value.reduce((t,e)=>t+(Number(e["Coût total"])||0),0)),k=t=>{D.value=t.api},m=async()=>{c.value=!0;try{const t=await h.post(`${n.lienApi}/interventionsParConducteur/${n.db}`,{annee:a.value},{headers:{"Content-Type":"application/json"}});o.value=t.data.data||[];const e=new Set(t.data.anneesDisponibles||[]);e.add(a.value),e.add(new Date().getFullYear()),b.value=Array.from(e).sort((l,v)=>v-l)}catch(t){x("Erreur chargement : "+(t.response?.data?.message||t.message))}finally{c.value=!1}},A=()=>{if(!p.value)return f("Grille non initialisée");if(!o.value.length)return f("Aucune donnée à exporter");const t=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");p.value.exportToExcel(`Interventions par conducteur_${a.value}_${n.state.enreg_societe.Nom}_${t}.xlsx`)},u=j({lecture:!1}),T=async()=>{try{const e=(await h.post(`${n.lienApi}/verifierDroit/${n.state.dbCommun6}`,{id_utilisateur:n.userId,id_page:2817,mail:n.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(u.lecture=e.lecture),u.lecture||(C("Vous n'avez pas le droit, veuillez consulter l'administrateur"),y("InterventionsParConducteur"))}catch(t){x("Une erreur est survenue : "+(t.response?.data?.message||t.message))}};return B(async()=>{await T(),u.lecture&&m()}),(t,e)=>{const l=S,v=V;return E((N(),P("div",O,[s("div",R,[s("div",U,[d(l,{icon:"pi pi-search",label:"Afficher",text:"",loading:c.value,onClick:e[0]||(e[0]=i=>m())},null,8,["loading"]),d(l,{icon:"pi pi-file-excel",label:"Exporter",text:"",onClick:e[1]||(e[1]=i=>A()),disabled:!o.value.length},null,8,["disabled"]),d(l,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=i=>_(y)("InterventionsParConducteur"))})]),s("div",Y,[e[5]||(e[5]=s("label",{class:"font-medium"},"Année",-1)),d(v,{modelValue:a.value,"onUpdate:modelValue":e[3]||(e[3]=i=>a.value=i),options:b.value,placeholder:"Année",size:"small",style:{"min-width":"120px"},onChange:e[4]||(e[4]=i=>m())},null,8,["modelValue","options"])])]),s("div",L,[s("div",M,[e[6]||(e[6]=s("div",{class:"text-xs font-medium text-blue-700 uppercase tracking-wide"},"Conducteurs",-1)),s("div",W,g(o.value.length),1)]),s("div",q,[e[7]||(e[7]=s("div",{class:"text-xs font-medium text-green-700 uppercase tracking-wide"},"Total interventions",-1)),s("div",J,g(I.value),1)]),s("div",K,[e[9]||(e[9]=s("div",{class:"text-xs font-medium text-orange-700 uppercase tracking-wide"},"Coût total",-1)),s("div",Q,[s("span",X,g(_(F)($.value)),1),e[8]||(e[8]=s("span",{class:"text-sm text-orange-600"},"DH",-1))])])]),s("div",Z,[d(H,{ref_key:"dataGrid",ref:p,"excel-file-name":"Interventions par conducteur","excel-sheet-name":"Interventions","row-data":o.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"numeric-columns":["Vidanges","Pneus","Batterie","Contrôles","Autres","Total interventions","Coût total"],"column-widths":{Conducteur:220,Vidanges:100,Pneus:90,Batterie:100,Contrôles:110,Autres:100,"Total interventions":140,"Coût total":130},"enable-totals":!0,"show-checkbox":!1,onGridReady:k},null,8,["row-data"])])],512)),[[G,u.lecture]])}}};export{de as default};
