import{_ as ae}from"./Imprimer-CqTc6qE9.js";import{r as a,f as le,o as d,c as D,b as n,i as b,z as oe,d as m,a as c,av as ie,M as ne,an as re,ap as ue,j as de,q as ce,F as pe,ar as fe}from"./vendor-0kGcmQpG.js";import{u as me,a as y,s,S as k}from"./index-Bn9WoKhP.js";import{_ as ve}from"./DataGrid-tb6QVwpZ.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const ge={key:0},be={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},ye={class:"w-full bg-white p-4"},Ce={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},we={class:"flex flex-col gap-2"},xe={class:"field"},$e={class:"field"},_e={class:"w-full flex flex-row items-center gap-3 p-2"},he={style:{height:"calc(100vh - 220px)"}},Te={__name:"CategorieBudget",props:{ndoc:{type:String,default:""}},setup(E){const{confirmAction:S,showSuccess:L,showError:v,showInfo:A,showWarn:R}=me(),I=E,w=a(),g=a(),F=a([]),u=a({}),U=a(null),C=a([]),p=a(!1),x=a(null),f=a(!1),r=a(!1),z=a(!1),$=a(!1),N=a(""),G=a(""),_=a(I.ndoc||""),O=a(null),M=a(null),o=fe({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),P=({event:t,ndoc:e,rowIndex:l})=>{_.value=e,x.value=l,B()},q=({selectedRows:t})=>{F.value=t,U.value=t.length>0?t[0]:null},W=t=>{g.value=t.api},H=[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>Z()},{label:"Imprimer la liste",icon:"pi pi-print",command:()=>ee()}];le(async()=>{await J(),_.value?(B(),f.value=!0,r.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)):h()});const J=async()=>{try{const e=(await y.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:903,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(o.lecture=e.lecture,o.ajout=e.ajout,o.modif=e.modif,o.supp=e.supp,o.devalidation=e.devalidation,o.validation=e.validation),o.lecture||(R("Vous n'avez pas le droit, veuillez consulter l'administrateur"),k("CategorieBudget"))}catch(t){v("Une erreur s'est produite lors de la vérification des droits."+t)}},h=async()=>{s.state.afficher_in_progress=!0;try{p.value=!1,N.value=G.value;const t=await y.post(`${s.lienApi}/categoriesBudget/${s.db}`,{},{headers:{"Content-Type":"application/json"}});C.value=t.data}catch(t){v(`Une erreur est survenue lors de l'affichage des catégories de budget.
 ${t}`)}finally{s.state.afficher_in_progress=!1}},j=async()=>{try{const t=await y.post(`${s.lienApi}/ajouterEtRenvoyerCategorie/${s.db}`);u.value=t.data,p.value=!0,f.value=!0,r.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)}catch(t){v(`Une erreur est survenue lors de l'ajout d'une catégorie de budget.
 ${t}`)}finally{s.state.afficher_in_progress=!1}},K=async()=>{f.value=!0,r.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)},Q=async()=>{try{const t=`${s.lienApi}/enregistrerCategoriesBudget/${s.db}/${u.value.IdCategorie}`;await y.post(t,u.value,{headers:{"Content-Type":"application/json"}}),f.value=!1,r.value=!1}catch(t){const e=t.response?.data?.message||t.message;v(`Une erreur est survenue : ${e}`)}finally{s.state.afficher_in_progress=!1}},X=()=>{f.value=!1,r.value=!1},Y=()=>{I.ndoc?k("CategorieBudget"):(p.value=!1,h(),x.value!=null&&g.value&&setTimeout(()=>{const t=g.value.getDisplayedRowCount();if(t>0){const e=Math.min(x.value,t-1),l=g.value.getDisplayedRowAtIndex(e);l&&(g.value.deselectAll(),l.setSelected(!0),g.value.ensureNodeVisible(l,"middle"))}},100))},Z=()=>{if(!w.value){A("Grille non initialisée");return}if(C.value.length===0){A("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");w.value.exportToExcel(`Liste des catégories de budget_${s.state.enreg_societe.Nom}_${e}.xlsx`)},ee=()=>{$.value=!0},B=async()=>{try{const t=await y.post(`${s.lienApi}/uneCategorie/${s.db}/${_.value}`);u.value=t.data,p.value=!0}catch(t){v(`Une erreur est survenue lors de l'affichage des détails de la catégorie.
 ${t}`)}finally{s.state.afficher_in_progress=!1}},te=async()=>{if(await S({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${s.lienApi}/supprimerCategorie/${s.db}/${u.value.IdCategorie}`;await y.post(e),p.value=!1,f.value=!1,z.value=!1,h(),L("La catégorie de budget a été supprimée avec succès.")}catch(e){const l=e.response?.data?.message||e.message;v(`Une erreur est survenue : 
 ${l}`)}};return(t,e)=>{const l=oe,T=ie,V=ne,se=ae;return d(),D(pe,null,[p.value&&o.lecture?(d(),D("div",ge,[n("div",be,[r.value?m("",!0):(d(),b(l,{key:0,icon:"pi pi-pencil",label:"Modifier",text:"",onClick:e[0]||(e[0]=i=>K()),disabled:!o.modif},null,8,["disabled"])),r.value?m("",!0):(d(),b(l,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=i=>t.$refs.actionsMenu.toggle(i)),text:"",class:"mr-3"})),c(T,{ref_key:"actionsMenu",ref:O,model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:j,disabled:!o.ajout},{label:"Supprimer",icon:"pi pi-trash",class:"text-red-500",command:te,disabled:!o.supp}],popup:!0},null,8,["model"]),r.value?m("",!0):(d(),b(l,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:Y})),r.value?(d(),b(l,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=i=>Q())})):m("",!0),r.value?(d(),b(l,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=i=>X())})):m("",!0)]),n("div",ye,[n("div",Ce,[n("div",we,[n("div",xe,[e[10]||(e[10]=n("label",{for:"idCategorie"},"Numéro",-1)),c(V,{size:"small",id:"idCategorie",modelValue:u.value.IdCategorie,"onUpdate:modelValue":e[4]||(e[4]=i=>u.value.IdCategorie=i),class:"w-full",disabled:""},null,8,["modelValue"])]),n("div",$e,[e[11]||(e[11]=n("label",{for:"inputFocus"},"Libellé",-1)),c(V,{size:"small",id:"inputFocus",modelValue:u.value.Libelle,"onUpdate:modelValue":e[5]||(e[5]=i=>u.value.Libelle=i),class:"w-full",disabled:!f.value},null,8,["modelValue","disabled"])])]),e[12]||(e[12]=n("div",null,null,-1))])])])):m("",!0),re(n("div",null,[n("div",_e,[c(l,{icon:"pi pi-plus-circle",label:"Ajouter",text:"",onClick:e[6]||(e[6]=i=>j()),disabled:!o.ajout},null,8,["disabled"]),c(T,{ref_key:"listeMenu",ref:M,model:H,popup:!0},{button:de(()=>[c(l,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[7]||(e[7]=i=>M.value.toggle(i))})]),_:1},512),c(l,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[8]||(e[8]=i=>ce(k)("CategorieBudget"))})]),n("div",he,[c(ve,{ref_key:"dataGrid",ref:w,"excel-file-name":"Categorie budget","excel-sheet-name":"Categorie budget","row-data":C.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{IdCategorie:200,Libelle:300},"enable-totals":!1,"show-checkbox":!1,"numeric-columns":[],onRowClicked:P,onSelectionChanged:q,onGridReady:W},null,8,["row-data"])])],512),[[ue,!p.value&&o.lecture]]),$.value?(d(),b(se,{key:1,data:C.value,showModelSelector:!0,listeModelType:"Liste des catégories de budget",modeList:!0,onClose:e[9]||(e[9]=i=>$.value=!1)},null,8,["data"])):m("",!0)],64)}}};export{Te as default};
