import React, { useState } from 'react'; import { Modal, View, Text, TextInput, TouchableOpacity, ScrollView, KeyboardAvoidingView, Platform, } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import { MealWithItems } from '../../types/Database'; import { useMealStore } from '../../store/MealStore'; interface EditMealModalProps { meal: MealWithItems | null; visible: boolean; onClose: () => void; } export const EditMealModal: React.FC = ({ meal, visible, onClose }) => { const { updateMeal } = useMealStore(); const [notes, setNotes] = useState(meal?.user_notes || ''); const [rating, setRating] = useState(meal?.user_rating || 0); const [location, setLocation] = useState(meal?.location || ''); const [isSaving, setIsSaving] = useState(false); React.useEffect(() => { if (meal) { setNotes(meal.user_notes || ''); setRating(meal.user_rating || 0); setLocation(meal.location || ''); } }, [meal]); const handleSave = async () => { if (!meal) return; setIsSaving(true); try { await updateMeal(meal.id, { user_notes: notes.trim() || null, user_rating: rating || null, location: location.trim() || null, }); onClose(); } catch (error) { console.error('Failed to update meal:', error); } finally { setIsSaving(false); } }; const renderStars = () => { return ( {[1, 2, 3, 4, 5].map((star) => ( setRating(star)} className="p-2"> ))} ); }; if (!meal) return null; return ( {/* Header */} Abbrechen Mahlzeit bearbeiten {isSaving ? 'Speichert...' : 'Fertig'} {/* Content */} {/* Rating */} Bewertung {renderStars()} {rating > 0 && ( setRating(0)} className="mt-2 self-center"> Bewertung entfernen )} {/* Location */} Ort {/* Notes */} Notizen {/* Meal Info */} Mahlzeit-Info {meal.food_items?.map((item) => item.name).join(', ') || 'Keine Lebensmittel erkannt'} {meal.total_calories && ( {Math.round(meal.total_calories)} kcal )} ); };