import"./hoisted.DebOr7RK.js";customElements.get("like-button")||customElements.define("like-button",class extends HTMLElement{async connectedCallback(){const i=this.dataset.key,o=this.dataset.label||"Like",t=this.querySelector(".like-btn"),l=this.querySelector(".like-count"),c=`liked:${i}`,n=(a,e)=>{l.textContent=String(a),t.setAttribute("aria-pressed",String(e)),t.setAttribute("aria-label",`${o} — ${a} ${a===1?"like":"likes"}`)};let s=!1;try{s=localStorage.getItem(c)==="1"}catch{}try{const e=await(await fetch(`/api/likes?key=${encodeURIComponent(i)}`,{headers:{Accept:"application/json"}})).json();n(Number(e?.counts?.[i]??0),s)}catch{n(0,s)}t.addEventListener("click",async()=>{if(!(s||t.disabled)){t.disabled=!0;try{const e=await(await fetch("/api/likes",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({key:i})})).json();if(e?.ok){s=!0;try{localStorage.setItem(c,"1")}catch{}n(Number(e.count??0),!0),t.classList.remove("pop"),t.offsetWidth,t.classList.add("pop")}}catch{}finally{t.disabled=!1}}})}});