(function() { window.toggleWishlist = function(itemId) { var btn = document.getElementById('wishlist-btn'); fetch('/api/wishlists/' + itemId, { method: 'POST', headers: csrfHeaders() }) .then(function(r) { return r.json(); }) .then(function(data) { if (data.wishlisted) { btn.textContent = 'Wishlisted'; } else { btn.textContent = 'Add to Wishlist'; } }); }; window.toggleCart = function(itemId) { var btn = document.getElementById('cart-btn'); fetch('/api/cart/' + itemId, { method: 'POST', headers: csrfHeaders() }) .then(function(r) { return r.json(); }) .then(function(data) { if (data.in_cart) { btn.textContent = 'In Cart'; showToast('Added to cart. Buying multiple items together saves the creator on processing fees.', 'info'); } else { btn.textContent = 'Add to Cart'; } }) .catch(function(err) { showToast(err.message || 'Failed to update cart'); }); }; })();