import { Plus } from 'lucide-react' import type { PackingState } from './usePackingListPanel' import { bagFillPct, countsTowardsMyLoad, itemWeight } from './packingListPanel.helpers' import { BagCard } from './PackingListPanelBagCard' export function BagSidebar(S: PackingState) { const { t, bags, items, tripId, tripMembers, canEdit, currentUserId, handleDeleteBag, handleUpdateBag, handleSetBagMembers, showAddBag, setShowAddBag, newBagName, setNewBagName, handleCreateBag, } = S // These numbers describe what you are carrying. An item someone shared with you stays // in your list, but they are the one bringing it, so it is not your weight (#1767). const myItems = items.filter(i => countsTowardsMyLoad(i, currentUserId)) // Reference for bags without a limit of their own — computed once instead of per bag. const heaviestBagWeight = Math.max(...bags.map(b => myItems.filter(i => i.bag_id === b.id).reduce((s, i) => s + itemWeight(i), 0)), 1) return (
{t('packing.bags')}
{bags.map(bag => { const bagItems = myItems.filter(i => i.bag_id === bag.id) const totalWeight = bagItems.reduce((sum, i) => sum + itemWeight(i), 0) const pct = bagFillPct(totalWeight, bag.weight_limit_grams, heaviestBagWeight) return ( handleDeleteBag(bag.id)} onUpdate={handleUpdateBag} onSetMembers={handleSetBagMembers} t={t} compact /> ) })} {/* Unassigned */} {(() => { const unassigned = myItems.filter(i => !i.bag_id) const unassignedWeight = unassigned.reduce((s, i) => s + itemWeight(i), 0) if (unassigned.length === 0) return null return (
{t('packing.noBag')} {unassignedWeight >= 1000 ? `${(unassignedWeight / 1000).toFixed(1)} kg` : `${unassignedWeight} g`}
{unassigned.length} {t('admin.packingTemplates.items')}
) })()} {/* Total */}
{t('packing.totalWeight')} {(() => { const w = myItems.reduce((s, i) => s + itemWeight(i), 0); return w >= 1000 ? `${(w / 1000).toFixed(1)} kg` : `${w} g` })()}
{/* Add bag */} {canEdit && (showAddBag ? (
setNewBagName(e.target.value)} onKeyDown={e => { if (e.key === 'Enter') handleCreateBag(); if (e.key === 'Escape') { setShowAddBag(false); setNewBagName('') } }} placeholder={t('packing.bagName')} style={{ flex: 1, padding: '5px 8px', borderRadius: 8, border: '1px solid var(--border-primary)', fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontFamily: 'inherit', outline: 'none' }} />
) : ( ))}
) }