'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { toast } from 'sonner' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { addComment, deleteComment } from '@/lib/actions' import { Trash2, MessageCircle } from 'lucide-react' import { Empty, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty' export type CommentEntityType = 'forum_thread' | 'proposal' | 'incident' | 'policy' export interface CommentRow { id: string body: string created_at: string edited_at: string | null author_id: string | null author_name: string | null } interface Props { entityType: CommentEntityType entityId: string comments: CommentRow[] currentMemberId: string | null canModerate: boolean locked?: boolean } export function CommentThread({ entityType, entityId, comments, currentMemberId, canModerate, locked }: Props) { const router = useRouter() const [body, setBody] = useState('') const [saving, setSaving] = useState(false) async function handleSubmit(e: React.FormEvent) { e.preventDefault() if (!body.trim() || locked) return setSaving(true) const result = await addComment({ entity_type: entityType, entity_id: entityId, body: body.trim() }) setSaving(false) if ('error' in result && result.error) { toast.error(result.error); return } setBody('') router.refresh() } async function handleDelete(commentId: string) { if (!confirm('Delete this comment?')) return const result = await deleteComment(commentId) if (result.error) { toast.error(result.error); return } toast.success('Comment deleted') router.refresh() } return (

Discussion{comments.length > 0 ? ` (${comments.length})` : ''}

{comments.length === 0 && ( No comments yet )} {comments.length > 0 && ( )} {locked ? (

This thread is locked. New comments are disabled.

) : (