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