import{f as b,o as L,c as S,b as p,a as n,z as j,q as k,F as R,ar as z,r as o}from"./vendor-BDR7yMJi.js";import{u as D,a as f,s,S as v}from"./index-BSaHX2oa.js";import{_ as F}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const G={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},N={class:"btns flex items-center gap-2 lg:w-1/2 lg:justify-start py-2"},T={style:{height:"calc(100vh - 150px)"}},U={__name:"ListeArticlesCaches",setup(V){const{showError:c,showSuccess:g,confirmAction:_,showWarn:l}=D(),u=z({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),d=o([]),a=o([]),x=o(),r=o(),A=t=>{r.value=t.api},w=({selectedRows:t})=>{a.value=t};b(async()=>{await y(),m()});const y=async()=>{try{const e=(await f.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:201,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(u.lecture=e.lecture,u.ajout=e.ajout),u.lecture||(l("Vous n'avez pas le droit, veuillez consulter l'administrateur"),v("ListeArticlesCaches"))}catch(t){const e=t.response?.data?.message||t.message;c(`Une erreur est survenue : ${e}`)}finally{s.state.afficher_in_progress=!1}},m=async()=>{s.state.afficher_in_progress=!0;try{const t=await f.post(`${s.lienApi}/articleCaches/${s.db}`);d.value=t.data}catch(t){c(`Une erreur est survenue lors de l'affichage des articles cachés
 ${t}`)}finally{s.state.afficher_in_progress=!1}},C=async()=>{if(!a.value||a.value.length<=0){l({title:"Aucun élément sélectionné",text:"Veuillez sélectionner au moins un élément avant de restaurer."});return}if(await _({message:`Voulez-vous vraiment restaurer ${a.value.length} article(s) caché(s) ?`,header:"Confirmation de restauration",icon:"pi pi-exclamation-triangle",acceptLabel:"Oui, restaurer",rejectLabel:"Annuler",acceptClass:"p-button-success"}))try{const e=a.value.map(i=>i.code_art);await f.post(`${s.lienApi}/miseAjourArticleCaches/${s.db}`,e,{headers:{"Content-Type":"application/json"}}),g("Articles restaurés avec succès"),a.value=[],r.value&&r.value.deselectAll(),await m()}catch(e){c(`Une erreur est survenue lors de la restauration des articles.
 ${e}`)}},$=()=>{if(!r.value){l("Grille non initialisée");return}if(d.value.length===0){l("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");r.value.exportDataAsExcel({fileName:`Liste_des_articles_caches_${s.state.enreg_societe.Nom}_${e}.xlsx`,sheetName:"Articles cachés",exportedRows:"all",onlySelected:!1,suppressTextAsCDATA:!0})};return(t,e)=>{const i=j;return L(),S(R,null,[p("div",G,[p("div",N,[n(i,{icon:"pi pi-refresh",label:"Restaurer",text:"",onClick:e[0]||(e[0]=h=>C())}),n(i,{icon:"pi pi-file-excel",label:"Exporter",text:"",onClick:e[1]||(e[1]=h=>$())}),n(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=h=>k(v)("ListeArticlesCaches"))})])]),p("div",T,[n(F,{ref_key:"agGrid",ref:x,"excel-file-name":"Liste articles caches","excel-sheet-name":"Liste articles caches","row-data":d.value,"excluded-columns":[],"column-widths":{code_art:150,Libelle:300,Famille:200,"Sous Famille":200},"enable-totals":!1,onGridReady:A,onSelectionChanged:w},null,8,["row-data"])])],64)}}};export{U as default};
