import React, { useState } from 'react' import { MessageCircle, Trash2, Send } from 'lucide-react' import { useAuthStore } from '../../store/authStore' import { useStoryStore } from '../../store/storyStore' import { useNotificationStore } from '../../store/notificationStore' import { useUIStore } from '../../store/uiStore' import { Comment } from '../../types' import { Avatar } from '../ui/Avatar' import { Button } from '../ui/Button' interface CommentSectionProps { storyId: number authorUserId: number } function timeAgo(str: string): string { const diff = Date.now() - new Date(str).getTime() const m = Math.floor(diff / 60000) if (m < 1) return 'just now' if (m < 60) return `${m}m ago` const h = Math.floor(m / 60) if (h < 24) return `${h}h ago` return `${Math.floor(h / 24)}d ago` } export const CommentSection: React.FC = ({ storyId, authorUserId }) => { const { currentUser } = useAuthStore() const { comments, addComment, deleteComment } = useStoryStore() const { addNotification } = useNotificationStore() const { addToast } = useUIStore() const [text, setText] = useState('') const [submitting, setSubmitting] = useState(false) const storyComments = comments .filter(c => c.story_id === storyId) .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()) const handleSubmit = async () => { if (!text.trim() || !currentUser) return setSubmitting(true) await new Promise(r => setTimeout(r, 300)) const comment: Comment = { comment_id: Date.now(), story_id: storyId, user_id: currentUser.user_id, username: currentUser.username, content: text.trim(), created_at: new Date().toISOString(), } addComment(comment) if (currentUser.user_id !== authorUserId) { addNotification({ user_id: authorUserId, type: 'comment', title: 'New Comment', message: `${currentUser.username} commented: "${text.trim().slice(0, 60)}..."`, link: `/story/${storyId}`, }) } setText('') setSubmitting(false) addToast('Comment posted!') } return (

Comments ({storyComments.length})

{/* Input */} {currentUser ? (