import{_ as me}from"./Imprimer-DluCFs7h.js";import{b as fe,B as ve,g as ge}from"./primevue-CfIk0_DY.js";import{a as o,o as be,i as ye,b as u,c as h,k as g,p,d as n,v as c,a7 as m,t as U,j as G,T as xe,H as we,l as Ce,F as _e,E as he,y as ke}from"./vue-core-Di3IuVqe.js";import{u as $e,b as w,s as a,S as B}from"./index-BxIwIJfy.js";import{u as Ae}from"./usePagerDetail-BeqYPv-1.js";import{D as De}from"./DataGrid-CoMfrBJA.js";import{N as Ie}from"./NumeroChip-QCXXOqUM.js";import"./ReportViewer-BNzhW7G2.js";import"./stimulsoft-B2-Y-rC1.js";import"./cjs-helpers-psZwOBky.js";import"./PDFButton-DhVJ6hNy.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const je={key:1,class:"omag-drawer",style:{"--omag-drawer-w":"640px"}},Be={class:"omag-drawer-header"},Me={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},Ee={key:5,class:"flex items-center",style:{"margin-left":"auto",gap:"2px"}},Te={style:{"min-width":"54px","text-align":"center",color:"#6b7280"}},Se={class:"m-4 omag-form"},Le={class:"omag-form-grid"},Fe={class:"flex flex-col gap-2 omag-col-full"},Re={class:"field"},Ne={class:"page-wrapper"},Ve={class:"w-full flex flex-row items-center gap-3 p-2"},Ue={class:"grille-container"},tt={__name:"CategorieBudget",props:{ndoc:{type:String,default:""}},setup(z){const{confirmAction:M,showSuccess:P,showError:b,showInfo:E,showWarn:O}=$e(),T=z,k=o(),y=o(),H=o([]),f=o({}),W=o(null),x=o([]),v=o(!1),C=o(null),d=o(!1),l=o(!1),q=o(!1),$=o(!1),J=o(""),K=o(""),_=o(T.ndoc||""),Q=o(null),S=o(null),i=he({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),X=({event:t,ndoc:e,rowIndex:s})=>{_.value=e,C.value=s,D()},Y=({selectedRows:t})=>{H.value=t,W.value=t.length>0?t[0]:null},Z=t=>{y.value=t.api},ee=[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>le()},{label:"Imprimer la liste",icon:"pi pi-print",command:()=>ie()}];be(async()=>{await te(),_.value?(D(),d.value=!0,l.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)):A()});const te=async()=>{try{const e=(await w.post(`${a.lienApi}/verifierDroit/${a.state.dbCommun6}`,{id_utilisateur:a.userId,id_page:903,mail:a.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(i.lecture=e.lecture,i.ajout=e.ajout,i.modif=e.modif,i.supp=e.supp,i.devalidation=e.devalidation,i.validation=e.validation),i.lecture||(O("Vous n'avez pas le droit, veuillez consulter l'administrateur"),B("CategorieBudget"))}catch(t){b("Une erreur s'est produite lors de la vérification des droits."+t)}},A=async()=>{a.state.afficher_in_progress=!0;try{v.value=!1,J.value=K.value;const t=await w.post(`${a.lienApi}/categoriesBudget/${a.db}`,{},{headers:{"Content-Type":"application/json"}});x.value=t.data}catch(t){b(`Une erreur est survenue lors de l'affichage des catégories de budget.
 ${t}`)}finally{a.state.afficher_in_progress=!1}},L=async()=>{try{const t=await w.post(`${a.lienApi}/ajouterEtRenvoyerCategorie/${a.db}`);f.value=t.data,v.value=!0,d.value=!0,l.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)}catch(t){b(`Une erreur est survenue lors de l'ajout d'une catégorie de budget.
 ${t}`)}finally{a.state.afficher_in_progress=!1}},se=async()=>{d.value=!0,l.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)},ae=async()=>{try{const t=`${a.lienApi}/enregistrerCategoriesBudget/${a.db}/${f.value.IdCategorie}`;await w.post(t,f.value,{headers:{"Content-Type":"application/json"}}),d.value=!1,l.value=!1}catch(t){const e=t.response?.data?.message||t.message;b(`Une erreur est survenue : ${e}`)}finally{a.state.afficher_in_progress=!1}},oe=()=>{d.value=!1,l.value=!1},F=async()=>{l.value&&!await M({message:"Des modifications ne sont pas enregistrées. Fermer et les perdre ?"})||(d.value=!1,l.value=!1,R())},R=()=>{T.ndoc?B("CategorieBudget"):(v.value=!1,A(),C.value!=null&&y.value&&setTimeout(()=>{const t=y.value.getDisplayedRowCount();if(t>0){const e=Math.min(C.value,t-1),s=y.value.getDisplayedRowAtIndex(e);s&&(y.value.deselectAll(),s.setSelected(!0),y.value.ensureNodeVisible(s,"middle"))}},100))},le=()=>{if(!k.value){E("Grille non initialisée");return}if(x.value.length===0){E("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");k.value.exportToExcel(`Liste des catégories de budget_${a.state.enreg_societe.Nom}_${e}.xlsx`)},ie=()=>{$.value=!0},D=async()=>{try{const t=await w.post(`${a.lienApi}/uneCategorie/${a.db}/${_.value}`);f.value=t.data,v.value=!0}catch(t){b(`Une erreur est survenue lors de l'affichage des détails de la catégorie.
 ${t}`)}finally{a.state.afficher_in_progress=!1}},re=ke(()=>x.value.map(t=>t.ndoc)),ne=async()=>{d.value=!1,l.value=!1,await D()},{totalListe:I,positionCourante:j,naviguer:N}=Ae({listeNdocs:re,ndoc:_,charger:ne,estEnEdition:l,onNaviguer:t=>{const e=x.value.findIndex(s=>s.ndoc===t);e!==-1&&(C.value=e)}}),ue=async()=>{if(await M({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${a.lienApi}/supprimerCategorie/${a.db}/${f.value.IdCategorie}`;await w.post(e),v.value=!1,d.value=!1,q.value=!1,A(),P("La catégorie de budget a été supprimée avec succès.")}catch(e){const s=e.response?.data?.message||e.message;b(`Une erreur est survenue : 
 ${s}`)}};return(t,e)=>{const s=fe,V=ve,ce=ge,de=me,pe=ye("maxlen-db");return u(),h(_e,null,[(u(),g(xe,{to:"body"},[v.value&&i.lecture?(u(),h("div",{key:0,class:"omag-drawer-scrim",onClick:F})):p("",!0),v.value&&i.lecture?(u(),h("div",je,[n("div",Be,[e[11]||(e[11]=n("span",{class:"omag-drawer-title"},"Catégorie budget",-1)),c(s,{icon:"pi pi-times",text:"",rounded:"",onClick:F,title:"Fermer"})]),n("div",Me,[l.value?p("",!0):(u(),g(s,{key:0,icon:"pi pi-pencil",label:"Modifier",text:"",onClick:e[0]||(e[0]=r=>se()),disabled:!i.modif},null,8,["disabled"])),l.value?p("",!0):(u(),g(s,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=r=>t.$refs.actionsMenu.toggle(r)),text:"",class:"mr-3"})),c(V,{ref_key:"actionsMenu",ref:Q,model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:L,disabled:!i.ajout},{label:"Supprimer",icon:"pi pi-trash",class:"text-red-500",command:ue,disabled:!i.supp}],popup:!0},null,8,["model"]),l.value?p("",!0):(u(),g(s,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:R})),l.value?(u(),g(s,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=r=>ae())})):p("",!0),l.value?(u(),g(s,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=r=>oe())})):p("",!0),!l.value&&m(I)>1?(u(),h("div",Ee,[c(s,{icon:"pi pi-chevron-left",text:"",rounded:"",disabled:m(j)<=1,onClick:e[4]||(e[4]=r=>m(N)(-1)),title:"Précédent (Alt + ←)"},null,8,["disabled"]),n("span",Te,U(m(j))+" / "+U(m(I)),1),c(s,{icon:"pi pi-chevron-right",text:"",rounded:"",disabled:m(j)>=m(I),onClick:e[5]||(e[5]=r=>m(N)(1)),title:"Suivant (Alt + →)"},null,8,["disabled"])])):p("",!0)]),n("div",Se,[n("div",Le,[n("div",Fe,[c(Ie,{value:f.value.IdCategorie},null,8,["value"]),n("div",Re,[e[12]||(e[12]=n("label",{for:"inputFocus"},"Libellé",-1)),G(c(ce,{size:"small",id:"inputFocus",modelValue:f.value.Libelle,"onUpdate:modelValue":e[6]||(e[6]=r=>f.value.Libelle=r),class:"w-full",disabled:!d.value},null,8,["modelValue","disabled"]),[[pe,"categoriesbudget.Libelle"]])])])])])])):p("",!0)])),G(n("div",Ne,[n("div",Ve,[c(s,{icon:"pi pi-plus-circle",label:"Ajouter",text:"",onClick:e[7]||(e[7]=r=>L()),disabled:!i.ajout},null,8,["disabled"]),c(V,{ref_key:"listeMenu",ref:S,model:ee,popup:!0},{button:Ce(()=>[c(s,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[8]||(e[8]=r=>S.value.toggle(r))})]),_:1},512),c(s,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[9]||(e[9]=r=>m(B)("CategorieBudget"))})]),n("div",Ue,[c(De,{ref_key:"dataGrid",ref:k,"excel-file-name":"Categorie budget","excel-sheet-name":"Categorie budget","row-data":x.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{IdCategorie:200,Libelle:300},"enable-totals":!1,"show-checkbox":!1,"numeric-columns":[],onRowClicked:X,onSelectionChanged:Y,onGridReady:Z},null,8,["row-data"])])],512),[[we,i.lecture]]),$.value?(u(),g(de,{key:0,data:x.value,showModelSelector:!0,listeModelType:"Liste des catégories de budget",modeList:!0,onClose:e[10]||(e[10]=r=>$.value=!1)},null,8,["data"])):p("",!0)],64)}}};export{tt as default};
