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