import { useState } from "react"; import { AlertCircle } from "lucide-react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "../../../components/ui/dialog.tsx"; import { Alert, AlertDescription } from "../../../components/ui/alert.tsx"; import { Button } from "../../../components/ui/button.tsx"; import { priorityWord } from "../../../components/ui/row-meta.tsx"; import type { BenchRow } from "../../../hooks/useBench.ts"; import { ActWithdrawn } from "../DiagnosticOrdersPage/ActWithdrawn.tsx"; import { dayAndTime } from "./benchTime.ts"; // Collection and receipt are separate acts: collecting moves the order, receiving mints the accession. const COPY = { collect: { title: "Mark specimen collected", confirm: "Confirm the specimen has been collected for this order.", note: "This updates the order status. Do not treat it as accessioning or label printing.", action: "Mark collected", busy: "Marking collected…", }, receive: { title: "Receive specimen", confirm: "Confirm the specimen for this order has been received.", note: "Receiving gives the specimen its accession number from its test specimen requirements.", action: "Receive specimen", busy: "Receiving…", }, } as const; interface Props { mode: keyof typeof COPY; row?: BenchRow; onClose: () => void; /** Rejects with the words to show when nothing changed. */ onConfirm: (row: BenchRow) => Promise; /** At receipt only: the tube can be turned away instead of accepted. */ onReject?: (row: BenchRow) => void; /** The caller may no longer make this write: the dialog stays readable and closable, and cannot send. */ withdrawn?: boolean; } export const CollectDialog = ({ mode, row, onClose, onConfirm, onReject, withdrawn }: Props) => { const copy = COPY[mode]; const [busy, setBusy] = useState(false); const [error, setError] = useState(); if (!row) return null; const ordered = dayAndTime(row.authoredOn); const detail = [ordered ? `Ordered ${ordered}` : undefined, priorityWord(row.priority), row.container, row.volume] .filter(Boolean) .join(" · "); const submit = async () => { setBusy(true); setError(undefined); try { await onConfirm(row); } catch (failure) { setError(failure instanceof Error ? failure.message : String(failure)); } finally { setBusy(false); } }; return ( { if (!open && !busy) onClose(); }}> {copy.title}
{`${row.patientDisplay ?? "Patient not recorded"} · ${row.test ?? "Test not recorded"}`} {detail ? {detail} : null}
{copy.confirm}

{copy.note}

{error ? ( {error} ) : null} {withdrawn ? : null} {mode === "receive" && onReject ? ( ) : null}
); };