import { IngredientTagList } from '@/add-log/components/IngredientTagList'; import { BottomSheet, BottomSheetTextInput } from '@/aesthetics/BottomSheet'; import { Text } from '@/aesthetics/Text'; import { colors, useColors } from '@/aesthetics/styles'; import { useHaptics } from '@/aesthetics/useHaptics'; import { useStrings } from '@/common/hooks/useStrings'; import type { Suggestion } from '@/types/foodlog'; import { Plus, X } from 'lucide-react-native'; import { useState } from 'react'; import { Pressable, ScrollView, StyleSheet, View } from 'react-native'; type SuggestionListProps = { suggestions: Suggestion[]; onPressSuggestion: (suggestion: Suggestion) => void; onDeleteSuggestion: (id: string) => void; onAddSuggestion: (name: string, ingredients: string[]) => void; }; export function SuggestionList({ suggestions, onPressSuggestion, onDeleteSuggestion, onAddSuggestion, }: SuggestionListProps) { const c = useColors(); const strings = useStrings(); const { impact, ImpactStyle } = useHaptics(); const [editMode, setEditMode] = useState(false); const [showAddModal, setShowAddModal] = useState(false); const [newName, setNewName] = useState(''); const [newIngredients, setNewIngredients] = useState([]); const [newIngredient, setNewIngredient] = useState(''); const closeAddModal = () => { setShowAddModal(false); setNewName(''); setNewIngredients([]); setNewIngredient(''); }; const handleAddSuggestion = () => { const trimmedName = newName.trim(); if (!trimmedName) return; onAddSuggestion(trimmedName, newIngredients); closeAddModal(); }; const handleAddIngredient = () => { const trimmed = newIngredient.trim(); if (trimmed && !newIngredients.includes(trimmed)) { setNewIngredients(prev => [...prev, trimmed]); } setNewIngredient(''); }; const handleRemoveIngredient = (ingredient: string) => { setNewIngredients(prev => prev.filter(i => i !== ingredient)); }; return ( <> {suggestions.map(suggestion => ( { if (editMode) { setEditMode(false); return; } onPressSuggestion(suggestion); }} onLongPress={() => { impact(ImpactStyle.Medium); setEditMode(true); }} delayLongPress={300} style={({ pressed }) => [styles.pill, { opacity: pressed ? 0.7 : 1 }]} > {suggestion.label} {editMode && ( onDeleteSuggestion(suggestion.id)} hitSlop={8} > )} ))} {editMode ? ( setEditMode(false)}> {strings.common.done} ) : ( setShowAddModal(true)}> )} {strings.addLog.log.foodItem} {strings.addLog.log.addShortcut} ); } const styles = StyleSheet.create({ suggestionsArea: { paddingHorizontal: 16, marginTop: 12 }, pillScroll: { paddingBottom: 12, paddingHorizontal: 4, gap: 8 }, pill: { borderRadius: 18 }, pillBlur: { paddingHorizontal: 14, height: 36, justifyContent: 'center', borderRadius: 18, backgroundColor: colors.camera.pillBg, }, pillText: { fontSize: 14, color: colors.camera.text }, pillDelete: { position: 'absolute', top: -4, right: -4, width: 16, height: 16, borderRadius: 8, backgroundColor: colors.camera.deleteBg, alignItems: 'center', justifyContent: 'center', zIndex: 1, }, addPillBlur: { width: 36, height: 36, paddingHorizontal: 0, paddingVertical: 0, alignItems: 'center', justifyContent: 'center', backgroundColor: colors.camera.buttonBgActive, }, donePillBlur: { backgroundColor: colors.camera.doneBg }, doneText: { color: colors.camera.text, fontWeight: '600', fontSize: 14 }, label: { fontSize: 14, fontWeight: '500', marginBottom: 8 }, input: { borderWidth: 1, borderRadius: 12, paddingHorizontal: 16, paddingVertical: 14, fontSize: 16, marginBottom: 20, }, saveBtn: { paddingVertical: 16, borderRadius: 12, alignItems: 'center' }, saveText: { fontSize: 16, fontWeight: '600' }, });