"use client"; import Image from "next/image"; import { type CSSProperties, type ReactNode, useState, useEffect } from "react"; import { apiGetCurrentUser } from "@/service/auth"; import ChatbotWidget from "@/uhm/components/ui/ChatbotWidget"; import Map, { type MapFeaturePayload } from "@/uhm/components/Map"; import ReplayPreviewLayerPanel from "@/uhm/components/editor/ReplayPreviewLayerPanel"; import PublicWikiSidebar from "@/uhm/components/wiki/PublicWikiSidebar"; import TimelineBar from "@/uhm/components/ui/TimelineBar"; import type { MapHoverPopupContent } from "@/uhm/components/map/useMapHoverPopup"; import type { Entity } from "@/uhm/api/entities"; import type { Wiki } from "@/uhm/api/wikis"; import type { BackgroundLayerId, BackgroundLayerVisibility } from "@/uhm/lib/map/styles/backgroundLayers"; import type { FeatureCollection } from "@/uhm/types/geo"; import type { Feature } from "@/uhm/lib/editor/state/useEditorState"; type Props = { renderDraft: FeatureCollection; labelContextDraft: FeatureCollection; labelTimelineYear?: number | null; selectedFeatureIds: (string | number)[]; onSelectFeatureIds: (ids: (string | number)[]) => void; backgroundVisibility: BackgroundLayerVisibility; geometryVisibility: Record; onToggleBackground: (id: BackgroundLayerId) => void; onToggleGeometry: (typeKey: string) => void; timelineYear: number; onTimelineYearChange: (year: number) => void; timelineTimeRange?: number; onTimelineTimeRangeChange?: (range: number) => void; timelineFilterEnabled?: boolean; onTimelineFilterEnabledChange?: (enabled: boolean) => void; isTimelineLoading: boolean; timelineDisabled?: boolean; timelineStatusText?: string | null; timelineStyle?: CSSProperties; onFeatureClick?: (payload: MapFeaturePayload | null) => void; hoverPopupEnabled?: boolean; getHoverPopupContent?: (feature: Feature) => MapHoverPopupContent | null; onHoverFeatureChange?: (feature: Feature | null) => void; activeEntity?: Entity | null; activeWiki?: Wiki | null; isWikiLoading?: boolean; wikiError?: string | null; onCloseWikiSidebar?: () => void; onWikiLinkRequest?: (request: { slug: string; rect: DOMRect }) => void; onWikiLinkEntitySelectionRequest?: (request: { slug: string; rect: DOMRect }) => void; onWikiLinkInteraction?: () => void; sidebarWidth?: number; onSidebarWidthChange?: (width: number) => void; maxSidebarDragWidth?: number; onPlayPreviewReplay?: () => void; mapHandleRef?: React.RefObject; overlay?: ReactNode; children?: ReactNode; onLoad?: () => void; instantLoad?: boolean; onToggleInstantLoad?: (val: boolean) => void; isLayerPanelVisible?: boolean; onLayerPanelVisibleChange?: (visible: boolean) => void; sidebarHeight?: number; onSidebarHeightChange?: (height: number) => void; showViewportControls?: boolean; hasAnyBottomPanel?: boolean; }; export default function PreviewMapShell({ renderDraft, labelContextDraft, labelTimelineYear, selectedFeatureIds, onSelectFeatureIds, backgroundVisibility, geometryVisibility, onToggleBackground, onToggleGeometry, timelineYear, onTimelineYearChange, timelineTimeRange, onTimelineTimeRangeChange, timelineFilterEnabled, onTimelineFilterEnabledChange, isTimelineLoading, timelineDisabled = false, timelineStatusText = null, timelineStyle, onFeatureClick, hoverPopupEnabled = false, getHoverPopupContent, onHoverFeatureChange, activeEntity = null, activeWiki = null, isWikiLoading = false, wikiError = null, onCloseWikiSidebar, onWikiLinkRequest, onWikiLinkEntitySelectionRequest, onWikiLinkInteraction, sidebarWidth, onSidebarWidthChange, maxSidebarDragWidth, onPlayPreviewReplay, mapHandleRef, overlay, children, onLoad, instantLoad = true, onToggleInstantLoad, isLayerPanelVisible: propsLayerPanelVisible, onLayerPanelVisibleChange, sidebarHeight, onSidebarHeightChange, showViewportControls = true, hasAnyBottomPanel = false, }: Props) { const [isMenuOpen, setIsMenuOpen] = useState(false); const [avatarUrl, setAvatarUrl] = useState(null); const [localLayerPanelVisible, setLocalLayerPanelVisible] = useState(true); const isLayerPanelVisible = propsLayerPanelVisible ?? localLayerPanelVisible; const setIsLayerPanelVisible = onLayerPanelVisibleChange ?? setLocalLayerPanelVisible; const [isMobileOrTablet, setIsMobileOrTablet] = useState(false); useEffect(() => { const checkDevice = () => setIsMobileOrTablet(window.innerWidth < 1024); checkDevice(); window.addEventListener("resize", checkDevice); return () => window.removeEventListener("resize", checkDevice); }, []); useEffect(() => { const fetchUserAvatar = async () => { try { const userData = await apiGetCurrentUser({ skipRefresh: true }); const nextAvatarUrl = getCurrentUserAvatarUrl(userData); if (nextAvatarUrl) setAvatarUrl(nextAvatarUrl); } catch { // Guest preview does not need an authenticated profile. } }; fetchUserAvatar(); }, []); const hasWikiSidebar = Boolean(activeEntity || activeWiki || isWikiLoading || wikiError); const hasBottomPanel = hasWikiSidebar || hasAnyBottomPanel; const menuOptionStyle: CSSProperties = { width: 46, height: 46, backgroundColor: "#1e293b", color: "#cbd5e1", border: "1px solid rgba(255, 255, 255, 0.08)", borderRadius: 12, display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer", transition: "all 0.2s ease", boxShadow: "0 2px 8px rgba(0, 0, 0, 0.12)", backdropFilter: "blur(6px)", }; return (