'use client' import { useState } from 'react' import Link from 'next/link' type CapaStatus = 'open' | 'in_progress' | 'overdue' | 'pending_verification' | 'verified' | 'reopened' | 'closed' type CapaAction = { id: string incident_id: string description: string department: string due_date: string priority: 'low' | 'med' | 'high' status: CapaStatus incidents: { reference_no: string | null } | null owner: { name: string } | null } const STATUS_ORDER: CapaStatus[] = ['open', 'in_progress', 'overdue', 'pending_verification', 'verified', 'closed'] const STATUS_LABELS: Record = { open: 'Open', in_progress: 'In Progress', overdue: 'Overdue', pending_verification: 'Pending Verification', verified: 'Verified', reopened: 'Reopened', closed: 'Closed', } const STATUS_COLORS: Record = { open: 'bg-blue-50 border-blue-200', in_progress: 'bg-yellow-50 border-yellow-200', overdue: 'bg-red-50 border-red-200', pending_verification: 'bg-purple-50 border-purple-200', verified: 'bg-green-50 border-green-200', reopened: 'bg-orange-50 border-orange-200', closed: 'bg-gray-50 border-gray-200', } const PRIORITY_BADGE: Record<'low' | 'med' | 'high', string> = { low: 'bg-gray-100 text-gray-600', med: 'bg-yellow-100 text-yellow-700', high: 'bg-red-100 text-red-700', } interface Props { capas: CapaAction[] } export function CapaBoard({ capas }: Props) { const [view, setView] = useState<'board' | 'table'>('board') const byStatus = STATUS_ORDER.reduce>((acc, s) => { acc[s] = capas.filter(c => c.status === s) return acc }, {} as Record) if (view === 'table') { return (
{capas.map(c => ( ))}
Ref Action Owner Due Priority Status
{(c.incidents as { reference_no: string | null } | null)?.reference_no ?? '—'} {c.description} {(c.owner as { name: string } | null)?.name ?? '—'} {c.due_date} {c.priority} {STATUS_LABELS[c.status]}
) } return (
{STATUS_ORDER.filter(s => s !== 'reopened').map(status => (

{STATUS_LABELS[status]} ({byStatus[status].length})

{byStatus[status].map(c => (

{c.description}

{(c.owner as { name: string } | null)?.name ?? '—'} {c.priority}

Due {c.due_date}

))} {byStatus[status].length === 0 && (

Empty

)}
))}
) }