import React from 'react'
import { List as ListIcon, Map as MapIcon, Search, Bookmark, CheckCheck, X, Trash2, Copy, CopyPlus, FolderInput, Plus, Tags, DownloadCloud } from 'lucide-react'
import Navbar from '../components/Layout/Navbar'
import ConfirmDialog from '../components/shared/ConfirmDialog'
import ListsRail from '../components/Collections/ListsRail'
import CollectionInviteCard from '../components/Collections/CollectionInviteCard'
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 ImportFromTripModal from '../components/Collections/ImportFromTripModal'
import ImportCollectionModal from '../components/Collections/ImportCollectionModal'
import CollectionPlaceDetail from '../components/Collections/CollectionPlaceDetail'
import LabelManager from '../components/Collections/LabelManager'
import BulkAssignLabelModal from '../components/Collections/BulkAssignLabelModal'
import { ActiveCollectionTours } from '../components/Tours/collection/CollectionToursSection'
import { useCollections } from './collections/useCollections'
import EmptyState from '../components/shared/EmptyState'
import '../styles/dashboard.css'
import HelpAnchor from '../components/Help/HelpAnchor'
import '../styles/collections.css'
export default function CollectionsPage(): React.ReactElement {
// ViewportRoute in App.tsx picks the branch now, so the phone screen is a
// chunk of its own instead of a dead limb in this one.
return (
<>
>
)
}
function CollectionsPageDesktop(): 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
// Invites also sit at the top of the body: with no lists of one's own the
// body is all there is (and the rail is hidden below 1080px), and the invite
// notification links to a list that is still an invite (#2645).
const bodyInvites = noLists ? c.orderedInvites : (c.routeInvite ? [c.routeInvite] : [])
// Selecting a place from the list toggles it, so clicking the row again clears
// it, as does the map background. A marker click always shows the place: a second
// click on the marker of the place that is open read as "the details do not open"
// rather than as "close them" (#2431). 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 showPlace = (id: number) => c.setSelectedPlaceId(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) => { showPlace(id); if (c.view === 'map') c.setView('list') }
const desktopSplit = c.isWide && c.hasMappable
const mapShown = c.hasMappable && (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) => (
c.setShowLabelManager(true)}
places={mappable}
selectedPlaceId={c.selectedPlaceId}
onSelect={onMapSelect}
onDeselect={deselect}
dark={c.dark}
overlay={overlay}
view={c.view}
onToggleView={toggleView}
search={c.search}
onSearch={c.setSearch}
t={t}
/>
)
// 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.setShowAddPlace(true)}
showLabels={isRealList && !mapShown}
labelOptions={c.labelOptions}
labelFilter={c.labelFilter}
onLabelFilter={c.setLabelFilter}
canManageLabels={canManageLabels}
onManageLabels={() => c.setShowLabelManager(true)}
canImport={canAddPlace}
onImport={() => c.setShowImport(true)}
showSelect={showSelect}
selectMode={c.selectMode}
onToggleSelect={() => c.setSelectMode(!c.selectMode)}
t={t}
/>
) : null
const listColumn = (
<>
{filterBar}
{c.visiblePlaces.length > 0
? listEl
: }
>
)
let body: React.ReactElement
if (c.placesLoading && !hasPlaces) {
body =
} else if (!hasPlaces) {
body = (
{canAddPlace && (
{/* An empty list is exactly where a trip import saves the most typing,
so it gets the same billing as adding one place by hand. */}
)}
)
} else if (desktopSplit) {
body = (
{listColumn}
{mapPanel(true)}
)
} else if (c.view === 'map' && c.hasMappable) {
body =
)}
{/* The whole tours the list keeps (LIB-03), above its places. */}
{isRealList && }
{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)}
onUploadImage={file => c.uploadPlaceImage(c.selectedPlace!.id, file)}
onCopyToTrip={c.openCopyForSelectedPlace}
onRemove={c.handleDetailRemove}
onRate={r => c.handleRatePlace(c.selectedPlace!.id, r)}
t={t}
/>
)}
{/* Add a place to the current list */}
{typeof c.activeId === 'number' && c.activeCollection && (
c.setShowAddPlace(false)}
onAdded={c.handlePlaceAdded}
t={t}
/>
)}
{/* A list file as a new list, or added to one that is already there (#2198, #2301) */}
{c.showImportFile && (
c.setShowImportFile(false)}
t={t}
/>
)}
{/* Bulk import of a trip's places into the current list */}
{typeof c.activeId === 'number' && c.activeCollection && (
c.setShowImport(false)}
onImported={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)}
onConfirm={c.handleDeleteList}
title={t('collections.deleteList')}
message={t('collections.deleteListConfirm')}
confirmLabel={t('common.delete')}
cancelLabel={t('common.cancel')}
/>
>
)
}