import { X, Plus } from 'lucide-react' import type { PackingState } from './usePackingListPanel' import { itemWeight } from './packingListPanel.helpers' import { BagCard } from './PackingListPanelBagCard' export function BagModal(S: PackingState) { const { setShowBagModal, t, bags, items, tripId, tripMembers, canEdit, handleDeleteBag, handleUpdateBag, handleSetBagMembers, showAddBag, setShowAddBag, newBagName, setNewBagName, handleCreateBag, } = S return (
setShowBagModal(false)}>
e.stopPropagation()}>

{t('packing.bags')}

{bags.map(bag => { const bagItems = items.filter(i => i.bag_id === bag.id) const totalWeight = bagItems.reduce((sum, i) => sum + itemWeight(i), 0) const maxWeight = Math.max(...bags.map(b => items.filter(i => i.bag_id === b.id).reduce((s, i) => s + itemWeight(i), 0)), 1) const pct = Math.min(100, Math.round((totalWeight / maxWeight) * 100)) return ( handleDeleteBag(bag.id)} onUpdate={handleUpdateBag} onSetMembers={handleSetBagMembers} t={t} /> ) })} {/* Unassigned */} {(() => { const unassigned = items.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 = items.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: '8px 12px', borderRadius: 10, border: '1px solid var(--border-primary)', fontSize: 13, fontFamily: 'inherit', outline: 'none' }} />
) : ( ))}
) }