'use client'; import { useState, useEffect } from 'react'; import { db, Item } from '@/lib/db'; import { inventoryApi } from '@/lib/api'; import PageShell from '@/components/PageShell'; import { History, X, Search, Filter } from 'lucide-react'; import { cn } from '@/lib/utils'; import { fetchAndCacheItems } from '@/lib/sync'; export default function LogsPage() { const [auditLogs, setAuditLogs] = useState([]); const [inventory, setInventory] = useState([]); const [loading, setLoading] = useState(true); const [searchQuery, setSearchQuery] = useState(''); useEffect(() => { loadData(); }, []); const loadData = async () => { setLoading(true); try { // Load inventory for name lookups const cached = await db.items.toArray(); setInventory(cached); // Fetch fresh logs const logs = await inventoryApi.getAuditLogs(50); setAuditLogs(logs); } catch (err) { console.error(err); } finally { setLoading(false); } }; const filteredLogs = auditLogs.filter(log => { const itemName = inventory.find(i => i.id === log.target_item_id)?.name || ''; return ( itemName.toLowerCase().includes(searchQuery.toLowerCase()) || log.action.toLowerCase().includes(searchQuery.toLowerCase()) || (log.username || '').toLowerCase().includes(searchQuery.toLowerCase()) ); }); return (

Audit History

Centralized Transaction Logs

setSearchQuery(e.target.value)} className="w-full bg-slate-900/50 border border-slate-800 focus:border-primary/50 rounded-2xl py-4 pl-12 pr-4 text-sm text-white placeholder:text-slate-600 outline-none transition-all shadow-inner" />
{loading ? (

Retrieving Logs From Cloud...

) : filteredLogs.length === 0 ? (

No transactions found

Try a different search term or check back later

) : (
{filteredLogs.map((log) => (
{log.action}
by {log.username || 'System'}
{inventory.find(i => i.id === log.target_item_id)?.name || `Item #${log.target_item_id}`}
{new Date(log.timestamp).toLocaleString()}
{log.details && ( {log.details} )}

0 ? "text-green-400" : "text-rose-400" )}> {log.quantity_change > 0 ? '+' : ''}{log.quantity_change}

))}
)}
); }