import Link from 'next/link'; import { apiFetch } from '../../_lib/api'; interface ThreadMessage { id: string; content: string; senderJid: string; senderName: string | null; tags: string[]; status: string; createdAt: string; } interface ThreadDetail { id: string; topic: string | null; sourceGroupName: string; messageCount: number; lastActivityAt: string; createdAt: string; messages: ThreadMessage[]; } const STATUS_COLORS: Record = { APPROVED: 'text-green-600', PENDING: 'text-amber-600', REJECTED: 'text-red-600', RAW: 'text-gray-400', DNC: 'text-gray-400', DISTRIBUTED: 'text-blue-600', }; export default async function ThreadDetailPage({ params, }: { params: Promise<{ id: string }>; }) { const { id } = await params; let thread: ThreadDetail | null = null; let error: string | null = null; try { const res = await apiFetch(`/admin/threads/${id}`); if (res.ok) { thread = await res.json(); } else { error = `API returned ${res.status}`; } } catch { error = 'Failed to load thread'; } if (error || !thread) { return (
← Back to threads

{error ?? 'Thread not found'}

); } return (
← Back to threads

{thread.topic ?? `Thread ${thread.id.slice(0, 8)}`}

{thread.sourceGroupName} · {thread.messageCount} messages · last activity {new Date(thread.lastActivityAt).toLocaleDateString()}

{thread.messages.map((msg) => (
{msg.senderName ?? msg.senderJid} · {new Date(msg.createdAt).toLocaleString()}
{msg.status} View

{msg.content}

{msg.tags.length > 0 && (
{msg.tags.map((tag) => ( {tag} ))}
)}
))}
); }