{label}
{rows.map((row, index) => (
{render(row, (patch) =>
onChange(rows.map((r, i) => (i === index ? { ...r, ...patch } : r)))
)}
))}
);
}
function initialsFromName(name: string): string {
const parts = name.trim().split(/\s+/).filter(Boolean);
if (parts.length === 0) {
return "?";
}
return parts
.slice(0, 2)
.map((part) => part[0])
.join("")
.toUpperCase();
}
const formatDate = (date: Date) =>
date.toLocaleDateString("en-US", {
month: "short",
day: "2-digit",
year: "numeric",
});
const today = () => formatDate(new Date());
// Patient dates are stored as formatted strings (e.g. "Jun 02, 2026"); parse one
// back to a Date so the calendar can highlight the current selection.
function parseDate(value: string): Date | undefined {
const trimmed = value.trim();
if (!trimmed) {
return undefined;
}
const parsed = new Date(trimmed);
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
}
// Calendar-backed date field that reads/writes the same formatted string the rest
// of the form uses.
function DatePicker({
value,
onChange,
ariaLabel,
placeholder,
className,
}: {
value: string;
onChange: (value: string) => void;
ariaLabel: string;
placeholder?: string;
className?: string;
}) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const placeholderText = placeholder ?? t("patientForm.pickDate");
return (