'use client' import { useState } from 'react' import Link from 'next/link' const TYPE_LABELS: Record = { injury: 'Injury / Medical', near_miss: 'Near Miss', hazard: 'Hazard', asset_damage: 'Asset Damage', environmental: 'Environmental', security: 'Security', fire: 'Fire / Emergency', transport: 'Transport / Vehicle', } const STATUS_COLORS: Record = { reported: 'bg-yellow-100 text-yellow-800', triaged: 'bg-blue-100 text-blue-800', investigating: 'bg-purple-100 text-purple-800', capa_pending: 'bg-orange-100 text-orange-800', verification: 'bg-indigo-100 text-indigo-800', closed: 'bg-green-100 text-green-800', } export type Incident = { id: string reference_no: string | null incident_type: string status: string severity: number | null reported_at: string sites: { name: string } | null zones: { name: string } | null trucks: { truck_no: string } | null reporter: { name: string } | null } interface Props { incidents: Incident[] basePath: string } export function IncidentList({ incidents, basePath }: Props) { const [typeFilter, setTypeFilter] = useState('') const [statusFilter, setStatusFilter] = useState('') const [search, setSearch] = useState('') const filtered = incidents.filter(inc => { if (typeFilter && inc.incident_type !== typeFilter) return false if (statusFilter && inc.status !== statusFilter) return false if (search) { const q = search.toLowerCase() return ( inc.reference_no?.toLowerCase().includes(q) || inc.incident_type.includes(q) || (inc.sites?.name ?? '').toLowerCase().includes(q) ) } return true }) return (
setSearch(e.target.value)} />
{filtered.length === 0 ? (
No incidents found
) : (
{filtered.map(inc => (
{inc.reference_no ?? '—'} {inc.status.replace(/_/g, ' ').toUpperCase()}
{TYPE_LABELS[inc.incident_type] ?? inc.incident_type} {inc.zones?.name && ` · ${inc.zones.name}`} {inc.sites?.name && ` · ${inc.sites.name}`} {inc.trucks?.truck_no && ( · {inc.trucks.truck_no} )}
{new Date(inc.reported_at).toLocaleDateString('en-MY')}
{inc.severity && (
Sev {inc.severity}
)}
))}
)}
) }