import React, {useMemo, useState} from "react"; import { Button, Confirm, Header, IconButton, Loading, Modal, Panel, SearchBox, Select, TabBar, tabClassName, Text, TextInput, } from "../ui"; import {PageContainer, useTitle} from "../Common"; import {collectLocations, useCatalog, useInventories} from "../../hooks/customHooks"; import {filterItems, InventoryTable} from "./InventoryTable"; import {InventoryItemsMobile} from "./InventoryItemsMobile"; import {InventorySummary} from "./InventorySummary"; import {InventoryExportPanel} from "./InventoryExportPanel"; import {InventoryPrint} from "./InventoryPrint"; import {RationEstimatePanel} from "../calculators/RationCalculator"; import {defaultGroupKey, defaultSumKey, findCaloriesKey, findCountKey} from "./summarize"; import {FieldSchemaEditor} from "./FieldSchemaEditor"; import {CatalogEditor} from "./CatalogEditor"; import {InventoryImportModal} from "./InventoryImportModal"; import {Media} from "../../contexts/contexts"; const INVENTORY_TYPES = [ {value: 'food', label: 'Food Storage'}, {value: 'fuel', label: 'Fuel'}, {value: 'tool', label: 'Tools'}, ]; function NewInventoryModal({open, onClose, onCreate}) { const [name, setName] = useState(''); const [type, setType] = useState('food'); const create = async () => { const inventory = await onCreate(name, type); if (inventory) { setName(''); setType('food'); onClose(); } }; return New Inventory setName(e.currentTarget.value)} placeholder='Food Storage' mb='1em'/>
Type:{' '} setSlug(value)} style={{minWidth: '14em'}} /> setNewOpen(true)} label='New inventory'/> {current && <> { setRenameValue(current.name); setRenaming(true); }} label='Rename inventory'/> setConfirmDelete(true)} label='Delete inventory'/> }
{current ? <> {tabs.map(({key, label}) => )} {tab === 'items' && <> {/* The search filter lives here so it clearly applies to the Items tab only, not Summary/Ration/Export. */}
{/* Portrait mobile: condensed, read-only. Rotate to landscape (tablet+) for the full editor. */} {/* The table gets the FULL items (so edits/adds don't drop filtered-out rows) plus the search, which it applies to its displayed rows only. */} persistInventory(slug, {items: newItems})}/> } {tab === 'summary' && } {tab === 'ration' && caloriesKey && } {tab === 'export' && } {/* Always mounted (hidden on screen) so the browser print dialog has the full table + summary to render. */} setEditFieldsOpen(false)} onSave={newFields => persistInventory(slug, {fields: newFields})}/> setImportOpen(false)} slug={slug} name={current.name} onChanged={fetchInventories}/> : Create an inventory to get started.} setNewOpen(false)} onCreate={onCreate}/> setCatalogOpen(false)} onSave={persistCatalog}/> setRenaming(false)} closeIcon size='tiny'> Rename Inventory setRenameValue(e.currentTarget.value)}/> setConfirmDelete(false)} onConfirm={doDelete} > {`Delete "${current?.name}" and all its items? This cannot be undone.`} ; }