import{C as T}from"./ComboDynamique-BzWI4ISP.js";import{b as $}from"./primevue-CfIk0_DY.js";import{o as q,j as A,H as j,b as G,c as H,d as s,v as n,a7 as B,t as p,E as I,a as r,y as v}from"./vue-core-Di3IuVqe.js";import{u as N,S as b,b as h,s as o}from"./index-BxIwIJfy.js";import{D as P}from"./DataGrid-CoMfrBJA.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const z={class:"flex flex-col min-w-full p-1 gap-2"},M={class:"flex flex-col lg:flex-row lg:items-center lg:justify-between gap-2"},O={class:"flex items-center gap-2"},R={class:"flex items-center gap-3"},U={class:"grid grid-cols-2 md:grid-cols-3 gap-3 mb-1"},F={class:"rounded-lg bg-blue-50 px-4 py-3"},L={class:"mt-1 text-2xl font-semibold text-blue-700"},W={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 text-2xl font-semibold text-orange-700"},X={style:{height:"calc(100vh - 280px)"}},le={__name:"HistoriqueVehiculesParConducteur",setup(Y){const{showError:g,showInfo:x,showWarn:_}=N(),u=r(!1),a=r([]),c=r(""),d=r(),y=r(),w=v(()=>a.value.filter(t=>t.Statut==="En cours").length),C=v(()=>a.value.filter(t=>t.Statut==="Terminé").length),D=t=>({"En cours":{bg:"#10b981",text:"#ffffff"},Terminé:{bg:"#94a3b8",text:"#ffffff"}})[t]||{bg:"#64748b",text:"#ffffff"},k=t=>{y.value=t.api},m=async()=>{u.value=!0;try{const t=await h.post(`${o.lienApi}/historiqueVehiculesParConducteur/${o.db}`,{matricule_conducteur:c.value},{headers:{"Content-Type":"application/json"}});a.value=t.data.data||[]}catch(t){g("Erreur chargement : "+(t.response?.data?.message||t.message))}finally{u.value=!1}},S=()=>{if(!d.value)return x("Grille non initialisée");if(!a.value.length)return x("Aucune donnée à exporter");const t=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");d.value.exportToExcel(`Historique vehicules par conducteur_${o.state.enreg_societe.Nom}_${t}.xlsx`)},l=I({lecture:!1}),V=async()=>{try{const e=(await h.post(`${o.lienApi}/verifierDroit/${o.state.dbCommun6}`,{id_utilisateur:o.userId,id_page:2809,mail:o.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(l.lecture=e.lecture),l.lecture||(_("Vous n'avez pas le droit, veuillez consulter l'administrateur"),b("HistoriqueVehiculesParConducteur"))}catch(t){g("Une erreur est survenue : "+(t.response?.data?.message||t.message))}finally{o.state.afficher_in_progress=!1}};return q(async()=>{await V(),l.lecture&&m()}),(t,e)=>{const f=$,E=T;return A((G(),H("div",z,[s("div",M,[s("div",O,[n(f,{icon:"pi pi-search",label:"Afficher",text:"",loading:u.value,onClick:e[0]||(e[0]=i=>m())},null,8,["loading"]),n(f,{icon:"pi pi-file-excel",label:"Exporter",text:"",onClick:e[1]||(e[1]=i=>S()),disabled:!a.value.length},null,8,["disabled"]),n(f,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=i=>B(b)("HistoriqueVehiculesParConducteur"))})]),s("div",R,[e[5]||(e[5]=s("label",{class:"font-medium"},"Conducteur",-1)),n(E,{modelValue:c.value,"onUpdate:modelValue":[e[3]||(e[3]=i=>c.value=i),e[4]||(e[4]=i=>m())],table:"Conducteur",placeholder:"Tous",size:"small",style:{"min-width":"250px"}},null,8,["modelValue"])])]),s("div",U,[s("div",F,[e[6]||(e[6]=s("div",{class:"text-xs font-medium text-blue-700 uppercase tracking-wide"},"Affectations",-1)),s("div",L,p(a.value.length),1)]),s("div",W,[e[7]||(e[7]=s("div",{class:"text-xs font-medium text-green-700 uppercase tracking-wide"},"En cours",-1)),s("div",J,p(w.value),1)]),s("div",K,[e[8]||(e[8]=s("div",{class:"text-xs font-medium text-orange-700 uppercase tracking-wide"},"Terminées",-1)),s("div",Q,p(C.value),1)])]),s("div",X,[n(P,{ref_key:"dataGrid",ref:d,"excel-file-name":"Historique vehicules par conducteur","excel-sheet-name":"Affectations","row-data":a.value,"document-number-fields":["ndoc"],"validation-fields":["Statut"],"custom-status-colors":D,"excluded-columns":["ndoc"],"numeric-columns":["Durée (j)"],"column-widths":{Conducteur:200,Véhicule:130,"Marque/Modèle":200,"Date début":120,"Date fin":120,"Durée (j)":100,Statut:110,Note:200},"date-columns":["Date début","Date fin"],"date-only":["Date début","Date fin"],"enable-totals":!1,"show-checkbox":!1,onGridReady:k},null,8,["row-data"])])],512)),[[j,l.lecture]])}}};export{le as default};
