import{r,f as X,o as v,c as E,b as a,i as x,z as Y,d as g,a as c,av as Z,M as ee,an as te,ap as se,q as le,F as ae,ar as oe}from"./vendor-0kGcmQpG.js";import{u as ie,a as b,s,S as C}from"./index-Bn9WoKhP.js";import{_ as ne}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const re={key:0},ue={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},ce={class:"justify-self-end ml-auto mr-3 font-bold text-xl"},de={class:"w-full bg-white p-3"},pe={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"},ve={class:"field"},me={class:"field"},fe={class:"field"},ge={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"},xe={class:"flex flex-wrap gap-2 sm:gap-3"},we={style:{height:"calc(100vh - 180px)",width:"100%"}},he={__name:"Niveau",props:["ndoc"],setup(T){const{confirmAction:D,showSuccess:U,showError:m,showInfo:w,showWarn:j}=ie(),y=T,_=r(y.ndoc),i=r({}),N=r([]),p=r(!1),$=r(null),d=r(!1),u=r(!1),h=r(),f=r(),B=r([]),F=({event:t,ndoc:e,rowIndex:l})=>{t?.target?.closest(".ag-selection-checkbox, .ag-checkbox, input")||(window.getSelection&&window.getSelection().removeAllRanges(),_.value=e,$.value=l,R())},z=({selectedRows:t})=>{B.value=t},L=t=>{f.value=t.api},V=r(""),G=r(""),S=r(!1),n=oe({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1});X(async()=>{await O(),y.ndoc?(R(),d.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)):k()});const O=async()=>{try{const e=(await b.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:1409,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(n.lecture=e.lecture,n.ajout=e.ajout,n.modif=e.modif,n.supp=e.supp,n.devalidation=e.devalidation,n.validation=e.validation),n.lecture||(j("Vous n'avez pas le droit, veuillez consulter l'administrateur"),C("Niveau"))}catch(t){m(`Une erreur s'est produite lors de la vérification des droits. ${t}`)}},k=async()=>{s.state.afficher_in_progress=!0;try{p.value=!1,V.value=G.value;const t=await b.post(`${s.lienApi}/Niveaux/${s.db}`,{condition:V.value});N.value=t.data.map(e=>({...e,ndoc:e.id_Niveau}))}catch(t){m(`Une erreur est survenue lors de l'affichage des niveaux ${t}`)}finally{s.state.afficher_in_progress=!1}},M=async()=>{try{const t=await b.post(`${s.lienApi}/AjouterEtRenvoyerniveau/${s.db}`);i.value=t.data,_.value=i.value.id_Niveau,p.value=!0,d.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch(t){m(`Une erreur est survenue lors de l'ajout d'un niveau
 ${t}`)}},q=async()=>{try{if(!i.value.Nom){j("Le nom est obligatoire");return}await b.post(`${s.lienApi}/enregistrerNiveau/${s.db}/${i.value.id_Niveau}`,i.value,{headers:{"Content-Type":"application/json"}}),d.value=!1,u.value=!1}catch(t){const e=t.response?.data?.message||t.message;m("Une erreur est survenue : "+e)}finally{s.state.afficher_in_progress=!1}},P=()=>{d.value=!1,u.value=!1},W=()=>{if(!h.value){w("Grille non initialisée");return}if(N.value.length===0){w("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");h.value.exportToExcel(`Liste des niveaux_${s.state.enreg_societe.Nom}_${e}.xlsx`)},H=()=>{w("Impression de la liste en cours...")},R=async()=>{try{const t=await b.post(`${s.lienApi}/unNiveau/${s.db}/${_.value}`);i.value=t.data,p.value=!0}catch(t){m(`Une erreur est survenue lors de l'affichage des détails du niveau ${t}`)}},J=async()=>{d.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},K=async()=>{if(await D({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${s.lienApi}/supprimerNiveau/${s.db}/${i.value.id_Niveau}`;await b.post(e),p.value=!1,d.value=!1,k(),U("Suppression effectuée avec succès")}catch(e){const l=e.response?.data?.message||e.message;m("Une erreur est survenue : "+l)}},Q=()=>{y.ndoc?C("Niveau"):(p.value=!1,k(),$.value!=null&&f.value&&setTimeout(()=>{const t=f.value.getDisplayedRowCount();if(t>0){const e=Math.min($.value,t-1),l=f.value.getDisplayedRowAtIndex(e);l&&(f.value.deselectAll(),l.setSelected(!0),f.value.ensureNodeVisible(l,"middle"))}},100))};return(t,e)=>{const l=Y,I=Z,A=ee;return v(),E(ae,null,[p.value&&n.lecture?(v(),E("div",re,[a("div",ue,[u.value?g("",!0):(v(),x(l,{key:0,onClick:e[0]||(e[0]=o=>J()),icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!n.modif},null,8,["disabled"])),u.value?g("",!0):(v(),x(l,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=o=>t.$refs.actionsMenu.toggle(o)),text:""})),c(I,{ref:"actionsMenu",model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:M,disabled:!n.ajout},{label:"Supprimer",icon:"pi pi-trash",command:K,disabled:!n.supp,class:"text-red-500"}],popup:!0},null,8,["model"]),u.value?g("",!0):(v(),x(l,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:Q})),u.value?(v(),x(l,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=o=>q())})):g("",!0),u.value?(v(),x(l,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=o=>P())})):g("",!0),a("div",ce,[c(l,{icon:"pi pi-paperclip",text:"",class:"p-button-rounded",onClick:e[4]||(e[4]=o=>S.value=!S.value)})])]),a("div",de,[a("div",pe,[a("div",ve,[e[10]||(e[10]=a("label",{for:"id_niveau",class:"block mb-1"},"Numéro",-1)),c(A,{size:"small",id:"id_niveau",modelValue:i.value.id_Niveau,"onUpdate:modelValue":e[5]||(e[5]=o=>i.value.id_Niveau=o),class:"w-full",disabled:""},null,8,["modelValue"])]),a("div",me,[e[11]||(e[11]=a("label",{for:"inputFocus",class:"block mb-1"},"Nom",-1)),c(A,{size:"small",id:"inputFocus",modelValue:i.value.Nom,"onUpdate:modelValue":e[6]||(e[6]=o=>i.value.Nom=o),disabled:!d.value,class:"w-full"},null,8,["modelValue","disabled"])]),a("div",fe,[e[12]||(e[12]=a("label",{for:"nomenclature",class:"block mb-1"},"Nomenclature",-1)),c(A,{size:"small",id:"nomenclature",modelValue:i.value.Nomenclature,"onUpdate:modelValue":e[7]||(e[7]=o=>i.value.Nomenclature=o),disabled:!d.value,class:"w-full"},null,8,["modelValue","disabled"])])])])])):g("",!0),te(a("div",null,[a("div",ge,[a("div",be,[a("div",xe,[c(l,{icon:"pi pi-plus",label:"Ajouter",onClick:M,text:"",disabled:!n.ajout},null,8,["disabled"]),c(l,{label:"Actions",icon:"pi pi-cog",onClick:e[8]||(e[8]=o=>t.$refs.actionsMenuList.toggle(o)),text:""}),c(I,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:W},{label:"Imprimer la liste",icon:"pi pi-print",command:H}],popup:!0},null,8,["model"]),c(l,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[9]||(e[9]=o=>le(C)("Niveau"))})])])]),a("div",we,[c(ne,{ref_key:"dataGrid",ref:h,"excel-file-name":"Niveaux","excel-sheet-name":"Niveaux","row-data":N.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{id_Niveau:120,Nom:200,Nomenclature:200},"enable-totals":!0,"show-checkbox":!1,onRowClicked:F,onSelectionChanged:z,onGridReady:L},null,8,["row-data"])])],512),[[se,!p.value&&n.lecture]])],64)}}};export{he as default};
