import { router } from 'expo-router'; import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, View } from 'react-native'; import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { fetchCategories } from '@/src/api/recipes.api'; import { ErrorView } from '@/src/components/ErrorView'; import { Screen } from '@/src/components/Screen'; import { useAuth } from '@/src/context/AuthContext'; import { useAppearance } from '@/src/context/AppearanceContext'; import { MealCategory } from '@/src/types/recipe'; import { categoryLabel } from '@/src/utils/recipe'; const CATEGORY_EMOJI: Record = { [MealCategory.Breakfast]: '🍳', [MealCategory.SecondBreakfast]: '🥐', [MealCategory.Lunch]: '🍲', [MealCategory.Dinner]: '🌙', }; export default function DashboardScreen() { const { t } = useTranslation(); const { user } = useAuth(); const { colors } = useAppearance(); const categoriesQuery = useQuery({ queryKey: ['categories'], queryFn: fetchCategories, }); const welcome = user?.userName ? t('dashboard.welcomeNamed', { name: user.userName }) : t('dashboard.welcome'); return ( {categoriesQuery.isLoading ? ( ) : categoriesQuery.isError ? ( categoriesQuery.refetch()} /> ) : ( router.push('/(main)/(tabs)/meals')} style={({ pressed }) => [ styles.allCard, { backgroundColor: colors.brand, opacity: pressed ? 0.9 : 1, }, ]} > {t('nav.allMeals')} {t('dashboard.viewRecipes')} router.push('/(main)/ingredients')} style={({ pressed }) => [ styles.card, { backgroundColor: colors.surface, borderColor: colors.border, opacity: pressed ? 0.9 : 1, }, ]} > 🥬 {t('nav.ingredientCatalog')} {t('ingredientCatalog.subtitle')} router.push('/(main)/diet-generator')} style={({ pressed }) => [ styles.card, { backgroundColor: colors.surface, borderColor: colors.border, opacity: pressed ? 0.9 : 1, }, ]} > {t('nav.dietGenerator')} {t('generators.diet.subtitle')} router.push('/(main)/recipe-generator')} style={({ pressed }) => [ styles.card, { backgroundColor: colors.surface, borderColor: colors.border, opacity: pressed ? 0.9 : 1, }, ]} > 🤖 {t('nav.recipeGenerator')} {t('generators.recipe.subtitle')} {(categoriesQuery.data ?? []).map((item) => ( router.push(`/(main)/category/${item.category}`)} style={({ pressed }) => [ styles.card, { backgroundColor: colors.surface, borderColor: colors.border, opacity: pressed ? 0.9 : 1, }, ]} > {CATEGORY_EMOJI[item.category as MealCategory] ?? '🍽️'} {categoryLabel(item.category, t)} {t('common.recipeCount', { count: item.count })} ))} )} ); } const styles = StyleSheet.create({ list: { gap: 12, paddingBottom: 24, }, allCard: { borderRadius: 16, padding: 18, gap: 4, }, allTitle: { color: '#fff', fontSize: 20, fontWeight: '700', }, allSubtitle: { color: 'rgba(255,255,255,0.9)', fontSize: 14, }, card: { borderWidth: 1, borderRadius: 16, padding: 16, flexDirection: 'row', alignItems: 'center', gap: 14, }, emoji: { fontSize: 28, }, cardBody: { flex: 1, gap: 2, }, cardTitle: { fontSize: 18, fontWeight: '600', }, cardCount: { fontSize: 14, }, loading: { flex: 1, alignItems: 'center', justifyContent: 'center', paddingVertical: 40, }, });