export type Party = { id: string; name: string | null; kind: 'person' | 'entity'; source: string | null; roles: string[]; represented_id: string | null; cash: string | null; in_kind: string | null; paid: string | null; share_count: string | null; work: string | null; commitment: string | null; source_snapshot?: { origin: string; reference: string; version: string | number | null; }; }; export type CompanyFacts = { form: string | null; proposed_name: string | null; seat: string | null; activities: string | null; regulated: string; currency: string | null; capital: string | null; nominal_value: string | null; management: string | null; binding: string | null; notes: string | null; parties: Party[]; }; /** Read actual form values, including autofill, without serializing private provenance. */ export function preparationValues( form: HTMLFormElement, facts: CompanyFacts, ): CompanyFacts { const data = new FormData(form); const value = (key: string, fallback: string | null) => { const v = data.get(key); return typeof v === 'string' ? v.trim() || null : fallback; }; return { form: value('form', facts.form), proposed_name: value('proposed_name', facts.proposed_name), seat: value('seat', facts.seat), activities: value('activities', facts.activities), regulated: value('regulated', facts.regulated) ?? 'unknown', currency: value('currency', facts.currency), capital: value('capital', facts.capital), nominal_value: value('nominal_value', facts.nominal_value), management: value('management', facts.management), binding: value('binding', facts.binding), notes: value('notes', facts.notes), parties: facts.parties.map((p) => ({ id: p.id, name: value(`${p.id}.name`, p.name), kind: p.kind, source: p.source, roles: p.roles, represented_id: p.represented_id, cash: value(`${p.id}.cash`, p.cash), in_kind: value(`${p.id}.in_kind`, p.in_kind), paid: value(`${p.id}.paid`, p.paid), share_count: value(`${p.id}.share_count`, p.share_count), work: value(`${p.id}.work`, p.work), commitment: value(`${p.id}.commitment`, p.commitment), })), }; }