import { Button, Container, Stack, Typography } from '@mui/material'; import { useParams, useNavigate, Link as RouterLink } from 'react-router-dom'; import { useMemo } from 'react'; import { useAreas, usePickItems, usePickList, useProducts } from '../hooks/dataHooks'; import { useDatabase } from '../context/DBProvider'; import { PickItemRow } from '../components/PickItemRow'; export const ActivePickListScreen = () => { const { id } = useParams(); const pickList = usePickList(id); const items = usePickItems(id); const products = useProducts(); const areas = useAreas(); const db = useDatabase(); const navigate = useNavigate(); const areaName = useMemo( () => areas.find((area) => area.id === pickList?.area_id)?.name ?? 'Area', [areas, pickList?.area_id], ); const handleIncrementQuantity = async (itemId: string) => { const existing = await db.pickItems.get(itemId); if (!existing) return; await db.pickItems.update(itemId, { quantity: existing.quantity + 1, updated_at: Date.now(), }); }; const handleToggleCarton = async (itemId: string) => { const existing = await db.pickItems.get(itemId); if (!existing) return; await db.pickItems.update(itemId, { quantity_bulk: existing.quantity_bulk > 0 ? 0 : 1, updated_at: Date.now(), }); }; const handleSwipeLeft = async (itemId: string) => { await db.pickItems.update(itemId, { status: 'picked', updated_at: Date.now() }); }; const handleDeleteItem = async (itemId: string) => { await db.pickItems.delete(itemId); }; const returnToLists = () => { navigate('/pick-lists'); }; return ( {areaName} List {pickList?.notes ? ( {pickList.notes} ) : null} {items.map((item) => ( p.id === item.product_id)} onIncrementQuantity={() => handleIncrementQuantity(item.id)} onToggleCarton={() => handleToggleCarton(item.id)} onSwipeLeft={() => handleSwipeLeft(item.id)} onSwipeRight={() => handleSwipeRight(item.id)} /> ))} ); };