import { useState, useMemo } from 'react'; function parseIngredientString(raw) { if (typeof raw !== 'string') return raw; const m = raw.match(/^([\d½¼¾⅓⅔.,–\-]+\s*(?:g|kg|ml|l|EL|TL|Stück|Packung|Prise|Bund|Dose|Scheibe|cm|dick)?)\s*(.*)/i); if (m) { const amount = m[1].trim(); const rest = m[2].trim(); const unitMatch = rest.match(/^((?:g|kg|ml|l|EL|TL|Stück|Packung|Prise|Bund|Dose|Scheibe|dick)s?)\s+(.*)/i); if (unitMatch) { return { amount, unit: unitMatch[1], name: unitMatch[2] }; } return { amount, unit: '', name: rest }; } return { amount: '', unit: '', name: raw }; } function normalizeIngredients(ingredients) { return ingredients.map(ing => typeof ing === 'string' ? parseIngredientString(ing) : ing ); } export default function IngredientList({ ingredients, editable, onChange }) { const [checked, setChecked] = useState({}); const normalized = useMemo(() => normalizeIngredients(ingredients), [ingredients]); const toggle = (i) => setChecked(prev => ({ ...prev, [i]: !prev[i] })); const updateIngredient = (i, field, value) => { const updated = normalized.map((ing, idx) => idx === i ? { ...ing, [field]: value } : ing ); onChange(updated); }; const addIngredient = () => { onChange([...normalized, { name: '', amount: '', unit: '' }]); }; const removeIngredient = (i) => { onChange(normalized.filter((_, idx) => idx !== i)); }; return (