import{b as l}from"./primevue-CfIk0_DY.js";import{u as d,b as r,s as e}from"./index-BxIwIJfy.js";import{o as m,a as i,b as v,k as f,q as _}from"./vue-core-Di3IuVqe.js";const y={__name:"FavorisSwitch",props:["fen","text"],setup(u){const{showError:n}=d(),o=u,a=i(!1);m(async()=>{try{const s=await r.post(`${e.lienApi}/unFavoris/${e.state.dbCommun6}`,{id_user:e.userId,Fen:o.fen},{headers:{"Content-Type":"application/json"}}),t=i([]);t.value=s.data,a.value=t.value.length>0}catch(s){n(`Une erreur est survenue lors de la récupération des favoris ${s}`)}});const c=async()=>{a.value=!a.value;try{a.value?await r.post(`${e.lienApi}/FavorisInsert/${e.state.dbCommun6}`,{Fen:o.fen,Libelle:o.text,id_utilisateur:e.userId},{headers:{"Content-Type":"application/json"}}):await r.post(`${e.lienApi}/supprimerFavoris/${e.state.dbCommun6}`,{Fen:o.fen,id_user:e.userId},{headers:{"Content-Type":"application/json"}}),window.dispatchEvent(new CustomEvent("favorisModifies"))}catch(s){const t=s.response?.data?.message||s.message;n(`Une erreur est survenue : ${t}`)}finally{e.state.afficher_in_progress=!1}};return(s,t)=>{const p=l;return v(),f(p,{class:_(a.value?"bouton-jaune":"p-button-secondary"),icon:"pi pi-star",text:"",rounded:"",onClick:c,"aria-label":"Favoris"},null,8,["class"])}}};export{y as _};
