export async function handleAddFavorite(id, tags, imageUrl, thumbnailUrl, showMessageCallback) { const safeTags = Array.isArray(tags) ? tags : []; const title = safeTags.length > 0 ? safeTags[0] : 'Favorite'; const allTags = safeTags.join(','); const result = await window.api.addFavorite({ id, title, imageUrl, thumbnailUrl, tags: allTags, }); if (result.success) { showMessageCallback('Added to favorites!', 'success'); } else { showMessageCallback(result.error, 'error'); } } export async function handleRemoveFavorite(id, favoritesGallery, showMessageCallback, applyLayoutCallback, currentLayout) { const result = await window.api.removeFavorite(id); if (result.success) { showMessageCallback('Removed from favorites.', 'success'); const cardToRemove = document.querySelector(`#favorites-gallery [data-id='${id}']`); if (cardToRemove) { cardToRemove.classList.add('opacity-0', 'scale-90'); setTimeout(() => { cardToRemove.remove(); if (favoritesGallery.children.length === 0) { applyLayoutCallback(favoritesGallery, currentLayout); favoritesGallery.innerHTML = '

You haven\'t saved any favorites yet.

'; } }, 300); } } else { showMessageCallback(result.error, 'error'); } } export function createAddFavoriteButton(id, safeTags, imageUrl, thumbnailUrl, showMessageCallback) { const button = document.createElement('button'); button.title = 'Add to Favorites'; button.className = 'p-2 rounded-full bg-black/50 text-white hover:bg-indigo-600 backdrop-blur-sm transition-colors'; button.innerHTML = ` `; button.onclick = (e) => { e.stopPropagation(); handleAddFavorite(id, safeTags, imageUrl, thumbnailUrl, showMessageCallback); }; return button; } export function createRemoveFavoriteButton(id, favoritesGallery, showMessageCallback, applyLayoutCallback, currentLayout) { const button = document.createElement('button'); button.title = 'Remove from Favorites'; button.className = 'p-2 rounded-full bg-black/50 text-white hover:bg-red-600 backdrop-blur-sm transition-colors'; button.innerHTML = ` `; button.onclick = (e) => { e.stopPropagation(); handleRemoveFavorite(id, favoritesGallery, showMessageCallback, applyLayoutCallback, currentLayout); }; return button; }