'use client'; import { useState } from 'react'; import { X, ArrowDownCircle, ArrowUpCircle } from 'lucide-react'; import { cn } from '@/lib/utils'; interface AuditLog { id: string; action: string; username?: string; timestamp: string; resolved_name: string; quantity_change?: number; target_snapshot?: string; details?: string; } interface LogsTableProps { logs: AuditLog[]; loading: boolean; } export default function LogsTable({ logs, loading }: LogsTableProps) { const [selectedLog, setSelectedLog] = useState(null); if (loading) { return (

Securing Audit Stream...

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

No events found

Refine your strategic filters

); } return ( <>
{/* Header Row */}
Action
Item
Operator
Timestamp
Delta
{logs.map((log) => ( ))}
{/* Selected Log Modal */} {selectedLog && (
{selectedLog.action.replace('_', ' ').toLowerCase()}

{selectedLog.resolved_name}

Protocol Operator

{selectedLog.username || 'Automated Process'}

Quantity Delta

0 ? "text-green-500" : "text-rose-500" )}> {selectedLog.quantity_change ? `${selectedLog.quantity_change > 0 ? '+' : ''}${selectedLog.quantity_change}` : (selectedLog.action.includes('DB') ? 'SYS' : '±')}

Universal Timestamp

{new Date(selectedLog.timestamp).toLocaleString(undefined, { dateStyle: 'full', timeStyle: 'medium' })}

{selectedLog.target_snapshot && (() => { try { const snap = JSON.parse(selectedLog.target_snapshot) as Record; return (

Snapshot Record

{Object.entries(snap).map(([key, val]) => ( (val && key !== 'image_url' && key !== 'id') ? (

{key.replace('_', ' ').toLowerCase()}

{String(val)}

) : null ))}
); } catch (e) { return null; } })()} {selectedLog.details && (

Intervention Details

{selectedLog.details}
)}
)} ); }