import { type KeyboardEvent, type MouseEvent } from "react"; import { Shield } from "lucide-react"; import { DashboardSection } from "./DashboardSection"; import { DashboardEmptyState } from "./DashboardEmptyState"; import { Markdown } from "@/components/atoms/Markdown"; import { cn } from "@/lib/utils"; import type { ActivityEventRead } from "@/api/generated/model"; export type ActivityEvent = ActivityEventRead; interface RecentActivitySectionProps { events: ActivityEvent[]; feedHref: string; onRowClick: (e: MouseEvent, href: string) => void; onRowKeyDown: (e: KeyboardEvent, href: string) => void; buildHref: (event: ActivityEvent) => string; formatRelative: (ts: string) => string; formatTimestamp: (ts: string) => string; } const eventTone = (eventType: string) => { const normalized = eventType.toLowerCase(); if (normalized.includes("error") || normalized.includes("fail")) { return { rail: "border-l-[color:var(--danger)]", dot: "bg-[color:var(--danger)]", row: "hover:border-[color:rgba(248,113,113,0.35)] hover:bg-[color:rgba(248,113,113,0.08)]", }; } if (normalized.includes("approval") || normalized.includes("review")) { return { rail: "border-l-[color:var(--warning)]", dot: "bg-[color:var(--warning)]", row: "hover:border-[color:rgba(251,191,36,0.35)] hover:bg-[color:rgba(251,191,36,0.08)]", }; } if (normalized.includes("complete") || normalized.includes("sync")) { return { rail: "border-l-[color:var(--success)]", dot: "bg-[color:var(--success)]", row: "hover:border-[color:rgba(52,211,153,0.35)] hover:bg-[color:rgba(52,211,153,0.08)]", }; } return { rail: "border-l-[color:var(--accent)]", dot: "bg-[color:var(--accent)]", row: "hover:border-[color:rgba(96,165,250,0.35)] hover:bg-[color:rgba(96,165,250,0.08)]", }; }; export function RecentActivitySection({ events, feedHref, onRowClick, onRowKeyDown, buildHref, formatRelative, formatTimestamp, }: RecentActivitySectionProps) { return (
{events.length > 0 ? ( events.map((event) => { const href = buildHref(event); const tone = eventTone(event.event_type); return (
onRowClick(e, href)} onKeyDown={(e) => onRowKeyDown(e, href)} className={cn( "cursor-pointer overflow-hidden rounded-lg border border-l-4 border-[color:var(--border)] bg-[color:var(--surface-muted)] px-3 py-2 transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--accent)]", tone.rail, tone.row, )} >

{event.event_type}

{formatRelative(event.created_at)}

{formatTimestamp(event.created_at)}

); }) ) : ( } message="No activity yet" sub="Activity appears here when events are emitted." /> )}
); }