import type { CollectionLabel, CollectionLink, CollectionPlace, CollectionStatus } from '@trek/shared'; import { Camera, Check, Copy, ExternalLink, Link2, Loader2, MapPin, Navigation, Pencil, Plus, Trash2, } from 'lucide-react'; import React, { useId, useRef, useState } from 'react'; import Markdown from 'react-markdown'; import { useNavigate } from 'react-router'; import remarkBreaks from 'remark-breaks'; import remarkGfm from 'remark-gfm'; import { useTranslation } from '../../i18n'; import { STATUS_META, STATUS_ORDER, normalizeLinkUrl } from '../../pages/collections/collectionsModel'; import type { Category, TranslationFn } from '../../types'; import { entityGradient } from '../../utils/gradients'; import { placesPath } from '../../utils/placesRoutes'; import MarkdownToolbar from '../Journey/MarkdownToolbar'; import { getNavigationTargets, navigationTargetLabel, openNavigationTarget } from '../Planner/placeNavigation'; import { getCategoryIcon } from '../shared/categoryIcons'; import { focusRevealedEditor } from '../shared/dialogFocus'; import { DialogShell } from '../shared/DialogShell'; import { markdownLinkComponents } from '../shared/markdownLink'; import { NavigationMenu } from '../shared/NavigationMenu'; import { NumericInput } from '../shared/NumericInput'; import PlaceRating from '../shared/StarRating'; import { Tooltip } from '../shared/Tooltip'; import CategoryTileMenu from './CategoryTileMenu'; import { CollectionLocationSearch } from './CollectionLocationSearch'; import { originPairs } from './libraryPairs'; import PlaceLocationBadge from './PlaceLocationBadge'; import PlaceOrigins from './PlaceOrigins'; import './placeSheet.css'; import PlaceSheetTabs from './PlaceSheetTabs'; import PlaceTagsCard from './PlaceTagsCard'; import { useCollectionPlaceForm } from './useCollectionPlaceForm'; import { useLibraryPlace } from './useLibraryPlace'; import { usePlaceSheet } from './usePlaceSheet'; import { usePlaceTags } from './usePlaceTags'; function linkHost(url: string): string { try { return new URL(url).hostname.replace(/^www\./, ''); } catch { return url; } } type PlacePatch = { name?: string; description?: string | null; notes?: string | null; links?: CollectionLink[]; category_id?: number | null; label_ids?: number[]; image_url?: string | null; lat?: number | null; lng?: number | null; address?: string | null; }; interface CollectionPlaceDetailProps { place: CollectionPlace; canEdit: boolean; canDelete: boolean; categories: Category[]; /** The active list's tags, which the edit form keeps as they are. */ labels: CollectionLabel[]; /** True while a dialog opened from here is open: Escape and the backdrop leave this one alone. */ blocked?: boolean; onClose: () => void; onSetStatus: (status: CollectionStatus) => void; onSave: (patch: PlacePatch) => Promise; /** Upload a custom cover image (#1136); enables the cover change/remove controls. */ onUploadImage?: (file: File) => Promise; onCopyToTrip: () => void; onRemove: () => void; /** Cast/clear the current user's star vote (#1435); every member may vote. */ onRate?: (rating: number | null) => Promise | void; t: TranslationFn; } function StatusSegment({ status, onSet, t, }: { status: CollectionStatus; onSet: (s: CollectionStatus) => void; t: TranslationFn; }): React.ReactElement { return (
{STATUS_ORDER.map((s) => { const Icon = STATUS_META[s].icon; const on = status === s; return ( ); })}
); } type Form = ReturnType; /** The cover: the picture or a gradient, the category, the picture controls and the name. */ function Cover({ place, form, canEdit, categories, labelId, onUploadImage, t, }: { place: CollectionPlace; form: Form; canEdit: boolean; categories: Category[]; labelId: string; onUploadImage?: (file: File) => Promise; t: TranslationFn; }) { const coverInputRef = useRef(null); const CatIcon = getCategoryIcon(place.category?.icon); const banner = form.cover; return (
{banner && }
{place.category?.name && ( {place.category.name} )}
{canEdit && onUploadImage && ( <> {place.image_url && !form.imgBusy && ( )} )}
{form.editing ? ( // The category rides in front of the name instead of a chip row in the form.
{categories.length > 0 && ( )} form.setName(e.target.value)} className="col-detail-name-input min-w-0 flex-1" ref={focusRevealedEditor} aria-label={t('common.name')} />
) : ( <>

{place.name}

)}
); } /** The edit form beside the cover: position, address, description and links. */ function EditForm({ form, t }: { form: Form; t: TranslationFn }) { const descRef = useRef(null); const coordPaste = (e: React.ClipboardEvent) => { const text = e.clipboardData.getData('text').trim(); const match = text.match(/^(-?\d+(?:\.\d*)?)(?:\s*[,;]\s*|\s+)(-?\d+(?:\.\d*)?)$/); if (match) { e.preventDefault(); form.setLat(match[1]); form.setLng(match[2]); } }; return (
{/* A place that has no position yet can be looked up here (#2837). */} {form.needsPosition && }
{t('places.formAddress')}
form.setAddress(e.target.value)} placeholder={t('places.formAddressPlaceholder')} className="col-detail-input" />
{t('collections.coordinates')}
{t('collections.description')}