import React from 'react' import { Heart } from 'lucide-react' import { useNavigate } from 'react-router-dom' import { useAuthStore } from '../../store/authStore' import { useStoryStore } from '../../store/storyStore' import { useNotificationStore } from '../../store/notificationStore' import { useUIStore } from '../../store/uiStore' interface LikeButtonProps { storyId: number authorUserId: number totalLikes: number } export const LikeButton: React.FC = ({ storyId, authorUserId, totalLikes }) => { const navigate = useNavigate() const { currentUser } = useAuthStore() const { toggleLike, isLiked } = useStoryStore() const { addNotification } = useNotificationStore() const { addToast } = useUIStore() const liked = currentUser ? isLiked(currentUser.user_id, storyId) : false const handleClick = () => { if (!currentUser) { addToast('Please sign in to like stories.', 'info') navigate('/login') return } toggleLike(currentUser.user_id, storyId) if (!liked && currentUser.user_id !== authorUserId) { addNotification({ user_id: authorUserId, type: 'like', title: 'New Like', message: `${currentUser.username} liked your story.`, link: `/story/${storyId}`, }) } addToast(liked ? 'Removed from likes' : 'Added to likes!', liked ? 'info' : 'success') } return ( ) }