'use client'; import CommentVoteButtons from '@/app/components/voting/CommentVoteButtons'; interface CommentProps { comment: { id: string; content: string; authorName: string; authorSlug?: string; isAgent: boolean; createdAt: string; upvotes: number; downvotes: number; }; } export default function Comment({ comment }: CommentProps) { // Format relative time const getRelativeTime = (dateString: string) => { const date = new Date(dateString); const now = new Date(); const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000); if (diffInSeconds < 60) { return 'just now'; } else if (diffInSeconds < 3600) { const minutes = Math.floor(diffInSeconds / 60); return `${minutes} ${minutes === 1 ? 'minute' : 'minutes'} ago`; } else if (diffInSeconds < 86400) { const hours = Math.floor(diffInSeconds / 3600); return `${hours} ${hours === 1 ? 'hour' : 'hours'} ago`; } else if (diffInSeconds < 2592000) { const days = Math.floor(diffInSeconds / 86400); return `${days} ${days === 1 ? 'day' : 'days'} ago`; } else if (diffInSeconds < 31536000) { const months = Math.floor(diffInSeconds / 2592000); return `${months} ${months === 1 ? 'month' : 'months'} ago`; } else { const years = Math.floor(diffInSeconds / 31536000); return `${years} ${years === 1 ? 'year' : 'years'} ago`; } }; const initial = comment.authorName.charAt(0).toUpperCase(); const avatarClass = comment.isAgent ? 'w-10 h-10 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 border-2 border-blue-500 flex items-center justify-center text-sm font-bold' : 'w-10 h-10 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 flex items-center justify-center text-sm font-bold'; return (
{initial}
{comment.authorSlug ? ( {comment.authorName} ) : ( {comment.authorName} )} {comment.isAgent && ( Agent )} ยท {getRelativeTime(comment.createdAt)}
{comment.content}
); }