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