document.addEventListener("DOMContentLoaded", function() { console.log(clubData.club.club_ID); var favoriteButton = document.getElementById("club-favorite-button"); if (favoriteButton) { favoriteButton.addEventListener("click", function() { if (favoriteButton.src.includes("/favorited.png")) { favoriteButton.src = "/img/club-page/unfavorited.png"; removeFavoriteTeam(1, 3); } else { console.log("kjhdsgkjh"); favoriteButton.src = "/img/club-page/favorited.png"; addFavoriteTeam(1, 3, 'Manchester City FC', 'https://crests.football-data.org/65.png'); } }); } }); async function addFavoriteTeam(userID, teamID, teamName, teamLogo) { try { console.log("yesss") const response = await fetch('/favteam/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userID: userID, teamID: teamID, teamName: teamName, teamLogo: teamLogo }) }); if (!response.ok) { throw new Error('Failed to add favorite team'); } console.log('New favorite team added successfully.'); } catch (error) { console.error('Error adding favorite team:', error); } } async function removeFavoriteTeam(userID, teamID) { try { const response = await fetch('/favteam/remove', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userID: userID, teamID: teamID }) }); if (!response.ok) { throw new Error('Failed to remove favorite team'); } console.log('Favorite team removed successfully.'); } catch (error) { console.error('Error removing favorite team:', error); } }