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