import{b as M,y as E}from"./primevue-CfIk0_DY.js";import{a as r,o as G,j as T,H as V,b as j,c as I,d as n,v as d,a7 as _,t as f,E as B,y}from"./vue-core-Di3IuVqe.js";import{u as P,s,S as w,o as z,b as h}from"./index-BxIwIJfy.js";import{D as F}from"./DataGrid-CoMfrBJA.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const H={class:"flex flex-col min-w-full p-1 gap-2"},O={class:"flex flex-col lg:flex-row lg:items-center lg:justify-between gap-2"},R={class:"flex items-center gap-2"},U={class:"flex items-center gap-3"},Y={class:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-1"},L={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-orange-50 px-4 py-3"},J={class:"mt-1 text-2xl font-semibold text-orange-700"},K={class:"rounded-lg bg-red-50 px-4 py-3"},Q={class:"mt-1 flex items-baseline gap-1"},X={class:"text-2xl font-semibold text-red-700"},Z={style:{height:"calc(100vh - 280px)"}},de={__name:"ContraventionsParConducteur",setup(ee){const{showError:x,showInfo:g,showWarn:C}=P(),u=r(!1),o=r([]),a=r(parseInt(s.state.annee_fiscale,10)||new Date().getFullYear()),b=r([a.value]),p=r(),D=r(),$=y(()=>o.value.reduce((t,e)=>t+(Number(e["Nb contraventions"])||0),0)),k=y(()=>o.value.reduce((t,e)=>t+(Number(e["Montant total"])||0),0)),N=t=>{D.value=t.api},m=async()=>{u.value=!0;try{const t=await h.post(`${s.lienApi}/contraventionsParConducteur/${s.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{u.value=!1}},A=()=>{if(!p.value)return g("Grille non initialisée");if(!o.value.length)return g("Aucune donnée à exporter");const t=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");p.value.exportToExcel(`Contraventions par conducteur_${a.value}_${s.state.enreg_societe.Nom}_${t}.xlsx`)},c=B({lecture:!1}),S=async()=>{try{const e=(await h.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:2810,mail:s.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(c.lecture=e.lecture),c.lecture||(C("Vous n'avez pas le droit, veuillez consulter l'administrateur"),w("ContraventionsParConducteur"))}catch(t){x("Une erreur est survenue : "+(t.response?.data?.message||t.message))}finally{s.state.afficher_in_progress=!1}};return G(async()=>{await S(),c.lecture&&m()}),(t,e)=>{const l=M,v=E;return T((j(),I("div",H,[n("div",O,[n("div",R,[d(l,{icon:"pi pi-search",label:"Afficher",text:"",loading:u.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=>_(w)("ContraventionsParConducteur"))})]),n("div",U,[e[5]||(e[5]=n("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"])])]),n("div",Y,[n("div",L,[e[6]||(e[6]=n("div",{class:"text-xs font-medium text-blue-700 uppercase tracking-wide"},"Conducteurs",-1)),n("div",W,f(o.value.length),1)]),n("div",q,[e[7]||(e[7]=n("div",{class:"text-xs font-medium text-orange-700 uppercase tracking-wide"},"Total contraventions",-1)),n("div",J,f($.value),1)]),n("div",K,[e[9]||(e[9]=n("div",{class:"text-xs font-medium text-red-700 uppercase tracking-wide"},"Montant cumulé",-1)),n("div",Q,[n("span",X,f(_(z)(k.value)),1),e[8]||(e[8]=n("span",{class:"text-sm text-red-600"},"DH",-1))])])]),n("div",Z,[d(F,{ref_key:"dataGrid",ref:p,"excel-file-name":"Contraventions par conducteur","excel-sheet-name":"Conducteurs","row-data":o.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"numeric-columns":["Nb contraventions","Montant total"],"column-widths":{Matricule:120,Conducteur:250,"Nb contraventions":150,"Montant total":150,"Dernière contravention":160},"date-columns":["Dernière contravention"],"date-only":["Dernière contravention"],"enable-totals":!0,"show-checkbox":!1,onGridReady:N},null,8,["row-data"])])],512)),[[V,c.lecture]])}}};export{de as default};
