/** * Pure helpers for the Company Settings form. * * Lives alongside CompanySettingsPage so the PERSONAL → Business upgrade * hydration rule can be unit-tested without a DOM test environment. * * (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) */ import type { Address, LegalForm } from '@archer/domain'; import type { Company } from '@/domain/entities/Company'; export interface CompanyFormState { name: string; website: string; vatId: string; industry: string; size: string; billingEmail: string; address: Address; legalForm: LegalForm | ''; taxNumber: string; registerCourt: string; registerNumber: string; directorName: string; } /** * Derive initial form state from the loaded Company + the viewer's PERSONAL * flag. When the account is PERSONAL, the `name` column on the server holds * the person's full name ("Max Mustermann") — we blank it so the upgrade * flow forces a real business name. `address.country` is pre-populated from the * signup country when present; when it is absent (legacy / non-wizard accounts * that never persisted a country) it defaults to 'DE' (German-first) so the * country combobox auto-selects a value instead of rendering blank — the user * can still change it. Every other field flows through untouched. */ export function initialCompanyFormState( company: Pick, isPersonalUpgrade: boolean, ): CompanyFormState { return { name: isPersonalUpgrade ? '' : company.name ?? '', website: company.website ?? '', vatId: company.vatId ?? '', industry: company.industry ?? '', size: company.size ?? '', billingEmail: company.billingEmail ?? '', address: { ...(company.address ?? {}), country: company.address?.country || 'DE' }, legalForm: (company.legalForm as LegalForm | undefined) ?? '', taxNumber: company.taxNumber ?? '', registerCourt: company.registerCourt ?? '', registerNumber: company.registerNumber ?? '', directorName: company.directorName ?? '', }; }