import{r,f as Z,o as v,c as E,b as o,i as w,z as ee,d as g,a as u,av as se,M as te,an as le,ap as oe,q as ie,F as ae,ar as ne}from"./vendor-0kGcmQpG.js";import{u as re,a as b,s as t,S as C}from"./index-Bn9WoKhP.js";import{_ as ce}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const ue={key:0},de={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},pe={class:"justify-self-end ml-auto mr-3 font-bold text-xl"},ve={class:"w-full bg-white p-3"},me={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"},fe={class:"field"},ge={class:"field"},be={class:"field"},we={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center"},_e={class:"flex flex-col gap-2 sm:flex-row sm:gap-3"},xe={class:"flex flex-wrap gap-2 sm:gap-3"},ye={style:{height:"calc(100vh - 200px)"}},Ae={__name:"Services",props:["ndoc"],setup(T){const{confirmAction:D,showSuccess:U,showError:m,showInfo:_,showWarn:j}=re(),x=T,y=r(x.ndoc),a=r({}),$=r([]),p=r(!1),h=r(null),d=r(!1),c=r(!1),k=r(null),B=["id_service","Nom","code_comptable"],F={id_service:120,Nom:200,code_comptable:150},V=r(""),z=r(""),M=r(!1),n=ne({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1});Z(async()=>{await L(),x.ndoc?(I(),d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)):S()});const L=async()=>{try{const e=(await b.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:1406,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||(j("Vous n'avez pas le droit, veuillez consulter l'administrateur"),C("Services"))}catch(s){m(`Une erreur s'est produite lors de la vérification des droits. ${s}`)}},S=async()=>{t.state.afficher_in_progress=!0;try{p.value=!1,V.value=z.value;const s=await b.post(`${t.lienApi}/services/${t.db}`,{condition:V.value});$.value=s.data.map(e=>({...e,ndoc:e.id_service}))}catch(s){m(`Une erreur est survenue lors de l'affichage des services ${s}`)}finally{t.state.afficher_in_progress=!1}},R=async()=>{try{const s=await b.post(`${t.lienApi}/AjouterEtRenvoyerservice/${t.db}`);a.value=s.data,y.value=a.value.id_service,p.value=!0,d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch(s){m(`Une erreur est survenue lors de l'ajout d'un service
 ${s}`)}},G=async()=>{try{if(!a.value.Nom){j("Le nom du service est obligatoire");return}const s=`${t.lienApi}/enregistrerService/${t.db}/${a.value.id_service}`;await b.post(s,a.value,{headers:{"Content-Type":"application/json"}}),d.value=!1,c.value=!1}catch(s){const e=s.response?.data?.message||s.message;m("Une erreur est survenue : "+e)}finally{t.state.afficher_in_progress=!1}},O=()=>{d.value=!1,c.value=!1},W=()=>{if(!k.value){_("Grille non initialisée");return}if($.value.length===0){_("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");k.value.exportToExcel(`Liste des services_${t.state.enreg_societe.Nom}_${e}.xlsx`)},q=()=>{_("Impression de la liste en cours...")},I=async()=>{try{const s=await b.post(`${t.lienApi}/unservice/${t.db}/${y.value}`);a.value=s.data,p.value=!0}catch(s){m(`Une erreur est survenue lors de l'affichage des détails du service ${s}`)}},P=async()=>{d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},H=async()=>{if(await D({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${t.lienApi}/supprimerService/${t.db}/${a.value.id_service}`;await b.post(e),p.value=!1,d.value=!1,S(),U("Suppression effectuée avec succès")}catch(e){const l=e.response?.data?.message||e.message;m("Une erreur est survenue : "+l)}},f=r(),J=r([]),K=s=>{f.value=s.api},Q=({event:s,ndoc:e,rowIndex:l})=>{s?.target?.closest(".ag-selection-checkbox, .ag-checkbox, input")||(window.getSelection&&window.getSelection().removeAllRanges(),y.value=e,h.value=l,I())},X=({selectedRows:s})=>{J.value=s},Y=()=>{x.ndoc?C("Services"):(p.value=!1,S(),h.value!=null&&f.value&&setTimeout(()=>{const s=f.value.getDisplayedRowCount();if(s>0){const e=Math.min(h.value,s-1),l=f.value.getDisplayedRowAtIndex(e);l&&(f.value.deselectAll(),l.setSelected(!0),f.value.ensureNodeVisible(l,"middle"))}},100))};return(s,e)=>{const l=ee,N=se,A=te;return v(),E(ae,null,[p.value&&n.lecture?(v(),E("div",ue,[o("div",de,[c.value?g("",!0):(v(),w(l,{key:0,onClick:e[0]||(e[0]=i=>P()),icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!n.modif},null,8,["disabled"])),c.value?g("",!0):(v(),w(l,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=i=>s.$refs.actionsMenu.toggle(i)),text:""})),u(N,{ref:"actionsMenu",model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:R,disabled:!n.ajout},{label:"Supprimer",icon:"pi pi-trash",command:H,disabled:!n.supp,class:"text-red-500"}],popup:!0},null,8,["model"]),c.value?g("",!0):(v(),w(l,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:Y})),c.value?(v(),w(l,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=i=>G())})):g("",!0),c.value?(v(),w(l,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=i=>O())})):g("",!0),o("div",pe,[u(l,{icon:"pi pi-paperclip",text:"",class:"p-button-rounded",onClick:e[4]||(e[4]=i=>M.value=!M.value)})])]),o("div",ve,[o("div",me,[o("div",fe,[e[10]||(e[10]=o("label",{for:"id_service",class:"block mb-1"},"Numéro",-1)),u(A,{size:"small",id:"id_service",modelValue:a.value.id_service,"onUpdate:modelValue":e[5]||(e[5]=i=>a.value.id_service=i),class:"w-full",disabled:""},null,8,["modelValue"])]),o("div",ge,[e[11]||(e[11]=o("label",{for:"inputFocus",class:"block mb-1"},"Nom",-1)),u(A,{size:"small",id:"inputFocus",modelValue:a.value.Nom,"onUpdate:modelValue":e[6]||(e[6]=i=>a.value.Nom=i),disabled:!d.value,class:"w-full"},null,8,["modelValue","disabled"])]),o("div",be,[e[12]||(e[12]=o("label",{for:"code_comptable",class:"block mb-1"},"Code Comptable",-1)),u(A,{size:"small",id:"code_comptable",modelValue:a.value.code_comptable,"onUpdate:modelValue":e[7]||(e[7]=i=>a.value.code_comptable=i),disabled:!d.value,class:"w-full"},null,8,["modelValue","disabled"])])])])])):g("",!0),le(o("div",null,[o("div",we,[o("div",_e,[o("div",xe,[u(l,{icon:"pi pi-plus",label:"Ajouter",onClick:R,text:"",disabled:!n.ajout},null,8,["disabled"]),u(l,{label:"Actions",icon:"pi pi-cog",onClick:e[8]||(e[8]=i=>s.$refs.actionsMenuList.toggle(i)),text:""}),u(N,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:W},{label:"Imprimer la liste",icon:"pi pi-print",command:q}],popup:!0},null,8,["model"]),u(l,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[9]||(e[9]=i=>ie(C)("Services"))})])])]),o("div",ye,[u(ce,{ref_key:"agGrid",ref:k,"excel-file-name":"Services","excel-sheet-name":"Services","row-data":$.value,"document-number-fields":["ndoc"],"column-order":B,"column-widths":F,"hidden-columns":["id_service"],"enable-totals":!1,onGridReady:K,onRowClicked:Q,onSelectionChanged:X},null,8,["row-data"])])],512),[[oe,!p.value&&n.lecture]])],64)}}};export{Ae as default};
