import React from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { FoodItem } from '@/types/Database'; interface FoodItemCardProps { foodItem: FoodItem; categoryColor?: string; onPress?: () => void; showDetails?: boolean; } export const FoodItemCard: React.FC = (props) => { const { foodItem, categoryColor = 'border-gray-200 bg-gray-50', onPress, showDetails = true, } = props; const formatValue = (value?: number, unit: string = 'g') => { if (value === undefined || value === null) return '--'; return `${Math.round(value)}${unit}`; }; const getConfidenceColor = (confidence?: number) => { if (!confidence) return 'text-gray-400'; if (confidence >= 0.8) return 'text-green-600'; if (confidence >= 0.6) return 'text-yellow-600'; return 'text-red-600'; }; const getConfidenceIcon = (confidence?: number) => { if (!confidence) return 'help-outline'; if (confidence >= 0.8) return 'checkmark-circle-outline'; if (confidence >= 0.6) return 'warning-outline'; return 'alert-circle-outline'; }; const renderNutritionValue = ( label: string, value?: number, unit: string = 'g', color: string = 'text-gray-700' ) => { if (value === undefined || value === null) return null; return ( {formatValue(value, unit)} {label} ); }; const CardComponent = onPress ? TouchableOpacity : View; return ( {/* Header */} {foodItem.name} {foodItem.portion_size && ( {foodItem.portion_size} )} {/* Confidence Indicator */} {foodItem.confidence && ( {Math.round(foodItem.confidence * 100)}% )} {/* Nutrition Information */} {showDetails && ( {/* Main Calories */} {foodItem.calories && ( {formatValue(foodItem.calories, ' kcal')} Kalorien )} {/* Macronutrients */} {(foodItem.protein || foodItem.carbs || foodItem.fat) && ( {renderNutritionValue('Protein', foodItem.protein, 'g', 'text-blue-600')} {renderNutritionValue('Kohlenhydrate', foodItem.carbs, 'g', 'text-green-600')} {renderNutritionValue('Fett', foodItem.fat, 'g', 'text-orange-600')} )} {/* Additional nutrients */} {(foodItem.fiber || foodItem.sugar) && ( {renderNutritionValue('Ballaststoffe', foodItem.fiber, 'g', 'text-purple-600')} {renderNutritionValue('Zucker', foodItem.sugar, 'g', 'text-pink-600')} {/* Spacer for alignment */} )} {/* Food Properties */} {Boolean(foodItem.is_organic) && ( 🌱 Bio )} {Boolean(foodItem.is_processed) && ( 📦 Verarbeitet )} {/* Allergens */} {foodItem.allergens && ( Allergene: {(() => { try { const allergens = JSON.parse(foodItem.allergens); return Array.isArray(allergens) && allergens.length > 0 ? allergens.join(', ') : 'Keine'; } catch { return 'Keine'; } })()} )} )} ); };