'use client' import { useState } from 'react' import { Button } from '@/components/ui/button' import { Textarea } from '@/components/ui/textarea' import { Card, CardContent } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { MessageSquare, Lock, Send, User } from 'lucide-react' import { cn } from '@/lib/utils' interface Comment { id: string author: string content: string createdAt: string } interface DiscussionThreadProps { comments: Comment[] onAddComment?: (content: string) => void isLocked?: boolean maxLength?: number isSubmitting?: boolean } function formatRelativeTime(dateStr: string): string { const date = new Date(dateStr) const now = new Date() const diffMs = now.getTime() - date.getTime() const diffMinutes = Math.floor(diffMs / 60000) const diffHours = Math.floor(diffMinutes / 60) const diffDays = Math.floor(diffHours / 24) if (diffMinutes < 1) return 'just now' if (diffMinutes < 60) return `${diffMinutes}m ago` if (diffHours < 24) return `${diffHours}h ago` if (diffDays < 7) return `${diffDays}d ago` return date.toLocaleDateString() } export function DiscussionThread({ comments, onAddComment, isLocked = false, maxLength = 2000, isSubmitting = false, }: DiscussionThreadProps) { const [newComment, setNewComment] = useState('') const handleSubmit = () => { const trimmed = newComment.trim() if (!trimmed || !onAddComment) return onAddComment(trimmed) setNewComment('') } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { e.preventDefault() handleSubmit() } } return (
{/* Locked banner */} {isLocked && (
Discussion is closed. No new comments can be added.
)} {/* Comments list */} {comments.length === 0 ? (

No comments yet

Be the first to share your thoughts on this project.

) : (
{comments.map((comment) => (
{comment.author} {formatRelativeTime(comment.createdAt)}

{comment.content}

))}
)} {/* Add comment form */} {!isLocked && onAddComment && (