import{f as L,o as P,c as R,b as t,a as n,q as h,z as j,j as G,av as q,ax as B,M as W,F as H,r as a}from"./vendor-0kGcmQpG.js";import{_ as O}from"./selectDate-B99dlzOe.js";import{_ as K}from"./FavorisSwitch-DD6nTfzi.js";import{u as Q,a as p,s,S as C}from"./index-Bn9WoKhP.js";import{_ as X}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const Y={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},Z={class:"btns flex items-center gap-2"},ee={class:"flex items-center p-2"},le={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4 mb-4"},te={style:{height:"calc(100vh - 240px)"}},ce={__name:"JournalEvenements",setup(se){const{showError:d,showInfo:x,showWarn:A}=Q(),y=a(),m=a([]),_=a([]),v=a([]),T=a(),u=a(),r=a(null),c=a(null),f=a(null),g=a(null),w=a(""),$=a(""),V=a([{label:"Création",value:"Création"},{label:"Modification",value:"Modification"},{label:"Suppression",value:"Suppression"}]),k={DateAction:l=>l.value?new Date(l.value).toLocaleString("fr-FR"):"",TypeAction:l=>l.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;"}[l.value]||""}">${l.value}</span>`:"",Utilisateur:l=>l.value?`<div class="flex items-center gap-2"><i class="pi pi-user text-gray-500 text-xs"></i><span>${l.value}</span></div>`:"",Changements:l=>{if(l.value){let e=l.value.replace(/→/g,'<span style="color: #2563eb; font-weight: bold;"> → </span>').replace(/\(vide\)/g,'<span style="color: #9ca3af; font-style: italic;">(vide)</span>');return l.value.startsWith("Nouvel")?`<span style="color: #166534;"><i class="pi pi-plus-circle" style="margin-right: 4px;"></i>${l.value}</span>`:l.value.startsWith("Supprimé")?`<span style="color: #991b1b;"><i class="pi pi-trash" style="margin-right: 4px;"></i>${l.value}</span>`:`<span style="font-size: 12px;">${e}</span>`}return""}},D=l=>{u.value=l.api,u.value.applyColumnState({state:[{colId:"DateAction",sort:"desc"}],defaultState:{sort:null}})},S=(l,e)=>{w.value=l,$.value=e},U=async()=>{if(v.value=[],c.value=null,r.value)try{const l=await p.post(`${s.lienApi}/JournalUtilisateurs/${s.db}`,{tableName:r.value});v.value=l.data}catch{}};L(async()=>{await E();try{const l=await p.post(`${s.lienApi}/JournalTables/${s.db}`,{annee_fiscale:s.state.annee_fiscale});_.value=l.data}catch(l){const e=l.response?.data?.message||l.message;d(`Une erreur est survenue : ${e}`)}});const E=async()=>{try{const e=(await p.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:1203,mail:s.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(e.lecture||(A("Vous n'avez pas le droit, veuillez consulter l'administrateur"),C("JournalEvenements")))}catch(l){const e=l.response?.data?.message||l.message;d("Une erreur est survenue : "+e)}finally{s.state.afficher_in_progress=!1}},J=async()=>{s.state.afficher_in_progress=!0;try{const l=await p.post(`${s.lienApi}/JournalEvenements/${s.db}`,{tableName:r.value,dateDu:w.value,dateAu:$.value,utilisateur:c.value,cleValeur:g.value,typeAction:f.value},{headers:{"Content-Type":"application/json"}});m.value=l.data.map((e,i)=>({...e,id:`${i}_${e.CleValeur}_${e.DateAction}`}))}catch(l){d(`Erreur lors de l'affichage de l'historique
 ${l}`)}finally{s.state.afficher_in_progress=!1}},M=()=>{if(!u.value){x("Grille non initialisée");return}if(m.value.length===0){x("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");u.value.exportDataAsExcel({fileName:`Historique_${r.value}_${s.state.enreg_societe.Nom}_${e}.xlsx`,sheetName:"Historique",exportedRows:"all",onlySelected:!1,suppressTextAsCDATA:!0})};return(l,e)=>{const i=j,N=K,z=q,b=B,F=O,I=W;return P(),R(H,null,[t("div",Y,[t("div",Z,[n(i,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=o=>J()),text:"",loading:h(s).state.afficher_in_progress},null,8,["loading"]),n(i,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=o=>y.value?.toggle(o))}),n(z,{ref_key:"actionsMenu",ref:y,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>M()},{label:"Favoris",icon:"pi pi-star",template:"favorisTemplate"}],popup:!0},{favorisTemplate:G(()=>[t("div",ee,[n(N,{fen:"JournalEvenements",text:"Journal des événements"}),e[7]||(e[7]=t("span",{class:"font-semibold ml-2 text-primary"},"Favoris",-1))])]),_:1},8,["model"]),n(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>h(C)("JournalEvenements"))})])]),t("div",null,[t("div",le,[t("div",null,[e[8]||(e[8]=t("label",{class:"block text-sm"},"Table",-1)),n(b,{size:"small",modelValue:r.value,"onUpdate:modelValue":e[3]||(e[3]=o=>r.value=o),options:_.value,optionLabel:"Libelle",optionValue:"TableName",placeholder:"Toutes les tables",filter:!0,showClear:!0,class:"w-full",onChange:U},null,8,["modelValue","options"])]),t("div",null,[e[9]||(e[9]=t("label",{class:"block text-sm"},"Période",-1)),n(F,{onSelectDate:S,defaultPeriod:"month",class:"w-full"})]),t("div",null,[e[10]||(e[10]=t("label",{class:"block text-sm"},"Utilisateur",-1)),n(b,{size:"small",modelValue:c.value,"onUpdate:modelValue":e[4]||(e[4]=o=>c.value=o),options:v.value,optionLabel:"NomUtilisateur",optionValue:"id_utilisateur",placeholder:"Tous les utilisateurs",filter:!0,showClear:!0,class:"w-full"},null,8,["modelValue","options"])]),t("div",null,[e[11]||(e[11]=t("label",{class:"block text-sm"},"Type d'action",-1)),n(b,{size:"small",modelValue:f.value,"onUpdate:modelValue":e[5]||(e[5]=o=>f.value=o),options:V.value,optionLabel:"label",optionValue:"value",placeholder:"Toutes les actions",showClear:!0,class:"w-full"},null,8,["modelValue","options"])]),t("div",null,[e[12]||(e[12]=t("label",{class:"block text-sm"},"Clé (ID)",-1)),n(I,{size:"small",modelValue:g.value,"onUpdate:modelValue":e[6]||(e[6]=o=>g.value=o),placeholder:"Valeur de la clé primaire",class:"w-full"},null,8,["modelValue"])])])]),e[13]||(e[13]=t("div",{class:"h-2"},null,-1)),t("div",te,[n(X,{ref_key:"agGrid",ref:T,"excel-file-name":"Journal evenements","excel-sheet-name":"Journal evenements","row-data":m.value,"excluded-columns":["id"],"date-columns":[],"column-widths":{Table:130,CleValeur:120,DateAction:160,TypeAction:120,Utilisateur:150,Changements:400},"custom-renderers":k,"enable-totals":!1,rowIdField:"id",onGridReady:D},null,8,["row-data"])])],64)}}};export{ce as default};
