import type { AuditItemResult } from "../../api/types"; const tierColors: Record = { critical: "var(--ctp-red)", low: "var(--ctp-peach)", partial: "var(--ctp-yellow)", good: "var(--ctp-green)", complete: "var(--ctp-teal)", }; interface AuditTableProps { items: AuditItemResult[]; loading: boolean; selectedPN: string | null; onSelect: (pn: string) => void; } export function AuditTable({ items, loading, selectedPN, onSelect, }: AuditTableProps) { if (loading) { return (
Loading audit data...
); } if (items.length === 0) { return (
No items found
); } return (
{[ "Score", "Part Number", "Description", "Category", "Sourcing", "Missing", ].map((h) => ( ))} {items.map((item) => { const color = tierColors[item.tier] ?? "var(--ctp-subtext0)"; const isSelected = selectedPN === item.part_number; return ( onSelect(item.part_number)} style={{ cursor: "pointer", backgroundColor: isSelected ? "var(--ctp-surface1)" : "transparent", transition: "background-color 0.15s", }} onMouseEnter={(e) => { if (!isSelected) e.currentTarget.style.backgroundColor = "var(--ctp-surface0)"; }} onMouseLeave={(e) => { if (!isSelected) e.currentTarget.style.backgroundColor = "transparent"; }} > ); })}
{h}
{(item.score * 100).toFixed(0)}% {item.part_number} {item.description} {item.category_name || item.category} {item.sourcing_type} {item.missing.length}
); } const thStyle: React.CSSProperties = { textAlign: "left", padding: "var(--d-th-py) var(--d-th-px)", fontSize: "var(--d-th-font)", borderBottom: "1px solid var(--ctp-surface1)", color: "var(--ctp-subtext0)", fontWeight: 500, position: "sticky", top: 0, backgroundColor: "var(--ctp-base)", zIndex: 1, }; const tdStyle: React.CSSProperties = { padding: "var(--d-td-py) var(--d-td-px)", fontSize: "var(--d-td-font)", borderBottom: "1px solid var(--ctp-surface0)", color: "var(--ctp-text)", };