// src/components/weather/favorite-button.tsx import { Star } from "lucide-react"; import { Button } from "@/components/ui/button"; import type { WeatherData } from "@/api/types"; import { useFavorites } from "@/hooks/use-favorite"; import { toast } from "sonner"; interface FavoriteButtonProps { data: WeatherData; } export function FavoriteButton({ data }: FavoriteButtonProps) { const { addFavorite, removeFavorite, isFavorite } = useFavorites(); const isCurrentlyFavorite = isFavorite(data.coord.lat, data.coord.lon); const handleToggleFavorite = () => { if (isCurrentlyFavorite) { removeFavorite.mutate(`${data.coord.lat}-${data.coord.lon}`); toast.error(`Removed ${data.name} from Favorites`); } else { addFavorite.mutate({ name: data.name, lat: data.coord.lat, lon: data.coord.lon, country: data.sys.country, }); toast.success(`Added ${data.name} to Favorites`); } }; return ( ); }