"use client"; import { MapPin } from "lucide-react"; import { Input } from "~/components/ui/input"; import { Label } from "~/components/ui/label"; import { SearchableSelect } from "~/components/ui/select"; import { US_STATES, ALL_COUNTRIES, POPULAR_COUNTRIES, formatPostalCode, PLACEHOLDERS, } from "~/lib/form-constants"; interface AddressFormProps { addressLine1: string; addressLine2: string; city: string; state: string; postalCode: string; country: string; onChange: (field: string, value: string) => void; errors?: { addressLine1?: string; addressLine2?: string; city?: string; state?: string; postalCode?: string; country?: string; }; required?: boolean; className?: string; } export function AddressForm({ addressLine1, addressLine2, city, state, postalCode, country, onChange, errors = {}, required = false, className = "", }: AddressFormProps) { const handlePostalCodeChange = (value: string) => { const formatted = formatPostalCode(value, country || "US"); onChange("postalCode", formatted); }; // Combine popular and all countries, removing duplicates const countryOptions = [ { value: "__placeholder__", label: "Select a country", disabled: true }, { value: "divider-popular", label: "Popular Countries", disabled: true }, ...POPULAR_COUNTRIES, { value: "divider-all", label: "All Countries", disabled: true }, ...ALL_COUNTRIES.filter( (c) => !POPULAR_COUNTRIES.some((p) => p.value === c.value), ), ]; const stateOptions = [ { value: "__placeholder__", label: "Select a state", disabled: true }, ...US_STATES, ]; return (
{errors.addressLine1}
)}{errors.city}
)}{errors.state}
)}{errors.postalCode}
)}{errors.country}
)}