import React, { useState, useCallback } from 'react'; import { View, Text, StyleSheet, KeyboardAvoidingView, Platform, ScrollView, TouchableOpacity, } from 'react-native'; import { router, useLocalSearchParams } from 'expo-router'; import { Ionicons } from '@expo/vector-icons'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { ErrorMessage } from '@/components/ui/ErrorMessage'; import { AppColors, BorderRadius, FontSizes, Spacing } from '@/constants/theme'; import { api } from '@/services/api'; export default function AddLovedOneScreen() { const params = useLocalSearchParams<{ email: string; partnerCode: string }>(); const email = params.email || ''; const partnerCode = params.partnerCode || ''; const [lovedOneName, setLovedOneName] = useState(''); const [relationship, setRelationship] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const relationships = [ { id: 'parent', label: 'Parent', icon: 'people' }, { id: 'grandparent', label: 'Grandparent', icon: 'heart' }, { id: 'spouse', label: 'Spouse', icon: 'heart-circle' }, { id: 'other', label: 'Other', icon: 'person' }, ]; const handleContinue = useCallback(async () => { setError(null); const trimmedName = lovedOneName.trim(); if (!trimmedName) { setError('Please enter the name of your loved one'); return; } if (!relationship) { setError('Please select your relationship'); return; } setIsLoading(true); try { // TODO: Save loved one data to backend // For now, just navigate to the purchase/subscription screen router.replace({ pathname: '/(auth)/purchase', params: { lovedOneName: trimmedName, relationship, partnerCode, }, }); } catch (err) { setError(err instanceof Error ? err.message : 'Something went wrong'); } finally { setIsLoading(false); } }, [lovedOneName, relationship, partnerCode]); const handleSkip = async () => { // Mark onboarding as completed so we don't redirect back here await api.setOnboardingCompleted(true); // Skip and go to main app without adding loved one router.replace('/(tabs)'); }; return ( {/* Skip Button */} Skip for now {/* Icon */} {/* Header */} Add a Loved One Tell us about the person you want to care for {/* Error Message */} {error && ( setError(null)} /> )} {/* Form */} { setLovedOneName(text); setError(null); }} autoCapitalize="words" autoCorrect={false} editable={!isLoading} returnKeyType="done" /> {/* Relationship Selection */} Relationship {relationships.map((rel) => ( { setRelationship(rel.id); setError(null); }} disabled={isLoading} > {rel.label} ))} {/* Continue Button */}