"use client"; import { NumberField, SelectField, TextField } from "@/components/FormField"; import type { HouseholdType, PersonRole } from "@/lib/types"; export interface ProfileDraft { householdType: HouseholdType; inflationRateDefault: number; startYear: number; persons: { role: PersonRole; name: string; age: number; retirementAge: number }[]; } export function emptyProfileDraft(): ProfileDraft { return { householdType: "SINGLE", inflationRateDefault: 1.5, startYear: new Date().getFullYear(), persons: [{ role: "PERSON_A", name: "", age: 35, retirementAge: 65 }], }; } // Gemeinsame Formularfelder für das Grundprofil eines Plans (Haushaltsform, Personen, // Inflation). Wird beim Plan-Erstellen und in den Plan-Einstellungen verwendet. export function PlanProfileFields({ draft, onChange, }: { draft: ProfileDraft; onChange: (next: ProfileDraft) => void; }) { function setType(type: HouseholdType) { if (type === "SINGLE") { onChange({ ...draft, householdType: type, persons: draft.persons.slice(0, 1) }); } else { const persons = draft.persons.length < 2 ? [...draft.persons, { role: "PERSON_B" as PersonRole, name: "", age: 35, retirementAge: 65 }] : draft.persons; onChange({ ...draft, householdType: type, persons }); } } function updatePerson(index: number, patch: Partial) { onChange({ ...draft, persons: draft.persons.map((p, i) => (i === index ? { ...p, ...patch } : p)), }); } return (
{draft.persons.map((person, index) => (
{draft.householdType === "COUPLE" ? (person.role === "PERSON_A" ? "Person A" : "Person B") : "Deine Angaben"}
updatePerson(index, { name: v })} />
updatePerson(index, { age: Math.round(v) })} /> updatePerson(index, { retirementAge: Math.round(v) })} />
))} onChange({ ...draft, startYear: Math.round(v) })} /> onChange({ ...draft, inflationRateDefault: v })} />
); }