import { useT } from "@agent-native/core/client/i18n"; import { IconCheck, IconChevronDown } from "@tabler/icons-react"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; const FALLBACK_TIMEZONES = [ "UTC", "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", "America/Sao_Paulo", "Europe/London", "Europe/Paris", "Europe/Berlin", "Europe/Moscow", "Africa/Cairo", "Asia/Jerusalem", "Asia/Dubai", "Asia/Kolkata", "Asia/Singapore", "Asia/Tokyo", "Asia/Shanghai", "Australia/Sydney", "Pacific/Auckland", ]; function getSupportedTimezones(currentTimezone: string) { const supported = typeof Intl !== "undefined" && (Intl as any).supportedValuesOf ? ((Intl as any).supportedValuesOf("timeZone") as string[]) : FALLBACK_TIMEZONES; return Array.from(new Set([currentTimezone, ...supported].filter(Boolean))); } function getTimezoneCity(timezone: string) { const city = timezone.split("/").pop() || timezone; return city.replace(/_/g, " "); } function getTimezoneRegion(timezone: string) { const region = timezone.split("/")[0] || ""; return region.replace(/_/g, " "); } export function TimezoneCombobox({ id = "timezone", value, onChange, }: { id?: string; value: string; onChange: (timezone: string) => void; }) { const [open, setOpen] = useState(false); const t = useT(); const options = getSupportedTimezones(value).map((timezone) => { const city = getTimezoneCity(timezone); const region = getTimezoneRegion(timezone); return { timezone, city, region, searchValue: `${city} ${region} ${timezone}`.trim(), }; }); const selected = options.find((option) => option.timezone === value); return ( {t("timezone.empty")} {options.map((option) => ( { onChange(option.timezone); setOpen(false); }} >

{option.city}

{option.timezone}

))}
); }