import { normalizeStateCode } from "@/data/areas"; import type { LocationFormValues } from "@/domain/locations/schemas/location-schema"; import type { Location } from "@/domain/locations/types/location"; /** Edit-mode defaults from a site; zip and title are carried so a save keeps them. */ export function toSiteFormValues(location: Location): LocationFormValues { const contacts = location.contacts && location.contacts.length > 0 ? location.contacts : [{ name: location.contact ?? "", phone: location.phone ?? "" }]; return { name: location.name ?? "", accountId: location.accountId != null ? String(location.accountId) : "", address: location.address ?? "", city: location.city ?? "", state: normalizeStateCode(location.state) ?? "", sitePhone: location.sitePhone ?? "", contactEmail: location.contactEmail ?? "", contacts, zipCode: location.zipCode ?? "", title: location.title ?? "", }; }