import { useUpdateHouseholdSettings } from "@/src/hooks/useHouseholdSettings"; import { Ionicons } from "@expo/vector-icons"; import { useRouter } from "expo-router"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { ActivityIndicator, Pressable, ScrollView, Text, TextInput, View, } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; const ACCENT = "#2563EB"; const SHARE_PRESETS = [50, 60, 75, 100]; export default function SetupScreen() { const insets = useSafeAreaInsets(); const router = useRouter(); const { t } = useTranslation(); const { mutate: updateSettings, isPending } = useUpdateHouseholdSettings(); const [step, setStep] = useState<1 | 2 | 3 | 4>(1); const [ownerName, setOwnerName] = useState(""); const [partnerName, setPartnerName] = useState(""); const [userSharePercent, setUserSharePercent] = useState(50); const [monthlyBudget, setMonthlyBudget] = useState("400"); const [splitChildCosts, setSplitChildCosts] = useState(true); function handleSkip() { finalize(); } function finalize() { const input = { ownerName: ownerName.trim() || "Ich", partnerName: partnerName.trim() || "Partner", userSharePercent, monthlyBudget: parseFloat(monthlyBudget.replace(",", ".")) || 400, splitChildCosts, onboardingComplete: true, }; updateSettings(input, { onSuccess: () => router.replace("/(app)/haushalt"), onError: () => router.replace("/(app)/haushalt"), }); } return ( {/* Progress bar */} {([1, 2, 3, 4] as const).map((s) => ( ))} {/* Skip */} {t('onboarding.skip')} {/* Step 1 — Willkommen */} {step === 1 && ( 💰 {t('onboarding.welcome')} {t('onboarding.subtitle')} )} {/* Step 2 — Namen */} {step === 2 && ( {t('setup.namesTitle')} {t('setup.namesHint')} {t('onboarding.yourName')} {t('settings.household.partnerName')} )} {/* Step 3 — Kostenaufteilung */} {step === 3 && ( {t('setup.costSplitTitle')} {t('setup.costSplitHint')} {/* Preset buttons */} {SHARE_PRESETS.map((p) => ( setUserSharePercent(p)} className="flex-1 py-3 rounded-xl items-center" style={{ backgroundColor: userSharePercent === p ? ACCENT : "#f3f4f6", }} > {p}% ))} {/* Preview */} {t('onboarding.preview', { own: userSharePercent, partner: partnerName.trim() || 'Partner', rest: 100 - userSharePercent, })} {/* Monthly budget */} {t('setup.monthlyBudgetLabel')} {/* Split child costs */} {t('setup.splitChildCostsLabel')} setSplitChildCosts(true)} className="flex-1 py-3 rounded-xl items-center" style={{ backgroundColor: splitChildCosts ? ACCENT : "#f3f4f6" }} > {t('common.yes')} setSplitChildCosts(false)} className="flex-1 py-3 rounded-xl items-center" style={{ backgroundColor: !splitChildCosts ? ACCENT : "#f3f4f6" }} > {t('common.no')} )} {/* Step 4 — Fertig */} {step === 4 && ( {t('onboarding.done')} {t('onboarding.doneHint')} )} {/* Bottom CTA */} {step < 4 ? ( setStep(((step + 1) as 1 | 2 | 3 | 4))} className="rounded-2xl py-4 items-center active:opacity-80" style={{ backgroundColor: ACCENT }} > {step === 1 ? t('onboarding.start') : t('common.next')} ) : ( {isPending ? ( ) : ( {t('onboarding.startApp')} )} )} ); }