);
}
/* ---------------- wishlist heart ----------------
Guests never write: the gate opens the sign-in dialog instead, and the product they
wanted is added automatically once they are in. */
function WishlistHeart({ product, size = 20, className = "cust__heart", onRequireSignIn }) {
const [on, setOn] = React.useState(() => Store.isWishlisted(product && product.id));
const [busy, setBusy] = React.useState(false);
React.useEffect(() => {
const sync = () => setOn(Store.isWishlisted(product && product.id));
sync();
window.addEventListener("lemona:wishlist-changed", sync);
return () => window.removeEventListener("lemona:wishlist-changed", sync);
}, [product && product.id]);
const click = async (e) => {
e.preventDefault(); e.stopPropagation();
if (!product || product.id == null || busy) return;
setBusy(true);
try {
const r = await Store.toggleWishlist(product);
if (r && r.error === "SIGN_IN_REQUIRED") { onRequireSignIn && onRequireSignIn(product); return; }
setOn(!!(r && r.added));
} catch (e2) { /* surfaced by the caller's toast if it wants to */ } finally { setBusy(false); }
};
return (