"use client"; import { useEffect, useState } from "react"; import { getAnalysisHistory } from "../actions/analysis"; import { formatDistanceToNow } from "date-fns"; import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { User, Clock, CheckCircle2, XCircle, Settings, HelpCircle, Loader2 } from "lucide-react"; import { cn } from "@/lib/utils"; interface LogEntry { id: string; action: string; createdAt: string | Date; admin: { name: string | null; email: string }; detection: { objectName: string }; correctedValues: any; } export function AnalysisHistory({ videoInternalId }: { videoInternalId: string }) { const [logs, setLogs] = useState([]); const [isLoading, setIsLoading] = useState(true); useEffect(() => { const fetch = async () => { try { const results = await getAnalysisHistory(videoInternalId); setLogs(results as any); } catch (err) { console.error("Failed to fetch history", err); } finally { setIsLoading(false); } }; fetch(); }, [videoInternalId]); if (isLoading) { return (

Loading audit log...

); } if (logs.length === 0) { return (

No history yet

Actions taken on this video's objects will appear here.

); } return (

Audit Trail ({logs.length})

{logs.map((log) => { const isApprove = log.action === 'approved'; const isReject = log.action === 'rejected'; const isCorrect = log.action === 'corrected'; const isIncorrect = log.action === 'marked_incorrect'; return (
{isApprove && } {isReject && } {isCorrect && } {isIncorrect && }

{log.admin.name || log.admin.email} {log.action.replace('_', ' ')} {log.detection.objectName}

{formatDistanceToNow(new Date(log.createdAt), { addSuffix: true })}
{log.correctedValues?.notes && (
"{log.correctedValues.notes}"
)}
); })}
); }