"use client"; import Link from "next/link"; import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { FileText, Upload, Calculator, CheckCircle, Send, Clock, User, AlertTriangle, Settings, Shield, } from "lucide-react"; import { formatDate } from "@/lib/formatting"; // Mock audit data - in real app this would come from API const mockAuditEvents = [ { id: "audit-1", type: "document_uploaded", title: "Document uploaded", description: "P60 Employment Certificate uploaded for John Smith", clientId: "client-1", clientName: "John Smith", userId: "user-1", userName: "Sarah Wilson", userRole: "preparer", timestamp: "2024-01-10T14:30:00Z", metadata: { fileName: "P60_2023-24.pdf", fileSize: "245KB", documentType: "P60", }, severity: "info", }, { id: "audit-2", type: "schedule_computed", title: "Schedule computed", description: "SA103 Self Employment schedule calculated for Sarah Johnson", clientId: "client-2", clientName: "Sarah Johnson", userId: "user-2", userName: "Mike Davis", userRole: "reviewer", timestamp: "2024-01-10T13:15:00Z", metadata: { scheduleType: "SA103", profit: "£45,000", taxLiability: "£8,500", }, severity: "info", }, { id: "audit-3", type: "coverage_check_failed", title: "Coverage check failed", description: "Missing evidence identified for Michael Brown - 2 critical items required", clientId: "client-3", clientName: "Michael Brown", userId: "system", userName: "System", userRole: "system", timestamp: "2024-01-10T11:45:00Z", metadata: { missingItems: ["Bank statements", "Property rental agreement"], coverageScore: "65%", }, severity: "warning", }, { id: "audit-4", type: "form_generated", title: "Form generated", description: "SA100 Main Return PDF created for Emma Davis", clientId: "client-4", clientName: "Emma Davis", userId: "user-3", userName: "Alex Thompson", userRole: "preparer", timestamp: "2024-01-10T10:20:00Z", metadata: { formType: "SA100", pages: 8, taxLiability: "£12,450", }, severity: "info", }, { id: "audit-5", type: "hmrc_submission", title: "HMRC submission prepared", description: "Tax return submitted to HMRC for David Wilson", clientId: "client-5", clientName: "David Wilson", userId: "user-2", userName: "Mike Davis", userRole: "reviewer", timestamp: "2024-01-10T09:30:00Z", metadata: { submissionId: "HMRC-2024-001234", taxYear: "2023-24", status: "submitted", }, severity: "success", }, { id: "audit-6", type: "user_login", title: "User login", description: "Sarah Wilson logged into the platform", clientId: null, clientName: null, userId: "user-1", userName: "Sarah Wilson", userRole: "preparer", timestamp: "2024-01-10T08:00:00Z", metadata: { ipAddress: "192.168.1.100", userAgent: "Chrome 120.0.0.0", location: "London, UK", }, severity: "info", }, { id: "audit-7", type: "policy_updated", title: "Coverage policy updated", description: "Self employment evidence requirements updated by administrator", clientId: null, clientName: null, userId: "admin-1", userName: "Admin User", userRole: "admin", timestamp: "2024-01-09T16:45:00Z", metadata: { policyType: "self_employment", changes: ["Added requirement for business bank statements"], }, severity: "warning", }, ]; const eventIcons = { document_uploaded: Upload, schedule_computed: Calculator, coverage_check_failed: AlertTriangle, form_generated: FileText, hmrc_submission: Send, user_login: User, policy_updated: Settings, system_error: AlertTriangle, default: Clock, }; const severityColors = { info: "bg-blue-100 text-blue-800 border-blue-200", success: "bg-green-100 text-green-800 border-green-200", warning: "bg-yellow-100 text-yellow-800 border-yellow-200", error: "bg-red-100 text-red-800 border-red-200", }; const roleColors = { admin: "bg-red-100 text-red-800", reviewer: "bg-blue-100 text-blue-800", preparer: "bg-green-100 text-green-800", system: "bg-gray-100 text-gray-800", }; export function AuditTimeline(): JSX.Element { return (
{mockAuditEvents.map((event, index) => { const Icon = eventIcons[event.type as keyof typeof eventIcons] || eventIcons.default; const isLast = index === mockAuditEvents.length - 1; return (
{/* Timeline line */} {!isLast && (
)}
{/* Icon */}
{/* Content */}

{event.title}

{event.description}

{event.severity} {formatDate(event.timestamp, { relative: true })}
{/* User and client info */}
{event.userName === "System" ? ( ) : ( event.userName .split(" ") .map((n) => n[0]) .join("") )} {event.userName} {event.userRole}
{event.clientName && ( <> {event.clientName} )}
{/* Metadata */} {event.metadata && Object.keys(event.metadata).length > 0 && (

Details

{Object.entries(event.metadata).map( ([key, value]) => (
{key .replace(/([A-Z])/g, " $1") .toLowerCase()} : {Array.isArray(value) ? value.join(", ") : String(value)}
) )}
)}
); })} {mockAuditEvents.length === 0 && (
No audit events found

Activity will appear here as work is completed

)}
); }