import { Ionicons } from "@expo/vector-icons"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { ActivityIndicator, Modal, Pressable, ScrollView, Text, TextInput, View, } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { TransactionScreen } from "@/src/components/features/transactions/TransactionScreen"; import { useChildren, useCreateChild, type Child } from "@/src/hooks/useChildren"; import { ModalHeader } from "@/src/components/ui/ModalHeader"; const CHILD_COLORS = [ "#ec4899", "#f59e0b", "#10b981", "#2563EB", "#7c3aed", "#ef4444", "#0ea5e9", "#378ADD", ]; function AddChildModal({ visible, onClose, onCreated, }: { visible: boolean; onClose: () => void; onCreated: (child: Child) => void; }) { const [name, setName] = useState(""); const [color, setColor] = useState(CHILD_COLORS[0]!); const { t } = useTranslation(); const { mutate: createChild, isPending } = useCreateChild(); function handleSave() { const trimmed = name.trim(); if (!trimmed) return; createChild( { name: trimmed, color }, { onSuccess: (data) => { onCreated(data.child); setName(""); setColor(CHILD_COLORS[0]!); onClose(); }, }, ); } function handleClose() { setName(""); setColor(CHILD_COLORS[0]!); onClose(); } return ( {/* Header */} {/* Name Input */} Name {/* Color Picker */} Farbe {CHILD_COLORS.map((c) => ( setColor(c)} style={{ width: 40, height: 40, borderRadius: 20, backgroundColor: c, alignItems: "center", justifyContent: "center", borderWidth: color === c ? 3 : 0, borderColor: "#fff", shadowColor: color === c ? c : "transparent", shadowOpacity: color === c ? 0.5 : 0, shadowRadius: 4, elevation: color === c ? 4 : 0, }} > {color === c && ( )} ))} ); } export default function KinderScreen() { const insets = useSafeAreaInsets(); const { t } = useTranslation(); const { data: children = [], isLoading } = useChildren(); const [activeChildId, setActiveChildId] = useState(null); const [showAddModal, setShowAddModal] = useState(false); // Determine active child — fall back to first child when list loads const activeChild = children.find((c) => c.id === activeChildId) ?? children[0] ?? null; if (isLoading) { return ( ); } return ( {/* Empty State */} {children.length === 0 && ( {t('children.noChildren')} {t('children.noChildrenHint')} setShowAddModal(true)} className="px-6 py-3 rounded-full items-center justify-center" style={{ backgroundColor: "#ec4899" }} > + {t('children.addChild')} )} {/* Children Tab Switcher + Content */} {children.length > 0 && activeChild && ( {children.map((child) => { const isActive = child.id === activeChild.id; return ( setActiveChildId(child.id)} style={{ paddingHorizontal: 16, paddingVertical: 7, borderRadius: 20, backgroundColor: isActive ? child.color : "#f3f4f6", }} > {child.name} ); })} {/* Add Child Button */} setShowAddModal(true)} style={{ width: 32, height: 32, borderRadius: 16, backgroundColor: "#fce7f3", alignItems: "center", justifyContent: "center", }} > } /> )} setShowAddModal(false)} onCreated={(child) => setActiveChildId(child.id)} /> ); }