import{_ as W}from"./ComboDynamique-DbhbUtR4.js";import{r as c,f as H,o as p,c as R,b as t,i as _,z as J,d as b,a as r,av as K,M as P,an as Q,ap as X,q as Y,F as Z,ar as ee}from"./vendor-BDR7yMJi.js";import{u as le,a as g,s as o,S as y}from"./index-BSaHX2oa.js";import{_ as se}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const te={key:0},oe={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},ae={class:"w-full bg-white p-3"},ie={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"},ne={class:"field"},re={class:"field"},ue={class:"field"},de={class:"field"},ce={class:"field"},me={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center"},pe={class:"flex flex-col gap-2 sm:flex-row sm:gap-3"},fe={class:"flex flex-wrap gap-2 sm:gap-3"},ve={style:{height:"calc(100vh - 180px)",width:"100%"}},ye={__name:"SitesCommercial",props:["ndoc"],setup(D){const{confirmAction:U,showSuccess:V,showError:f,showWarn:w}=le(),x=D,$=c(x.ndoc),s=c({}),k=c([]),m=c(!1),S=c(null),u=c(!1),d=c(!1),C=c(),v=c(),n=ee({lecture:!1,ajout:!1,modif:!1,supp:!1}),N=({event:l,ndoc:e,rowIndex:i})=>{l?.target?.closest(".ag-selection-checkbox, .ag-checkbox, input")||(window.getSelection&&window.getSelection().removeAllRanges(),$.value=e,S.value=i,j())},T=l=>{v.value=l.api};H(async()=>{await B(),x.ndoc?(j(),u.value=!0,d.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)):I()});const B=async()=>{try{const e=(await g.post(`${o.lienApi}/verifierDroit/${o.state.dbCommun6}`,{id_utilisateur:o.userId,id_page:230,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.lecture||(w("Vous n'avez pas le droit, veuillez consulter l'administrateur"),y("SitesCommercial"))}catch(l){f(`Une erreur s'est produite lors de la vérification des droits. ${l}`)}},I=async()=>{o.state.afficher_in_progress=!0;try{m.value=!1;const l=await g.post(`${o.lienApi}/listesites/${o.db}`,{});k.value=l.data.map(e=>({...e,ndoc:e.Id_site}))}catch(l){f(`Une erreur est survenue lors de l'affichage des sites ${l}`)}finally{o.state.afficher_in_progress=!1}},h=async()=>{try{const l=await g.post(`${o.lienApi}/AjouterEtRenvoyersite/${o.db}`);s.value=l.data,$.value=s.value.Id_site,m.value=!0,u.value=!0,d.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch(l){f(`Une erreur est survenue lors de l'ajout d'un site
 ${l}`)}},F=async()=>{try{if(!s.value.Nom){w("Le nom du site est obligatoire");return}if(!s.value.code_client){w("Le client est obligatoire");return}const l=`${o.lienApi}/enregistrerSite/${o.db}/${s.value.Id_site}`;await g.post(l,s.value,{headers:{"Content-Type":"application/json"}}),u.value=!1,d.value=!1,V("Enregistrement effectué avec succès")}catch(l){const e=l.response?.data?.message||l.message;f("Une erreur est survenue : "+e)}finally{o.state.afficher_in_progress=!1}},z=()=>{u.value=!1,d.value=!1},L=()=>{if(!C.value)return;if(k.value.length===0){w("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");C.value.exportToExcel(`Sites_${o.state.enreg_societe.Nom}_${e}.xlsx`)},j=async()=>{try{const l=await g.post(`${o.lienApi}/unsite/${o.db}/${$.value}`);s.value=l.data,m.value=!0}catch(l){f(`Une erreur est survenue lors de l'affichage des détails du site ${l}`)}},G=async()=>{u.value=!0,d.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},q=async()=>{if(await U({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${o.lienApi}/supprimerSite/${o.db}/${s.value.Id_site}`;await g.post(e),m.value=!1,u.value=!1,x.ndoc?y("SitesCommercial"):I(),V("Suppression effectuée avec succès")}catch(e){const i=e.response?.data?.message||e.message;f("Une erreur est survenue : "+i)}},O=()=>{x.ndoc?y("SitesCommercial"):(m.value=!1,I(),S.value!=null&&v.value&&setTimeout(()=>{const l=v.value.getDisplayedRowCount();if(l>0){const e=Math.min(S.value,l-1),i=v.value.getDisplayedRowAtIndex(e);i&&(v.value.deselectAll(),i.setSelected(!0),v.value.ensureNodeVisible(i,"middle"))}},100))};return(l,e)=>{const i=J,M=K,A=P,E=W;return p(),R(Z,null,[m.value&&n.lecture?(p(),R("div",te,[t("div",oe,[d.value?b("",!0):(p(),_(i,{key:0,onClick:e[0]||(e[0]=a=>G()),icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!n.modif},null,8,["disabled"])),d.value?b("",!0):(p(),_(i,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=a=>l.$refs.actionsMenu.toggle(a)),text:""})),r(M,{ref:"actionsMenu",model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:h,disabled:!n.ajout},{label:"Supprimer",icon:"pi pi-trash",command:q,disabled:!n.supp,class:"text-red-500"}],popup:!0},null,8,["model"]),d.value?b("",!0):(p(),_(i,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:O})),d.value?(p(),_(i,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=a=>F())})):b("",!0),d.value?(p(),_(i,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=a=>z())})):b("",!0)]),t("div",ae,[t("div",ie,[t("div",ne,[e[11]||(e[11]=t("label",{for:"Id_site",class:"block mb-1"},"Numéro",-1)),r(A,{size:"small",id:"Id_site",modelValue:s.value.Id_site,"onUpdate:modelValue":e[4]||(e[4]=a=>s.value.Id_site=a),class:"w-full",disabled:""},null,8,["modelValue"])]),t("div",re,[e[12]||(e[12]=t("label",{for:"client",class:"block mb-1"},"Client",-1)),r(E,{id:"client",modelValue:s.value.code_client,"onUpdate:modelValue":e[5]||(e[5]=a=>s.value.code_client=a),placeholder:"Sélectionner un client",table:"client",disabled:!u.value,class:"w-full"},null,8,["modelValue","disabled"])]),t("div",ue,[e[13]||(e[13]=t("label",{for:"inputFocus",class:"block mb-1"},"Nom",-1)),r(A,{size:"small",id:"inputFocus",modelValue:s.value.Nom,"onUpdate:modelValue":e[6]||(e[6]=a=>s.value.Nom=a),disabled:!u.value,class:"w-full"},null,8,["modelValue","disabled"])]),t("div",de,[e[14]||(e[14]=t("label",{for:"adresse",class:"block mb-1"},"Adresse",-1)),r(A,{size:"small",id:"adresse",modelValue:s.value.Adresse,"onUpdate:modelValue":e[7]||(e[7]=a=>s.value.Adresse=a),disabled:!u.value,class:"w-full"},null,8,["modelValue","disabled"])]),t("div",ce,[e[15]||(e[15]=t("label",{for:"ville",class:"block mb-1"},"Ville",-1)),r(E,{id:"ville",modelValue:s.value.Id_ville,"onUpdate:modelValue":e[8]||(e[8]=a=>s.value.Id_ville=a),placeholder:"Sélectionner une ville",table:"ville",disabled:!u.value,class:"w-full"},null,8,["modelValue","disabled"])])])])])):b("",!0),Q(t("div",null,[t("div",me,[t("div",pe,[t("div",fe,[r(i,{icon:"pi pi-plus",label:"Ajouter",onClick:h,text:"",disabled:!n.ajout},null,8,["disabled"]),r(i,{label:"Actions",icon:"pi pi-cog",onClick:e[9]||(e[9]=a=>l.$refs.actionsMenuList.toggle(a)),text:""}),r(M,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:L}],popup:!0},null,8,["model"]),r(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[10]||(e[10]=a=>Y(y)("SitesCommercial"))})])])]),t("div",ve,[r(se,{ref_key:"dataGrid",ref:C,"excel-file-name":"Sites commercial","excel-sheet-name":"Sites commercial","row-data":k.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc","Id_affaire_p","Id_ville","IDCommune","code_comptable","Matricule_controleur","RIB","code_client","affaire"],onRowClicked:N,onGridReady:T},null,8,["row-data"])])],512),[[X,!m.value&&n.lecture]])],64)}}};export{ye as default};
