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