import{C as E}from"./ComboDynamique-BzWI4ISP.js";import{b as G,y as H}from"./primevue-CfIk0_DY.js";import{a as n,o as K,j as T,H as j,b as I,c as z,d as s,v as r,a7 as B,t as g,E as F,y as _}from"./vue-core-Di3IuVqe.js";import{u as M,s as a,S as w,b as D}from"./index-BxIwIJfy.js";import{D as N}from"./DataGrid-CoMfrBJA.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const U={class:"flex flex-col min-w-full p-1 gap-2"},L={class:"flex flex-col lg:flex-row lg:items-center lg:justify-between gap-2"},O={class:"flex items-center gap-2"},P={class:"flex items-center gap-3"},Y={class:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-1"},W={class:"rounded-lg bg-blue-50 px-4 py-3"},J={class:"mt-1 text-2xl font-semibold text-blue-700"},Q={class:"rounded-lg bg-green-50 px-4 py-3"},X={class:"mt-1 text-base font-semibold text-green-700"},Z={class:"rounded-lg bg-orange-50 px-4 py-3"},ee={class:"mt-1 text-base font-semibold text-orange-700"},te={style:{height:"calc(100vh - 280px)"}},me={__name:"HistoriqueRelevesKm",setup(se){const{showError:x,showInfo:b,showWarn:k}=M(),m=n(!1),l=n([]),i=n(parseInt(a.state.annee_fiscale,10)||new Date().getFullYear()),h=n([i.value]),p=n(""),v=n(),V=n(),y=t=>t?new Date(t).toLocaleDateString("fr-FR"):"—",$=_(()=>l.value.length?y(l.value[l.value.length-1].Date):"—"),C=_(()=>l.value.length?y(l.value[0].Date):"—"),R=t=>{V.value=t.api},d=async()=>{m.value=!0;try{const t=await D.post(`${a.lienApi}/historiqueRelevesKm/${a.db}`,{annee:i.value,id_vehicule:p.value},{headers:{"Content-Type":"application/json"}});l.value=t.data.data||[];const e=new Set(t.data.anneesDisponibles||[]);e.add(i.value),e.add(new Date().getFullYear()),h.value=Array.from(e).sort((u,f)=>f-u)}catch(t){x("Erreur chargement : "+(t.response?.data?.message||t.message))}finally{m.value=!1}},q=()=>{if(!v.value)return b("Grille non initialisée");if(!l.value.length)return b("Aucune donnée à exporter");const t=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");v.value.exportToExcel(`Historique releves km_${i.value}_${a.state.enreg_societe.Nom}_${t}.xlsx`)},c=F({lecture:!1}),A=async()=>{try{const e=(await D.post(`${a.lienApi}/verifierDroit/${a.state.dbCommun6}`,{id_utilisateur:a.userId,id_page:2812,mail:a.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(c.lecture=e.lecture),c.lecture||(k("Vous n'avez pas le droit, veuillez consulter l'administrateur"),w("HistoriqueRelevesKm"))}catch(t){x("Une erreur est survenue : "+(t.response?.data?.message||t.message))}finally{a.state.afficher_in_progress=!1}};return K(async()=>{await A(),c.lecture&&d()}),(t,e)=>{const u=G,f=H,S=E;return T((I(),z("div",U,[s("div",L,[s("div",O,[r(u,{icon:"pi pi-search",label:"Afficher",text:"",loading:m.value,onClick:e[0]||(e[0]=o=>d())},null,8,["loading"]),r(u,{icon:"pi pi-file-excel",label:"Exporter",text:"",onClick:e[1]||(e[1]=o=>q()),disabled:!l.value.length},null,8,["disabled"]),r(u,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>B(w)("HistoriqueRelevesKm"))})]),s("div",P,[e[7]||(e[7]=s("label",{class:"font-medium"},"Année",-1)),r(f,{modelValue:i.value,"onUpdate:modelValue":e[3]||(e[3]=o=>i.value=o),options:h.value,placeholder:"Année",size:"small",style:{"min-width":"120px"},onChange:e[4]||(e[4]=o=>d())},null,8,["modelValue","options"]),e[8]||(e[8]=s("label",{class:"font-medium ml-2"},"Véhicule",-1)),r(S,{modelValue:p.value,"onUpdate:modelValue":[e[5]||(e[5]=o=>p.value=o),e[6]||(e[6]=o=>d())],table:"VehiculeParc",placeholder:"Tous",size:"small",style:{"min-width":"220px"}},null,8,["modelValue"])])]),s("div",Y,[s("div",W,[e[9]||(e[9]=s("div",{class:"text-xs font-medium text-blue-700 uppercase tracking-wide"},"Relevés",-1)),s("div",J,g(l.value.length),1)]),s("div",Q,[e[10]||(e[10]=s("div",{class:"text-xs font-medium text-green-700 uppercase tracking-wide"},"Premier relevé",-1)),s("div",X,g($.value),1)]),s("div",Z,[e[11]||(e[11]=s("div",{class:"text-xs font-medium text-orange-700 uppercase tracking-wide"},"Dernier relevé",-1)),s("div",ee,g(C.value),1)])]),s("div",te,[r(N,{ref_key:"dataGrid",ref:v,"excel-file-name":"Historique releves km","excel-sheet-name":"Relevés km","row-data":l.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"numeric-columns":["Kilométrage"],"column-widths":{Date:120,Véhicule:150,"Marque/Modèle":250,Kilométrage:150},"date-columns":["Date"],"date-only":["Date"],"enable-totals":!1,"show-checkbox":!1,onGridReady:R},null,8,["row-data"])])],512)),[[j,c.lecture]])}}};export{me as default};
