import { useMemo, useState } from 'react'; import { ChevronDown, ClipboardCheck } from 'lucide-react'; import type { DirectorAcknowledgmentDocumentRow } from '@/business/director-dashboard/types'; import { cn } from '@/lib/utils'; interface DirectorAcknowledgmentTrackingPanelProps { readonly documents: readonly DirectorAcknowledgmentDocumentRow[]; } export function DirectorAcknowledgmentTrackingPanel({ documents, }: DirectorAcknowledgmentTrackingPanelProps) { const [isPanelExpanded, setIsPanelExpanded] = useState(false); const [expandedDocumentIds, setExpandedDocumentIds] = useState>( () => new Set(), ); const groupedDocuments = useMemo(() => groupDocumentsByCategory(documents), [documents]); const missingAcknowledgmentCount = documents.reduce( (total, document) => total + document.missingCount, 0, ); function toggleDocument(documentId: string) { setExpandedDocumentIds((current) => { const next = new Set(current); if (next.has(documentId)) { next.delete(documentId); } else { next.add(documentId); } return next; }); } return (
{isPanelExpanded && groupedDocuments.length === 0 ? (

No active documents are assigned to this scope yet.

) : isPanelExpanded ? (
{groupedDocuments.map((group) => (

{group.label}

{group.documents.map((document, index) => { const isExpanded = expandedDocumentIds.has(document.id); return (
0 ? 'border-t border-gray-100' : undefined} > {isExpanded && (
{document.missingStaff.length === 0 ? (

Every staff member in scope has acknowledged this version.

) : (

Not acknowledged

{document.missingStaff.map((staff) => (
{staff.name} {staff.role}
))}
)}
)}
); })}
))}
) : (

Expand to review document acknowledgment status by category.

)}
); } function groupDocumentsByCategory( documents: readonly DirectorAcknowledgmentDocumentRow[], ): readonly { readonly category: string; readonly label: string; readonly documents: readonly DirectorAcknowledgmentDocumentRow[]; }[] { const groups = new Map(); const labels = new Map(); for (const document of documents) { const rows = groups.get(document.category) ?? []; rows.push(document); groups.set(document.category, rows); labels.set(document.category, document.categoryLabel); } return [...groups.entries()].map(([category, rows]) => ({ category, label: labels.get(category) ?? category, documents: rows, })); } function getStatusClassName(missingCount: number): string { return missingCount > 0 ? 'rounded-lg bg-amber-100 px-2.5 py-1 text-xs font-semibold text-amber-700' : 'rounded-lg bg-emerald-100 px-2.5 py-1 text-xs font-semibold text-emerald-700'; }