"use client"; import * as React from "react"; import { cn } from "./lib/utils"; export type AuditAction = "create" | "update" | "delete" | "login" | "export"; export interface AuditEntry { id: string; actor: string; initials: string; action: AuditAction; target: string; time: string; ip?: string; } export interface AuditLogProps extends React.HTMLAttributes { entries: AuditEntry[]; /** Shows all actions if omitted */ filter?: AuditAction | "all"; } const ACTION_TONE: Record = { create: "border-success/50 bg-success/10 text-success", update: "border-warning/50 bg-warning/10 text-warning", delete: "border-destructive/50 bg-destructive/10 text-destructive", login: "border-accent/50 bg-accent/10 text-accent", export: "border-border bg-secondary text-muted-foreground", }; const ACTION_LABEL: Record = { create: "CREATED", update: "UPDATED", delete: "DELETED", login: "LOGIN", export: "EXPORTED", }; /** Audit log: actor + action + timestamp + IP with status tones. */ export function AuditLog({ entries, filter = "all", className, ...props }: AuditLogProps) { const visible = filter === "all" ? entries : entries.filter((e) => e.action === filter); return (
{visible.map((e, idx) => (
{e.initials}
{e.actor} {ACTION_LABEL[e.action]} {e.target}

{e.time}{e.ip ? ` ยท ${e.ip}` : ""}

))} {visible.length === 0 && (

No audit records found.

)}
); }