import React from 'react' import { List as ListIcon, Map as MapIcon, Search, Bookmark, CheckCheck, X, Trash2, Copy, CopyPlus, FolderInput, Plus, Tags } from 'lucide-react' import Navbar from '../components/Layout/Navbar' import Modal from '../components/shared/Modal' import ListsRail from '../components/Collections/ListsRail' import ListEditorModal from '../components/Collections/ListEditorModal' import CollectionHero from '../components/Collections/CollectionHero' import CollectionList from '../components/Collections/CollectionList' import CollectionFilterBar from '../components/Collections/CollectionFilterBar' import CollectionMapPanel from '../components/Collections/CollectionMapPanel' import CopyToTripModal from '../components/Collections/CopyToTripModal' import MoveToListModal from '../components/Collections/MoveToListModal' import ShareCollectionModal from '../components/Collections/ShareCollectionModal' import AddPlaceToCollectionModal from '../components/Collections/AddPlaceToCollectionModal' import CollectionPlaceDetail from '../components/Collections/CollectionPlaceDetail' import LabelManager from '../components/Collections/LabelManager' import BulkAssignLabelModal from '../components/Collections/BulkAssignLabelModal' import { useCollections } from './collections/useCollections' import '../styles/dashboard.css' import '../styles/collections.css' function EmptyState({ icon, title, text, action }: { icon: React.ReactNode; title: string; text: string; action?: React.ReactNode }): React.ReactElement { return (
{icon}

{title}

{text}

{action &&
{action}
}
) } export default function CollectionsPage(): React.ReactElement { const c = useCollections() const { t } = c const title = c.isAllSaved ? t('collections.allSaved') : (c.activeCollection?.name ?? t('collections.title')) const isShared = c.activeCollection?.is_owner === false const eyebrow = c.isAllSaved ? t('collections.hero.all') : (isShared ? t('collections.hero.shared') : t('collections.hero.mine')) const heroColor = c.activeCollection?.color || '#6366f1' const heroCover = c.activeCollection?.cover_image ?? null const hasPlaces = c.places.length > 0 const noLists = !c.loading && c.collections.length === 0 const showSelect = c.isAllSaved || c.activeCollection != null // Labels are per-collection, so only on a real (non "All saved") list. const isRealList = !c.isAllSaved && typeof c.activeId === 'number' const canManageLabels = isRealList && c.canEdit // Selecting a place toggles it, so clicking it again — or the map background — // clears it. Below the desktop breakpoint the list and map are separate views; // above it the list view is a split with a persistent map that pans to the // selection (the map stays mounted across the list↔map toggle so it animates). const mappable = c.mappable const openPlace = (id: number) => c.setSelectedPlaceId(c.selectedPlaceId === id ? null : id) const deselect = () => c.setSelectedPlaceId(null) const toggleView = () => { // Going to the full-map view closes the (list-docked) detail sheet. if (c.view !== 'map') c.setSelectedPlaceId(null) c.setView(c.view === 'map' ? 'list' : 'map') } // Clicking a marker in the full-map view drops back to the split so the list // + detail come into view alongside the map. const onMapSelect = (id: number) => { openPlace(id); if (c.view === 'map') c.setView('list') } const desktopSplit = c.isWide && mappable.length > 0 const mapShown = mappable.length > 0 && (c.view === 'map' || c.isWide) const mapOverlay = c.isWide && mapShown // the map carries the toggle + search const canAddPlace = typeof c.activeId === 'number' && c.canEdit // a real list you can edit const listEl = ( ) const mapPanel = (overlay: boolean) => ( ) // Filter row + the list (or a "no match" note when a filter hides everything). // Kept together so the filters stay reachable even when nothing matches. const filterBar = hasPlaces ? ( c.setShowLabelManager(true)} showSelect={showSelect} selectMode={c.selectMode} onToggleSelect={() => c.setSelectMode(!c.selectMode)} t={t} /> ) : null const listColumn = ( <> {filterBar} {c.visiblePlaces.length > 0 ? listEl : } title={t('collections.empty.noMatchTitle')} text={t('collections.empty.noMatchText')} />} ) let body: React.ReactElement if (c.placesLoading && !hasPlaces) { body =
} else if (!hasPlaces) { body = } title={t('collections.empty.title')} text={t('collections.empty.text')} /> } else if (desktopSplit) { body = (
{listColumn}
{mapPanel(true)}
) } else if (c.view === 'map' && mappable.length > 0) { body =
{mapPanel(false)}
} else { body = listColumn } const rail = ( { c.setMobileRailOpen(false); c.setEditorTarget('new') }} onAcceptInvite={c.handleAcceptInvite} onDeclineInvite={c.handleDeclineInvite} t={t} /> ) return ( <>
{noLists ? ( } title={t('collections.empty.firstTitle')} text={t('collections.empty.firstText')} action={ } /> ) : ( <>
{ if (c.activeCollection) c.setEditorTarget(c.activeCollection) }} shareMemberCount={c.shareMemberCount} onShare={() => c.setShowShare(true)} t={t} />
{(!mapOverlay || canAddPlace) && (
{!c.isWide && mappable.length > 0 && (
)} {canAddPlace && ( )}
{!mapOverlay && (
c.setSearch(e.target.value)} placeholder={t('collections.search')} />
)}
)} {c.selectMode && (
{t('collections.selectedCount', { count: c.selectedIds.length })}
{c.canEdit && isRealList && ( )} {c.canEdit && ( )} {c.canDelete && ( )}
)} {body} )}
{/* Mobile rail drawer */} {c.mobileRailOpen && ( <>
c.setMobileRailOpen(false)} />
{rail}
)} {/* Place detail — a bottom sheet (no backdrop, so the map behind stays visible + interactive). On the desktop split it docks over the list column so the map stays clear; otherwise it's a full-width sheet. Clicking another place / the map background re-points the selection. */} {c.selectedPlace && c.view !== 'map' && ( c.updatePlace(c.selectedPlace!.id, patch)} onCopyToTrip={c.openCopyForSelectedPlace} onRemove={c.handleDetailRemove} t={t} /> )}
{/* Add a place to the current list */} {typeof c.activeId === 'number' && c.activeCollection && ( c.setShowAddPlace(false)} onAdded={c.handlePlaceAdded} t={t} /> )} {/* Copy to trip */} {/* Move / duplicate the selection into another list */} {c.listPickerMode && ( l.id !== c.activeId)} count={c.selectedIds.length} onPick={c.listPickerMode === 'move' ? c.handleMoveToList : c.handleDuplicateToList} onClose={() => c.setListPickerMode(null)} t={t} /> )} {/* Share / fusion */} {c.canShare && typeof c.activeId === 'number' && c.activeCollection && ( c.setShowShare(false)} collectionId={c.activeId} collectionName={c.activeCollection.name} isOwner={c.isOwner} members={c.members} onAfterLeave={c.handleAfterLeave} t={t} /> )} {/* Create / edit a list — name, colour, cover, description, links */} c.setEditorTarget(null)} onCreated={c.handleEditorCreated} onRequestDelete={c.setConfirmDeleteList} t={t} /> {/* Manage the list's custom labels (editor+) */} {canManageLabels && ( c.setShowLabelManager(false)} t={t} /> )} {/* Bulk-assign labels to the current selection */} {canManageLabels && ( { c.setLabelPickerOpen(false); c.setShowLabelManager(true) }} onClose={() => c.setLabelPickerOpen(false)} t={t} /> )} {/* Delete-list confirm */} c.setConfirmDeleteList(null)} title={t('collections.deleteList')} size="sm" footer={
} >

{t('collections.deleteListConfirm')}

) }