import{w as m,f as y,o as h,c as x,b as s,a as u,z as b,B as _,r as i}from"./vendor-0kGcmQpG.js";import{a as $,s as d}from"./index-Bn9WoKhP.js";import{_ as F}from"./DataGrid-tb6QVwpZ.js";const S={class:"flex items-center gap-3 mb-2"},q={class:"text-sm text-gray-500"},w={style:{height:"calc(100vh - 440px)"}},B={__name:"HistoriqueDocument",props:{tableName:{type:String,required:!0},colonneFiltre:{type:String,required:!0},valeurFiltre:{type:[String,Number],required:!0}},setup(p){const r=p,a=i([]),o=i(!1),f=i(),c=i(),g={DateAction:e=>e.value?new Date(e.value).toLocaleString("fr-FR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"",TypeAction:e=>e.value?`<span style="padding: 2px 8px; border-radius: 4px; font-size: 12px; ${{Création:"background-color: #dcfce7; color: #166534;",Modification:"background-color: #fef3c7; color: #92400e;",Suppression:"background-color: #fee2e2; color: #991b1b;"}[e.value]||""}">${e.value}</span>`:"",Utilisateur:e=>e.value?`<div class="flex items-center gap-2"><i class="pi pi-user text-gray-500 text-xs"></i><span>${e.value}</span></div>`:"",Changements:e=>{if(e.value){let t=e.value.replace(/→/g,'<span style="color: #2563eb; font-weight: bold;"> → </span>').replace(/\(vide\)/g,'<span style="color: #9ca3af; font-style: italic;">(vide)</span>');return e.value.startsWith("Nouvel")?`<span style="color: #166534;"><i class="pi pi-plus-circle" style="margin-right: 4px;"></i>${e.value}</span>`:e.value.startsWith("Supprimé")?`<span style="color: #991b1b;"><i class="pi pi-trash" style="margin-right: 4px;"></i>${e.value}</span>`:`<span style="font-size: 12px;">${t}</span>`}return""}},v=e=>{c.value=e.api,c.value.applyColumnState({state:[{colId:"DateAction",sort:"desc"}],defaultState:{sort:null}})},n=async()=>{if(!(!r.tableName||!r.colonneFiltre||!r.valeurFiltre)){o.value=!0;try{const e=await $.post(`${d.lienApi}/JournalDocument/${d.db}`,{tableName:r.tableName,colonneFiltre:r.colonneFiltre,valeurFiltre:String(r.valeurFiltre)});a.value=e.data.map((t,l)=>({...t,id:`${l}_${t.DateAction}`}))}catch{}finally{o.value=!1}}};return m(()=>r.valeurFiltre,()=>{n()}),y(()=>{n()}),(e,t)=>{const l=b;return h(),x("div",null,[s("div",S,[u(l,{icon:"pi pi-refresh",text:"",onClick:t[0]||(t[0]=A=>n()),loading:o.value,title:"Rafraîchir"},null,8,["loading"]),s("span",q,_(a.value.length)+" modification(s) ",1)]),s("div",w,[u(F,{ref_key:"agGrid",ref:f,"excel-file-name":"Historique document","excel-sheet-name":"Historique document","row-data":a.value,"excluded-columns":["id"],"date-columns":[],"column-widths":{DateAction:160,TypeAction:120,Utilisateur:150,Changements:400},"custom-renderers":g,"enable-totals":!1,rowIdField:"id",onGridReady:v},null,8,["row-data"])])])}}};export{B as _};
