"use client"; import { ChevronDown, ChevronRight, MessageSquare } from "lucide-react"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { CommentComposer } from "../comment-composer/comment-composer"; import { CommentItem } from "../comment-item/comment-item"; import type { CommentThreadProps } from "./types"; export function CommentThread({ thread, members, membersLoading = false, onCreateReply, onEditComment, onDeleteComment, isSubmitting = false, }: CommentThreadProps) { const [isRepliesExpanded, setIsRepliesExpanded] = useState(true); const [isReplyComposerOpen, setIsReplyComposerOpen] = useState(false); const parentComment = { id: thread.id, content: thread.content, contentRendered: thread.contentRendered, author: thread.author, createdAt: thread.createdAt, updatedAt: thread.updatedAt, isEdited: thread.isEdited, canEdit: thread.canEdit, canDelete: thread.canDelete, }; const handleReply = () => { setIsReplyComposerOpen(true); setIsRepliesExpanded(true); }; const handleReplySubmit = (content: string) => { onCreateReply(thread.id, content); setIsReplyComposerOpen(false); }; const handleReplyCancel = () => { setIsReplyComposerOpen(false); }; const hasReplies = thread.replies.length > 0; const showReplies = thread.replies.length === 1 || isRepliesExpanded; return (
{/* Parent comment */} onEditComment(id, "")} onDelete={onDeleteComment} /> {/* Replies and actions - using flex layout with connector */} {(hasReplies || isReplyComposerOpen) && (
{/* Connector column - vertical line */}
{/* Content column */}
{/* Expand/collapse for multiple replies */} {thread.replies.length > 1 && ( )} {/* Reply items */} {showReplies && hasReplies && (
{thread.replies.map((reply) => ( onEditComment(id, "")} onDelete={onDeleteComment} /> ))}
)} {/* Reply composer or button */} {isReplyComposerOpen ? ( ) : ( )}
)} {/* Reply button when no replies yet */} {!hasReplies && !isReplyComposerOpen && (
)}
); }