import{f as H,o as u,c as _,an as J,ap as K,b as l,a as f,z as O,q as P,j as Q,av as W,i as y,d as m,M as X,F as Y,r as o}from"./vendor-0kGcmQpG.js";import{_ as Z}from"./DataGrid-tb6QVwpZ.js";import{u as ee,s as a,a as g,S as te}from"./index-Bn9WoKhP.js";import"./useAgGridConfig-DjXMc6wb.js";const se={class:"flex flex-col"},ae={class:"flex flex-row justify-start gap-3"},oe={style:{height:"calc(100vh - 150px)"}},le={key:0},ie={class:"w-full flex flex-wrap items-start md:flex-row justify-start gap-3"},ne={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},re={class:"h-full bg-white p-3"},ce={class:"w-full flex flex-col md:flex-row md:justify-start md:items-center gap-3"},ue={class:"md:w-2/3"},de={class:"p-float-label"},ge={__name:"Localisation",setup(pe){const{confirmAction:$,showSuccess:k,showError:v,showInfo:L}=ee(),C=o(),j=o(),d=o(),c=o({}),A=o(null),h=o([]),r=o(!1),b=o(null),p=o(!1),i=o(!1),x=o(""),M=t=>{d.value=t.api},E=({selectedRows:t})=>{A.value=t&&t.length>0?t[0]:null},I=({ndoc:t,rowIndex:e})=>{x.value=t,b.value=e,D()},R=o({ajout:!0}),S=[{label:"Imprimer la liste",icon:"pi pi-print",command:()=>z()}];H(async()=>{await w()});const w=async()=>{a.state.afficher_in_progress=!0;try{r.value=!1;const t=await g.post(`${a.lienApi}/Localisation/${a.db}`,{},{headers:{"Content-Type":"application/json"}});h.value=t.data}catch{v("Une erreur est survenue lors de l'affichage des localisations")}finally{a.state.afficher_in_progress=!1}},D=async()=>{try{const t=await g.post(`${a.lienApi}/unLocalisation/${a.db}/${x.value}`);c.value=t.data,r.value=!0}catch{v("Une erreur est survenue lors de l'affichage des détails")}},F=async()=>{try{const t=`${a.lienApi}/enregistrerLocalisation/${a.db}/${c.value.IDLocalisation}`;await g.post(t,c.value,{headers:{"Content-Type":"application/json"}}),r.value=!1,p.value=!1,i.value=!1,w()}catch(t){const e=t.response?.data?.message||t.message;v(`Une erreur est survenue : ${e}`)}finally{a.state.afficher_in_progress=!1}},T=()=>{p.value=!1,i.value=!1},V=()=>{r.value=!1,w(),b.value!=null&&d.value&&setTimeout(()=>{const t=d.value.getDisplayedRowCount();if(t>0){const e=Math.min(b.value,t-1),s=d.value.getDisplayedRowAtIndex(e);s&&(d.value.deselectAll(),s.setSelected(!0),d.value.ensureNodeVisible(s,"middle"))}},100)},B=async()=>{if(await $({message:"Voulez-vous vraiment supprimer cette localisation ?"}))try{const e=`${a.lienApi}/supprimerLocalisation/${a.db}/${c.value.IDLocalisation}`;await g.post(e),r.value=!1,p.value=!1,await w(),k("Localisation supprimée avec succès")}catch(e){const s=e.response?.data?.message||e.message;v(`Une erreur est survenue : ${s}`)}},U=async()=>{try{const t=await g.post(`${a.lienApi}/AjouterEtRenvoyerLocalisation/${a.db}`);c.value=t.data,r.value=!0,p.value=!0,i.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch{v("Une erreur est survenue lors de l'ajout")}},N=async()=>{p.value=!0,i.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},z=()=>{L("Fonctionnalité d'impression à implémenter")};return(t,e)=>{const s=O,G=W,q=X;return u(),_(Y,null,[J(l("div",se,[l("div",ae,[f(s,{text:"",icon:"pi pi-plus-circle",label:"Ajouter",onClick:e[0]||(e[0]=n=>U()),disabled:!R.value?.ajout},null,8,["disabled"]),f(s,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=n=>P(te)("Localisation"))}),f(G,{ref_key:"actionsMenu",ref:C,model:S,popup:!0},{activator:Q(({open:n})=>[f(s,{text:"",icon:"pi pi-cog",label:"Actions",onClick:n},null,8,["onClick"])]),_:1},512)]),l("div",oe,[f(Z,{ref_key:"gridListe",ref:j,"excel-file-name":"Localisations","excel-sheet-name":"Localisations","row-data":h.value,"document-number-fields":["ndoc"],"column-widths":{Libelle:400},"enable-totals":!1,"show-checkbox":!1,onGridReady:M,onSelectionChanged:E,onRowClicked:I},null,8,["row-data"])])],512),[[K,!r.value]]),r.value?(u(),_("div",le,[l("div",null,[l("div",ie,[i.value?m("",!0):(u(),y(s,{key:0,onClick:e[2]||(e[2]=n=>N()),text:"",icon:"pi pi-pencil",label:"Modifier"})),i.value?m("",!0):(u(),y(s,{key:1,text:"",icon:"pi pi-trash",label:"Supprimer",onClick:e[3]||(e[3]=n=>B())})),i.value?m("",!0):(u(),y(s,{key:2,text:"",icon:"pi pi-arrow-left",label:"Retour",onClick:V}))]),l("div",ne,[i.value?(u(),y(s,{key:0,text:"",icon:"pi pi-save",label:"Enregistrer",class:"p-button-primary",onClick:e[4]||(e[4]=n=>F())})):m("",!0),i.value?(u(),y(s,{key:1,text:"",icon:"pi pi-times",label:"Annuler",class:"p-button-secondary",onClick:e[5]||(e[5]=n=>T())})):m("",!0)]),l("div",re,[l("div",ce,[l("div",ue,[l("span",de,[e[7]||(e[7]=l("label",{for:"inputFocus"},"Localisation",-1)),f(q,{size:"small",id:"inputFocus",modelValue:c.value.Libelle_loca,"onUpdate:modelValue":e[6]||(e[6]=n=>c.value.Libelle_loca=n),disabled:!p.value,class:"w-full"},null,8,["modelValue","disabled"])])])])])])])):m("",!0)],64)}}};export{ge as default};
