import React, {useState} from "react"; import {Input, Select, TableBody, TableCell, TableHeader, TableHeaderCell, TableRow} from "semantic-ui-react"; import {Button, Header, Icon, Modal, Table} from "../Theme"; import {ALL_UNITS} from "./units"; const UNIT_OPTIONS = [{key: '', value: '', text: '—'}, ...ALL_UNITS.map(u => ({key: u, value: u, text: u}))]; const COLUMNS = [ {key: 'name', label: 'Name', width: 4}, {key: 'category', label: 'Category', width: 3}, {key: 'subcategory', label: 'Subcategory', width: 3}, {key: 'item_size', label: 'Size', width: 2}, {key: 'item_size_unit', label: 'Unit', width: 2}, {key: 'calories', label: 'kcal', width: 2}, ]; function blankEntry() { return {name: '', category: '', subcategory: '', item_size: '', item_size_unit: '', calories: ''}; } /** * Manage the shared food catalog: a scrollable, editable table (add/edit/delete) saved as a whole list. Each * entry's `calories` is the total for one `item_size` package — the value pre-filled onto inventory items. */ export function CatalogEditor({catalog, open, onClose, onSave}) { const [draft, setDraft] = useState([]); React.useEffect(() => { if (open) { setDraft((catalog || []).map(e => ({...e}))); } }, [open, catalog]); const update = (index, key, value) => setDraft(prev => prev.map((e, i) => i === index ? {...e, [key]: value} : e)); const remove = (index) => setDraft(prev => prev.filter((_, i) => i !== index)); const add = () => setDraft(prev => [blankEntry(), ...prev]); const save = async () => { // Drop fully-empty rows. const cleaned = draft.filter(e => (e.name || '').trim()); await onSave(cleaned); onClose(); }; return Food Catalog

Known items used to autocomplete and pre-fill the entry form. kcal is the total calories for one package of the given size.

{COLUMNS.map(c => {c.label})} {draft.map((entry, index) => { const aria = (col) => `${entry.name || 'new item'} ${col}`; return update(index, 'name', e.target.value)}/> update(index, 'category', e.target.value)}/> update(index, 'subcategory', e.target.value)}/> update(index, 'item_size', e.target.value)}/> update(index, 'calories', e.target.value)}/> ; })}
; }