import type { HistoryEvent } from "../../lib/api"; interface TimelineEventCardProps { event: HistoryEvent; isSelected: boolean; onClick: () => void; } // Get icon and color based on event type function getEventStyle(eventType: string, eventSubtype: string | null) { const type = eventType.toLowerCase(); const subtype = eventSubtype?.toLowerCase(); if (type === "task") { if (subtype === "created") return { icon: "+", color: "text-[#9bc3ff]" }; if (subtype === "started") return { icon: "\u25B6", color: "text-green-400" }; if (subtype === "completed") return { icon: "\u2713", color: "text-emerald-400" }; if (subtype === "failed") return { icon: "\u2717", color: "text-red-400" }; if (subtype === "stopped") return { icon: "\u25A0", color: "text-yellow-400" }; return { icon: "\u2022", color: "text-[#9bc3ff]" }; } if (type === "checkpoint") { return { icon: "\u2691", color: "text-purple-400" }; } if (type === "phase") { return { icon: "\u21B3", color: "text-cyan-400" }; } if (type === "chat") { return { icon: "\u2709", color: "text-[#75aafc]" }; } if (type === "contract") { return { icon: "\u2606", color: "text-[#9bc3ff]" }; } if (type === "file") { return { icon: "\u2630", color: "text-[#7788aa]" }; } return { icon: "\u2022", color: "text-[#7788aa]" }; } // Format relative time function formatRelativeTime(dateStr: string): string { const date = new Date(dateStr); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffSec = Math.floor(diffMs / 1000); const diffMin = Math.floor(diffSec / 60); const diffHour = Math.floor(diffMin / 60); const diffDay = Math.floor(diffHour / 24); if (diffSec < 60) return "just now"; if (diffMin < 60) return `${diffMin}m ago`; if (diffHour < 24) return `${diffHour}h ago`; if (diffDay < 7) return `${diffDay}d ago`; return date.toLocaleDateString(); } // Extract a preview from event data function getEventPreview(event: HistoryEvent): string { const data = event.eventData as Record; // Task events if (data.taskName) return String(data.taskName); if (data.name) return String(data.name); // Chat events if (data.message) { const msg = String(data.message); return msg.length > 50 ? msg.slice(0, 50) + "..." : msg; } // Checkpoint events if (data.checkpointMessage) return String(data.checkpointMessage); if (data.commitSha) return `Commit ${String(data.commitSha).slice(0, 7)}`; // Phase events if (data.phase) return `Phase: ${data.phase}`; // Contract events if (data.contractName) return String(data.contractName); return ""; } export function TimelineEventCard({ event, isSelected, onClick }: TimelineEventCardProps) { const { icon, color } = getEventStyle(event.eventType, event.eventSubtype); const preview = getEventPreview(event); return ( ); }