'use client'; import { useQuery } from '@tanstack/react-query'; import { Loader2, MessageCircle } from 'lucide-react'; import { getComments } from '@/api/comments'; import { Comment } from '@/types'; import CommentForm from './CommentForm'; import CommentItem from './CommentItem'; interface CommentListProps { postSlug: string; } export default function CommentList({ postSlug }: CommentListProps) { const { data: comments, isLoading, error } = useQuery({ queryKey: ['comments', postSlug], queryFn: () => getComments(postSlug), }); const countComments = (list: Comment[]): number => { if (!list) return 0; return list.reduce((acc, curr) => acc + 1 + countComments(curr.children), 0); }; const totalCount = comments ? countComments(comments) : 0; if (isLoading) { return (