import{r as o,f as K,o as f,c as R,b as a,i as w,z as Q,d as g,a as u,av as X,M as Y,an as Z,ap as ee,q as le,F as te,ar as se}from"./vendor-0kGcmQpG.js";import{u as ae,a as b,s as t,S as C}from"./index-Bn9WoKhP.js";import{_ as ie}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const oe={key:0},ne={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},re={class:"w-full bg-white p-3"},ce={class:"grid grid-cols-1 lg:grid-cols-2 gap-4"},ue={class:"flex flex-col gap-2"},de={class:"field"},pe={class:"field"},fe={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center"},me={class:"flex flex-col gap-2 sm:flex-row sm:gap-3 lg:w-1/2 lg:justify-start"},ve={class:"flex flex-wrap gap-2 sm:gap-3"},ge={style:"height: calc(100vh - 200px)"},ye={__name:"FamilleClient",props:["ndoc"],setup(V){const{confirmAction:E,showError:m,showInfo:x,showWarn:T}=ae(),_=V,A=o(_.ndoc),c=o({}),y=o([]),d=o(!1),h=o(null),p=o(!1),n=o(!1),I=o(""),S=o(""),$=o(),v=o(),B=o([]),i=se({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),U=({event:l,ndoc:e,rowIndex:s})=>{A.value=e,h.value=s,F()},z=({selectedRows:l})=>{B.value=l},L=l=>{v.value=l.api};K(async()=>{await N(),_.ndoc?(F(),p.value=!0,n.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)):k()});const N=async()=>{try{const e=(await b.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:208,mail:t.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(i.lecture=e.lecture,i.ajout=e.ajout,i.modif=e.modif,i.supp=e.supp,i.devalidation=e.devalidation,i.validation=e.validation),i.lecture||(T("Vous n'avez pas le droit, veuillez consulter l'administrateur"),C("FamilleClient"))}catch(l){m(`Une erreur s'est produite lors de la vérification des droits. ${l}`)}},k=async()=>{t.state.afficher_in_progress=!0;try{d.value=!1,I.value=S.value;const l=await b.post(`${t.lienApi}/famille_client/${t.db}`,{condition:I.value},{headers:{"Content-Type":"application/json"}});y.value=l.data}catch(l){m(`Une erreur est survenue lors de l'affichage des familles clients
 ${l}`)}finally{t.state.afficher_in_progress=!1}},j=async()=>{try{const l=await b.post(`${t.lienApi}/AjouterEtRenvoyerFamille_client/${t.db}`);c.value=l.data,d.value=!0,p.value=!0,n.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch(l){m(`Une erreur est survenue lors de l'ajout de la famille client
 ${l}`)}finally{t.state.afficher_in_progress=!1}},G=async()=>{p.value=!0,n.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},O=async()=>{try{const l=`${t.lienApi}/enregistrerFamille_client/${t.db}/${c.value.IDfamille_client}`;await b.post(l,c.value,{headers:{"Content-Type":"application/json"}}),p.value=!1,n.value=!1}catch(l){const e=l.response?.data?.message||l.message;m("Une erreur est survenue : "+e)}finally{t.state.afficher_in_progress=!1}},q=()=>{p.value=!1,n.value=!1},P=()=>{if(!$.value){x("Grille non initialisée");return}if(y.value.length===0){x("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");$.value.exportToExcel(`Liste des familles clients_${t.state.enreg_societe.Nom}_${e}.xlsx`)},W=()=>{x("Impression de la liste en cours...")},F=async()=>{try{const l=await b.post(`${t.lienApi}/unfamille_client/${t.db}/${A.value}`);c.value=l.data,d.value=!0}catch(l){m(`Une erreur est survenue lors de l'affichage des détails de la famille client
 ${l}`)}finally{t.state.afficher_in_progress=!1}},H=async()=>{if(await E({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${t.lienApi}/supprimerFamille_client/${t.db}/${c.value.IDfamille_client}`;await b.post(e),d.value=!1,p.value=!1,k()}catch(e){const s=e.response?.data?.message||e.message;m("Une erreur est survenue : "+s)}},J=()=>{_.ndoc?C("FamilleClient"):(d.value=!1,k(),h.value!=null&&v.value&&setTimeout(()=>{const l=v.value.getDisplayedRowCount();if(l>0){const e=Math.min(h.value,l-1),s=v.value.getDisplayedRowAtIndex(e);s&&(v.value.deselectAll(),s.setSelected(!0),v.value.ensureNodeVisible(s,"middle"))}},100))};return(l,e)=>{const s=Q,D=X,M=Y;return f(),R(te,null,[d.value&&i.lecture?(f(),R("div",oe,[a("div",ne,[n.value?g("",!0):(f(),w(s,{key:0,onClick:G,icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!i.modif},null,8,["disabled"])),n.value?g("",!0):(f(),w(s,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[0]||(e[0]=r=>l.$refs.actionsMenu.toggle(r)),text:""})),u(D,{ref:"actionsMenu",model:[{label:"Supprimer",icon:"pi pi-trash",command:H,disabled:!i.supp,class:"text-red-500"},{label:"Ajouter",icon:"pi pi-plus-circle",command:j,disabled:!i.ajout}],popup:!0},null,8,["model"]),n.value?g("",!0):(f(),w(s,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:J})),n.value?(f(),w(s,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[1]||(e[1]=r=>O())})):g("",!0),n.value?(f(),w(s,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[2]||(e[2]=r=>q())})):g("",!0)]),a("div",re,[a("div",ce,[a("div",ue,[a("div",de,[e[7]||(e[7]=a("label",{for:"IDfamille_client",class:"block mb-1"},"Numéro",-1)),u(M,{size:"small",id:"IDfamille_client",modelValue:c.value.IDfamille_client,"onUpdate:modelValue":e[3]||(e[3]=r=>c.value.IDfamille_client=r),class:"w-full",disabled:""},null,8,["modelValue"])]),a("div",pe,[e[8]||(e[8]=a("label",{for:"inputFocus",class:"block mb-1"},"Libellé",-1)),u(M,{size:"small",id:"inputFocus",modelValue:c.value.libelle,"onUpdate:modelValue":e[4]||(e[4]=r=>c.value.libelle=r),disabled:!p.value,class:"w-full"},null,8,["modelValue","disabled"])])]),e[9]||(e[9]=a("div",{class:"flex flex-col gap-2"},null,-1))])])])):g("",!0),Z(a("div",null,[a("div",fe,[a("div",me,[a("div",ve,[u(s,{icon:"pi pi-plus",label:"Ajouter",onClick:j,text:"",disabled:!i.ajout},null,8,["disabled"]),u(s,{label:"Actions",icon:"pi pi-cog",onClick:e[5]||(e[5]=r=>l.$refs.actionsMenuList.toggle(r)),text:""}),u(s,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[6]||(e[6]=r=>le(C)("FamilleClient"))}),u(D,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:P},{label:"Imprimer la liste",icon:"pi pi-print",command:W}],popup:!0},null,8,["model"])])]),e[10]||(e[10]=a("div",{class:"flex items-center gap-3 lg:w-1/2 lg:justify-end whitespace-nowrap"},null,-1))]),a("div",ge,[u(ie,{ref_key:"dataGrid",ref:$,"excel-file-name":"Famille client","excel-sheet-name":"Famille client","row-data":y.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc","IDfamille_client"],"column-widths":{libelle:300},onRowClicked:U,onSelectionChanged:z,onGridReady:L},null,8,["row-data"])])],512),[[ee,!d.value&&i.lecture]])],64)}}};export{ye as default};
