import { RotateCw } from "lucide-react"; import { candidatesOf, needsPicker, orderZoneOptions, type ZoneCheck } from "../../utils/locationTimeZoneCheck"; import { ComboboxControl } from "../ui/combobox-control"; import { Button } from "../ui/button"; import { Spinner } from "../ui/spinner"; import { FieldError } from "../ui/field"; type LocationTimeZoneFieldProps = { id: string; check: ZoneCheck; options: { label: string; value: string }[]; help: string; error?: string; disabled?: boolean; onCorrect: (timeZone: string) => void; onRetry: () => void; }; const NOTICE: Partial> = { ambiguous: "This address could be in more than one time zone. Choose the right one.", unverified: "We could not match this address, so its time zone was not looked up. Choose it below.", failed: "The time zone could not be looked up just now. Choose it below, or try again.", }; // A location's time zone, derived from its address (Spencer, 2026-09-23). The derived zone is shown // for confirmation; the picker appears only when the address is ambiguous, unmatched, the lookup // failed, or the admin chooses to change it. const LocationTimeZoneField = ({ id, check, options, help, error, disabled, onCorrect, onRetry, }: LocationTimeZoneFieldProps) => { const labelOf = (zone: string) => options.find((o) => o.value === zone)?.label ?? zone; const notice = NOTICE[check.state]; return (
Time zone {check.state === "unchecked" && (
We look this up once the address is complete.
)} {check.state === "checking" && (
Looking up the time zone
)} {check.state === "derived" && (
{labelOf(check.timeZone)} {check.address && ยท from {check.address}}
)} {notice && (
{notice} {check.state === "failed" && ( )}
)} {needsPicker(check) && ( zone && onCorrect(zone)} placeholder="Start typing a city or region" disabled={disabled} /> )}
{help}
{error && {error}}
); }; export default LocationTimeZoneField;