import { ArrowRight } from "lucide-react"; import { Badge, type BadgeProps } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { fmt } from "@/lib/format"; import type { ClaimDetail } from "@/types"; type MatchedRemitCardProps = { matchedRemittance: ClaimDetail["matchedRemittance"]; }; /** * Remittance status → Badge variant. Mirrors the list-endpoint mapping * in ``RemittanceStatus`` (received / posted / reconciled). Unknown * statuses (the type is an unconstrained string) fall back to ``muted`` * so a future backend status doesn't blow up the drawer. */ const STATUS_VARIANT: Record = { received: "secondary", posted: "default", reconciled: "success", }; function statusVariantFor(status: string): BadgeProps["variant"] { return STATUS_VARIANT[status] ?? "muted"; } /** * Matched-remittance card for the claim detail drawer (SP4). * * Renders only when the claim has been paired with an ERA (the * ``matchedRemittance`` field is non-null). Layout: a single card with * remit id + status badge + received date on the left, big mono * ``totalPaid`` on the right, plus a "View remittance →" link that * deep-links to ``/remittances?id={id}`` (v1: full page navigation via * ``window.location.href``; a router-based nav handler is a v2 concern). */ export function MatchedRemitCard({ matchedRemittance }: MatchedRemitCardProps) { if (matchedRemittance === null) return null; const { id, totalPaid, status, receivedAt } = matchedRemittance; // SP7: per-line counts may be missing on pre-SP7 claim-detail responses. const matchedLines = matchedRemittance.matchedLines; const totalLines = matchedRemittance.totalLines; const hasLineCounts = typeof matchedLines === "number" && typeof totalLines === "number"; const allMatched = hasLineCounts && matchedLines === totalLines; const handleViewRemittance = () => { window.location.href = `/remittances?id=${id}`; }; return (

Matched Remittance

{/* Left: remit id + status badge + received date */}
{id}
{status} Received {fmt.date(receivedAt)}
{/* Right: total paid + view-remittance link */}
{fmt.usdPrecise(totalPaid)}
{hasLineCounts ? ( lines: {matchedLines}/{totalLines} matched {!allMatched ? ` (${totalLines! - matchedLines!} unmatched)` : null} ) : null}
); }