import { useId } from 'react' import { focusRevealedEditor } from '../shared/dialogFocus' import { Backpack, Package, Plus } from 'lucide-react' import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT } from '../shared/DialogShell' import { CardHead, INPUT, PANEL } from '../shared/dialogParts' import type { PackingState } from './usePackingListPanel' import { bagFillPct, bagLoadSummary, packedWeight, perPersonLoads } from './packingListPanel.helpers' import { BagCard } from './PackingListPanelBagCard' import { PackingWeightSummary } from './PackingWeightSummary' export function BagModal(S: PackingState) { const labelId = useId() const { setShowBagModal, t, bags, items, tripId, tripMembers, canEdit, currentUserId, handleDeleteBag, handleUpdateBag, handleSetBagMembers, showAddBag, setShowAddBag, newBagName, setNewBagName, handleCreateBag, unassignedWeightGrams, serverWeightsFresh, } = S // The ITEM LISTS still describe what you are carrying — an item someone shared // with you stays in your list, but they are the one bringing it (#1767). The // WEIGHTS no longer do. A bag's load is the bag's, whoever packed it and // whether or not you may see the items, so it comes from the server (#2191). const { myItems, bagItemsOf, bagWeightOf, heaviestBagWeight, unassigned, unassignedWeight, totalWeight } = bagLoadSummary(bags, items, currentUserId, unassignedWeightGrams, serverWeightsFresh) const close = () => setShowBagModal(false) const resetNewBag = () => { setShowAddBag(false); setNewBagName('') } return ( } tint={NEUTRAL_TINT} labelId={labelId} onClose={close} title={t('packing.bags')} /> )} footer={( {t('common.close')} {canEdit && ( showAddBag ? {t('packing.addBag')} : setShowAddBag(true)} icon={}>{t('packing.addBag')} )} )} > {bags.map(bag => { const bagItems = bagItemsOf(bag) const bagWeight = bagWeightOf(bag) const pct = bagFillPct(bagWeight, bag.weight_limit_grams, heaviestBagWeight) return ( handleDeleteBag(bag.id)} onUpdate={handleUpdateBag} onSetMembers={handleSetBagMembers} t={t} /> ) })} {(unassigned.length > 0 || unassignedWeight > 0) && (
} title={t('packing.noBag')} />
{unassigned.length} {t('admin.packingTemplates.items', { count: unassigned.length })} {unassignedWeight >= 1000 ? `${(unassignedWeight / 1000).toFixed(1)} kg` : `${unassignedWeight} g`}
)} {/* Total, packed share and who carries what (#1131) */}
{canEdit && showAddBag && (
} title={t('packing.addBag')} /> setNewBagName(e.target.value)} onKeyDown={e => { if (e.key === 'Enter' && newBagName.trim()) void handleCreateBag() if (e.key === 'Escape') { e.preventDefault(); resetNewBag() } }} placeholder={t('packing.bagName')} className={INPUT} />
)}
) }