"use client"; import { Fragment, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from "react"; import { createPortal } from "react-dom"; import { Maximize, Minimize, SlidersHorizontal, ZoomOut } from "lucide-react"; import type { DiveProfile, DiveProfileEvent, DiveProfileEventType, } from "@/lib/api/dives"; import { alignedDomain, axisTicks, labelCapacity, labelWidth, niceDomain, stepCount, type Domain, } from "@/lib/chart-scale"; import { buildAreaPath, segmentByTimeGap } from "@/lib/chart-path"; import { type ChannelSeries, type ProfileAxisKey, type ProfileChannel, type ProfileChannelKey, type ProfileSeriesKey, type ProfileViewKey, ELAPSED_TICK_TARGET, EVENTS_LABEL, PANEL_AXES, PROFILE_CHANNELS, PROFILE_CHANNEL_KEYS, PROFILE_VIEW_KEYS, axisDomain, axisUnitSuffix, channelAxis, channelWord, channelsOnAxis, cylinderName, type CylinderLabels, depthDomain, displayChannel, describeEvent, elapsedTicks, formatChannelValue, formatElapsed, formatElapsedSpoken, cutAtDiveEnd, type DiveAxis, drawnSampleIndexAt, gapThreshold, nearestEvent, placeOnDiveAxis, profileScalePlacement, readoutTolerance, temperatureDomain, toChannelSeries, toPressureSeries, tooltipSide, tooltipVerticalAnchor, TOOLTIP_GAP_PX, } from "@/lib/dive-profile"; import { DIVE_PROFILE_SERIES_KEY, parseSeriesVisibility, readStoredSeries, subscribeToNothing, toggleSeries, writeSeriesVisibility, } from "@/lib/chart-series-view"; import { cn } from "@/lib/utils"; import { CHART_HOVER_CARD } from "@/components/charts/chart-hover-card"; import { Button } from "@/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { IconTooltip } from "@/components/ui/tooltip"; import { DiveProfileFullscreen } from "@/components/dives/dive-profile-fullscreen"; import { type ChartReadout, useChartReadout } from "@/hooks/useChartReadout"; import { useChartWidth } from "@/hooks/useChartWidth"; import { useChartZoom } from "@/hooks/useChartZoom"; import { type ElementSize, useElementSize } from "@/hooks/useElementSize"; import { useFullscreen } from "@/hooks/useFullscreen"; import { useUnits } from "@/hooks/useUnits"; import type { UnitSystem } from "@/lib/units"; // Hand-rolled SVG rather than a charting library. The app ships a strict // nonce-based CSP (`src/proxy.ts`): inline style *attributes* are allowed, but a // library that injects a `