'use client'; import Link from 'next/link'; import { useState } from 'react'; import type { PlazaComment } from '@/types/plaza'; import { formatCount, formatRelativeTime } from '@/lib/format'; import { fetchComments } from '@/lib/api'; import { CommentReportButton } from '@/components/post/CommentReportButton'; type CommentThreadProps = { postId: string; comment: PlazaComment; depth?: number; onReply: (comment: PlazaComment) => void; onToggleLike: (comment: PlazaComment) => void; }; export function CommentThread({ postId, comment, depth = 0, onReply, onToggleLike, }: CommentThreadProps) { const [replies, setReplies] = useState([]); const [expanded, setExpanded] = useState(false); const [loadingReplies, setLoadingReplies] = useState(false); const loadReplies = async () => { if (loadingReplies || expanded) return; setLoadingReplies(true); try { const data = await fetchComments(postId, { parent_id: comment.id }); setReplies(data.comments); setExpanded(true); } finally { setLoadingReplies(false); } }; const canReply = depth === 0; return (
0 ? 'border-l border-[#ebe4d6] pl-4' : undefined}>
{comment.author.display_name}

{comment.content}

{formatRelativeTime(comment.created_at)} {canReply ? ( ) : null}
{canReply && comment.reply_count > 0 && !expanded ? ( ) : null}
{expanded && replies.length > 0 ? ( ) : null}
); }