import{_ as ae}from"./Imprimer-CqTc6qE9.js";import{r as s,f as ne,g as re,o as d,c as j,b as i,i as v,z as ue,d as m,j as x,a as r,av as ce,M as de,an as pe,ap as me,q as fe,S as ve,F as ge,ar as be,e as ye}from"./vendor-0kGcmQpG.js";import{u as we,a as y,s as o,S as F}from"./index-Bn9WoKhP.js";import"./ReportViewer-1Jmo7TFF.js";const $e={key:0},ke={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},xe={class:"w-full bg-white p-3"},Ce={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},he={class:"mb-3"},De={class:"p-float-label"},_e={class:"mb-3"},Re={class:"p-float-label"},Te={class:"w-full flex p-2 flex-row items-center gap-3"},Ae={class:"ag-theme-quartz",style:{height:"calc(100vh - 250px)",width:"100%"}},Fe={__name:"Region",props:{ndoc:{type:String,default:""}},setup(z){const{showError:g,showInfo:h,showWarn:E}=we(),N=z,c=s({}),V=s(null),b=s([]),f=s(!1),p=s(!1),a=s(!1),w=s(!1),$=s(!1),U=s(""),D=s(""),_=s(N.ndoc||""),B=s(null),k=s(null),R=s(null),T=s(null),n=be({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),L=[{label:"Supprimer",icon:"pi pi-trash",command:()=>le(),disabled:ye(()=>!n.supp)}],G=[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>Z()},{label:"Imprimer la liste",icon:"pi pi-print",command:()=>ee()}],q=s([{field:"IDRegion",headerName:"Numéro",sortable:!0,filter:"agTextColumnFilter",width:150,checkboxSelection:!0,headerCheckboxSelection:!1},{field:"libelle",headerName:"Libellé",sortable:!0,filter:"agTextColumnFilter",width:200}]),O=s({sortable:!0,filter:"agTextColumnFilter",floatingFilter:!1,resizable:!0,suppressHeaderMenuButton:!0}),P=s({mode:"singleRow",checkboxes:!1,enableClickSelection:!0});ne(async()=>{await H(),_.value?(te(),p.value=!0,a.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)):C()});const H=async()=>{try{const e=(await y.post(`${o.lienApi}/verifierDroit/${o.state.dbCommun6}`,{id_utilisateur:o.userId,id_page:1801,mail:o.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||(E("Vous n'avez pas le droit, veuillez consulter l'administrateur"),F("Region"))}catch(t){g("Une erreur s'est produite lors de la vérification des droits."+t)}},C=async()=>{o.state.afficher_in_progress=!0;try{f.value=!1,U.value=D.value;const t=await y.post(`${o.lienApi}/regions/${o.db}`,{condition:D.value},{headers:{"Content-Type":"application/json"}});b.value=t.data}catch(t){g(`Une erreur s'est produite lors du chargement des régions.
 ${t}`)}finally{o.state.afficher_in_progress=!1}},W=t=>{k.value=t.api,setTimeout(()=>{k.value&&b.value&&b.value.length>0&&k.value.sizeColumnsToFit()},100)},J=t=>{V.value=t.data},A=async()=>{try{const t=await y.post(`${o.lienApi}/AjouterEtRenvoyerregion/${o.db}`);c.value=t.data,f.value=!0,p.value=!0,a.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)}catch(t){g(`Une erreur s'est produite lors de l'ajout d'une région. ${t}`)}},K=async()=>{p.value=!0,a.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)},Q=async()=>{try{const t=`${o.lienApi}/enregistrerRegion/${o.db}/${c.value.IDRegion}`;await y.post(t,c.value,{headers:{"Content-Type":"application/json"}}),p.value=!1,a.value=!1}catch(t){const e=t.response?.data?.message||t.message;g(`Une erreur est survenue : ${e}`)}finally{o.state.afficher_in_progress=!1}},X=()=>{p.value=!1,a.value=!1},Y=()=>{f.value=!1,p.value=!1,a.value=!1,C()},Z=()=>{if(!k.value){h("Grille non initialisée");return}if(b.value.length===0){h("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");k.value.exportDataAsExcel({fileName:`Liste des régions_${o.state.enreg_societe.Nom}_${e}.xlsx`,sheetName:"Régions",exportedRows:"all",onlySelected:!1,suppressTextAsCDATA:!0})},ee=()=>{$.value=!0},te=async()=>{try{const t=await y.post(`${o.lienApi}/unregion/${o.db}/${_.value}`);c.value=t.data,f.value=!0}catch(t){g(`Une erreur s'est produite lors du chargement des détails de la région. ${t}`)}},le=async()=>{w.value=!0},se=async()=>{try{const t=`${o.lienApi}/supprimerRegion/${o.db}/${c.value.IDRegion}`;await y.post(t),f.value=!1,p.value=!1,w.value=!1,C()}catch(t){const e=t.response?.data?.message||t.message;g(`Une erreur est survenue :
 ${e}`)}};return(t,e)=>{const u=ue,S=ce,I=de,oe=re("ag-grid-vue"),M=ve,ie=ae;return d(),j(ge,null,[f.value&&n.lecture?(d(),j("div",$e,[i("div",ke,[a.value?m("",!0):(d(),v(u,{key:0,icon:"pi pi-pencil",label:"Modifier",onClick:e[0]||(e[0]=l=>K()),disabled:!n.modif},null,8,["disabled"])),a.value?m("",!0):(d(),v(u,{key:1,icon:"pi pi-plus-circle",label:"Ajouter",onClick:e[1]||(e[1]=l=>A())})),a.value?m("",!0):(d(),v(S,{key:2,ref_key:"actionsMenu",ref:R,model:L,popup:!0},{button:x(()=>[r(u,{icon:"pi pi-cog",label:"Actions",onClick:e[2]||(e[2]=l=>R.value.toggle(l))})]),_:1},512)),a.value?m("",!0):(d(),v(u,{key:3,icon:"pi pi-arrow-left",label:"Retour",onClick:e[3]||(e[3]=l=>Y())})),a.value?(d(),v(u,{key:4,icon:"pi pi-save",label:"Enregistrer",onClick:e[4]||(e[4]=l=>Q())})):m("",!0),a.value?(d(),v(u,{key:5,icon:"pi pi-times",label:"Annuler",onClick:e[5]||(e[5]=l=>X())})):m("",!0)]),i("div",xe,[i("div",Ce,[i("div",he,[i("span",De,[r(I,{size:"small",id:"idRegion",modelValue:c.value.IDRegion,"onUpdate:modelValue":e[6]||(e[6]=l=>c.value.IDRegion=l),class:"w-full",disabled:""},null,8,["modelValue"]),e[15]||(e[15]=i("label",{for:"idRegion"},"Numéro",-1))])]),i("div",_e,[i("span",Re,[r(I,{size:"small",id:"inputFocus",modelValue:c.value.libelle,"onUpdate:modelValue":e[7]||(e[7]=l=>c.value.libelle=l),class:"w-full",disabled:!p.value},null,8,["modelValue","disabled"]),e[16]||(e[16]=i("label",{for:"inputFocus"},"Libellé",-1))])])])])])):m("",!0),pe(i("div",null,[i("div",Te,[r(u,{icon:"pi pi-plus-circle",label:"Ajouter",text:"",onClick:e[8]||(e[8]=l=>A()),disabled:!n.ajout},null,8,["disabled"]),r(S,{ref_key:"listeMenu",ref:T,model:G,popup:!0},{button:x(()=>[r(u,{icon:"pi pi-cog",label:"Actions",onClick:e[9]||(e[9]=l=>T.value.toggle(l))})]),_:1},512),r(u,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[10]||(e[10]=l=>fe(F)("Region"))})]),i("div",Ae,[r(oe,{ref_key:"agGrid",ref:B,rowData:b.value,columnDefs:q.value,defaultColDef:O.value,theme:t.$agGridTheme,localeText:t.$agGridLocale,rowSelection:P.value,suppressRowClickSelection:!1,enableCellTextSelection:!0,onGridReady:W,onRowClicked:J,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["rowData","columnDefs","defaultColDef","theme","localeText","rowSelection"])])],512),[[me,!f.value&&n.lecture]]),r(M,{visible:w.value,"onUpdate:visible":e[12]||(e[12]=l=>w.value=l),style:{width:"450px"},header:"Confirmation",modal:!0},{footer:x(()=>[r(u,{label:"Non",icon:"pi pi-times",class:"p-button-text",onClick:e[11]||(e[11]=l=>w.value=!1)}),r(u,{label:"Oui",icon:"pi pi-check",class:"p-button-danger",onClick:se})]),default:x(()=>[e[17]||(e[17]=i("div",{class:"confirmation-content flex align-items-center"},[i("i",{class:"pi pi-exclamation-triangle mr-3",style:{"font-size":"2rem"}}),i("span",null,"Voulez-vous vraiment supprimer cette région?")],-1))]),_:1},8,["visible"]),r(M,{visible:$.value,"onUpdate:visible":e[14]||(e[14]=l=>$.value=l),style:{width:"80vw"},header:"Impression",modal:!0,closable:!0},{default:x(()=>[i("div",null,[$.value?(d(),v(ie,{key:0,data:b.value,showModelSelector:!0,listeModelType:"Liste des régions",modeList:!0,onClose:e[13]||(e[13]=l=>$.value=!1)},null,8,["data"])):m("",!0)])]),_:1},8,["visible"])],64)}}};export{Fe as default};
