'use client'; import { ArrowRight, Ban, CheckCircle2, MessageSquare, UserMinus } from 'lucide-react'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { cn } from '@/lib/utils'; export type ThreadItemType = 'comment' | 'status_change' | 'protocol_event'; export interface ThreadItem { id: string; type: ThreadItemType; author?: string; content?: string; from?: string; to?: string; event?: string; timestamp: Date; } interface ThreadViewProps { items: ThreadItem[]; variant?: 'stack' | 'chat'; currentUser?: string; onAddComment?: (text: string) => void; } function getInitials(name: string): string { return name .split(' ') .map((part) => part[0]) .join('') .toUpperCase() .slice(0, 2); } function formatRelativeTime(date: Date): string { const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffSecs = Math.floor(diffMs / 1000); const diffMins = Math.floor(diffSecs / 60); const diffHours = Math.floor(diffMins / 60); const diffDays = Math.floor(diffHours / 24); if (diffSecs < 60) return 'just now'; if (diffMins < 60) return `${diffMins}m ago`; if (diffHours < 24) return `${diffHours}h ago`; if (diffDays < 7) return `${diffDays}d ago`; return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric' }); } function getProtocolIcon(event?: string) { switch (event?.toUpperCase()) { case 'HANDOFF': return ; case 'BLOCKED': return ; case 'CLOSED': return ; default: return ; } } function getProtocolLabel(event?: string): string { switch (event?.toUpperCase()) { case 'HANDOFF': return 'Handoff'; case 'BLOCKED': return 'Blocked'; case 'CLOSED': return 'Closed'; default: return 'Event'; } } function CommentItem({ item, isSelf }: { item: ThreadItem; isSelf: boolean }) { return (
{!isSelf ? ( {item.author ? getInitials(item.author) : '??'} ) : null}
{item.author || 'Unknown'} {formatRelativeTime(item.timestamp)}

{item.content}

{isSelf ? ( {item.author ? getInitials(item.author) : 'ME'} ) : null}
); } function StatusChangeItem({ item }: { item: ThreadItem }) { return (
Status: {item.from || 'unknown'} {item.to || 'unknown'} {formatRelativeTime(item.timestamp)}
); } function ProtocolEventItem({ item }: { item: ThreadItem }) { return (
{getProtocolIcon(item.event)}
{getProtocolLabel(item.event)} {item.content && ( {item.content} )}
{formatRelativeTime(item.timestamp)}
); } export function ThreadView({ items, variant = 'stack', currentUser = 'you', onAddComment }: ThreadViewProps) { void onAddComment; return (
{items.length === 0 ? (

No activity yet

) : (
{items.map((item) => { switch (item.type) { case 'comment': return ( ); case 'status_change': return ; case 'protocol_event': return ; default: return null; } })}
)}
); }