import type { ReactNode } from "react"; import type { Address } from "fhir/r4"; import { Input } from "../components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../components/ui/select"; import { StateSelect } from "../components/ui/state-select"; import { ADDRESS_CITY_CLASS, ADDRESS_ROW_CLASS, ADDRESS_STATE_CLASS, ADDRESS_STATE_ZIP_GROUP_CLASS, ADDRESS_ZIP_CLASS, } from "../components/ui/address-row"; import { sanitizeUsPostalCode } from "./usStates"; // Flat draft model for the emergency-contact multi-part editor (mapped to/from a `Patient.contact[]` // entry by each caller - see `PatientProfileCard`'s `setEmergencyContact`/`emergencyContactDraft` // (single, staff card) and `EmergencyContacts`'s `setEmergencyContactAt`/`emergencyContactToDraft` // (multi, patient card)). export interface EmergencyContactDraft { given: string; family: string; relationship: string; phone: string; email: string; } /** * Multi-part `renderEditor` for a FHIR `Address` - plain `ui/input`, no `@wordpress/components`, * so it ports cleanly wherever it's used. Extracted out of `PatientProfileCard` (staff patient * edit) so the patient-self profile cards can reuse it without duplicating the markup. * * Matches `EditableField`'s `renderEditor` prop signature exactly * (`(draft, setDraft, disabled) => ReactNode`), so callers can pass it straight through: * `renderEditor={AddressEditor}` - no wrapping arrow function needed. */ export const AddressEditor = ( draft: Address, setDraft: (value: Address) => void, disabled: boolean, ): ReactNode => { const line = draft.line ?? []; const set = (patch: Partial
) => setDraft({ ...draft, ...patch }); const setLine = (index: number, next: string) => { const lines = [line[0] ?? "", line[1] ?? ""]; lines[index] = next; setDraft({ ...draft, line: lines }); }; return (