import{u as ee,a as g,s as t,S as k,g as se}from"./index-Bn9WoKhP.js";import{r,f as te,o as m,c as S,b as l,i as w,z as le,d as b,a as d,av as oe,M as ae,an as ie,ap as ne,q as re,F as ue,ar as de,e as T}from"./vendor-0kGcmQpG.js";import{_ as ce}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const pe={key:0},me={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},fe={class:"w-full bg-white p-3"},ve={class:"grid grid-cols-1 lg:grid-cols-2 gap-4"},ge={class:"flex flex-col gap-2"},be={class:"p-float-label"},we={class:"p-float-label"},xe={class:"flex flex-col gap-2"},ye={class:"p-float-label"},_e={class:"p-float-label"},$e={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center mb-3"},he={class:"flex flex-col gap-2 sm:flex-row sm:gap-3 lg:w-1/2 lg:justify-start"},ke={class:"flex flex-wrap gap-2 sm:gap-3"},Ae={style:{height:"calc(100vh - 200px)"}},De={__name:"GroupeDeRemise",props:["ndoc"],setup(U){const{confirmAction:F,showSuccess:A,showError:f,showInfo:R,showWarn:C}=ee(),x=U,V=r(x.ndoc),i=r({}),y=r([]),p=r(!1),_=r(null),c=r(!1),u=r(!1),j=r(""),z=r(""),$=r(),v=r(),B=r([]),n=de({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),N=({event:s,ndoc:e,rowIndex:o})=>{V.value=e,_.value=o,M()},L=({selectedRows:s})=>{B.value=s},O=s=>{v.value=s.api},P=T(()=>[{label:"Ajouter",icon:"pi pi-plus-circle",command:D,disabled:!n.ajout},{label:"Supprimer",icon:"pi pi-trash",command:Y,disabled:!n.supp,class:"text-red-500"}]),q=T(()=>[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:Q},{label:"Imprimer la liste",icon:"pi pi-print",command:X}]);te(async()=>{await W(),x.ndoc?(M(),c.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)):h()});const W=async()=>{try{const e=(await g.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:217,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||(C("Vous n'avez pas le droit, veuillez consulter l'administrateur"),k("GroupeDeRemise"))}catch(s){f(`Une erreur s'est produite lors de la vérification des droits. ${s}`)}},h=async()=>{t.state.afficher_in_progress=!0;try{p.value=!1,j.value=z.value;const s=await g.post(`${t.lienApi}/Groupe_Remise/${t.db}`,{condition:j.value},{headers:{"Content-Type":"application/json"}});y.value=s.data}catch(s){f(`Une erreur est survenue lors de l'affichage des groupes de remise
 ${s}`)}finally{t.state.afficher_in_progress=!1}},D=async()=>{try{const s=await g.post(`${t.lienApi}/AjouterEtRenvoyerGroupe_Remise/${t.db}`);i.value=s.data,p.value=!0,c.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)}catch(s){f(`Une erreur est survenue lors de l'ajout du groupe de remise
 ${s}`)}finally{t.state.afficher_in_progress=!1}},H=async()=>{c.value=!0,u.value=!0,setTimeout(()=>{document.getElementById("inputFocus")?.focus()},200)},J=async()=>{try{const s=`${t.lienApi}/enregistrerGroupe_Remise/${t.db}/${i.value.ngroupe}`;await g.post(s,i.value,{headers:{"Content-Type":"application/json"}}),c.value=!1,u.value=!1,A("Enregistrement réussi")}catch(s){const e=s.response?.data?.message||s.message;f("Une erreur est survenue : "+e)}},K=()=>{c.value=!1,u.value=!1},Q=()=>{if(!$.value){R("Grille non initialisée");return}if(y.value.length===0){R("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");$.value.exportToExcel(`Liste des groupes de remise_${t.state.enreg_societe.Nom}_${e}.xlsx`)},X=()=>{C("La fonction d'impression n'est pas encore implémentée.")},M=async()=>{try{const s=await g.post(`${t.lienApi}/unGroupe_Remise/${t.db}/${V.value}`);i.value=s.data,p.value=!0}catch(s){f(`Une erreur est survenue lors de l'affichage des détails du groupe de remise
 ${s}`)}finally{t.state.afficher_in_progress=!1}},Y=async()=>{if(await F({message:"Voulez-vous vraiment supprimer ce groupe de remise ?"}))try{const e=`${t.lienApi}/supprimerGroupe_Remise/${t.db}/${i.value.ngroupe}`;await g.post(e),A("Suppression réussie"),p.value=!1,c.value=!1,h()}catch(e){const o=e.response?.data?.message||e.message;f("Une erreur est survenue : "+o)}},Z=()=>{x.ndoc?k("GroupeDeRemise"):(p.value=!1,h(),_.value!=null&&v.value&&setTimeout(()=>{const s=v.value.getDisplayedRowCount();if(s>0){const e=Math.min(_.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=le,G=oe,I=ae,E=se;return m(),S(ue,null,[p.value&&n.lecture?(m(),S("div",pe,[l("div",me,[u.value?b("",!0):(m(),w(o,{key:0,onClick:e[0]||(e[0]=a=>H()),icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!n.modif},null,8,["disabled"])),u.value?b("",!0):(m(),w(o,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=a=>s.$refs.actionsMenu.toggle(a)),text:""})),d(G,{ref:"actionsMenu",model:P.value,popup:!0},null,8,["model"]),u.value?b("",!0):(m(),w(o,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:Z})),u.value?(m(),w(o,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=a=>J())})):b("",!0),u.value?(m(),w(o,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=a=>K())})):b("",!0)]),l("div",fe,[l("div",ve,[l("div",ge,[l("span",be,[e[10]||(e[10]=l("label",{for:"ngroupe"},"Numéro",-1)),d(I,{size:"small",id:"ngroupe",modelValue:i.value.ngroupe,"onUpdate:modelValue":e[4]||(e[4]=a=>i.value.ngroupe=a),class:"w-full",disabled:""},null,8,["modelValue"])]),l("span",we,[e[11]||(e[11]=l("label",{for:"inputFocus"},"Libellé",-1)),d(I,{size:"small",id:"inputFocus",modelValue:i.value.libelle,"onUpdate:modelValue":e[5]||(e[5]=a=>i.value.libelle=a),disabled:!c.value,class:"w-full"},null,8,["modelValue","disabled"])])]),l("div",xe,[l("span",ye,[e[12]||(e[12]=l("label",{for:"datedebut"},"Date Debut",-1)),d(E,{size:"small",modelValue:i.value.datedebut,"onUpdate:modelValue":e[6]||(e[6]=a=>i.value.datedebut=a),disabled:!c.value,"input-class":"w-full"},null,8,["modelValue","disabled"])]),l("span",_e,[e[13]||(e[13]=l("label",{for:"datefin"},"Date Fin",-1)),d(E,{size:"small",modelValue:i.value.datefin,"onUpdate:modelValue":e[7]||(e[7]=a=>i.value.datefin=a),disabled:!c.value,"input-class":"w-full"},null,8,["modelValue","disabled"])])])])])])):b("",!0),ie(l("div",null,[l("div",$e,[l("div",he,[l("div",ke,[d(o,{icon:"pi pi-plus",label:"Ajouter",onClick:D,text:"",disabled:!n.ajout},null,8,["disabled"]),d(G,{ref:"listeActionsMenu",popup:!0,model:q.value},null,8,["model"]),d(o,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[8]||(e[8]=a=>s.$refs.listeActionsMenu.toggle(a))}),d(o,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[9]||(e[9]=a=>re(k)("groupeDeRemise"))})])]),e[14]||(e[14]=l("div",{class:"flex items-center gap-3 lg:w-1/2 lg:justify-end whitespace-nowrap"},null,-1))]),l("div",Ae,[d(ce,{ref_key:"dataGrid",ref:$,"excel-file-name":"Groupe de remise","excel-sheet-name":"Groupe de remise","row-data":y.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc","ngroupe"],"column-widths":{libelle:250,datedebut:150,datefin:150},onRowClicked:N,onSelectionChanged:L,onGridReady:O},null,8,["row-data"])])],512),[[ne,!p.value&&n.lecture]])],64)}}};export{De as default};
