import React, { useRef } from "react";
import {
  _ChartTooltip as ChartTooltip,
  _useChartActionsMenu as useChartActionsMenu
} from "@dynatrace/strato-components-preview/charts";
import {
  useMapTooltipPinnedState,
  useMapTooltipState
} from "../../store/selectors.js";
const DotLayerTooltip = (props) => {
  const { tooltipTemplate, layerId } = props;
  const {
    selectedItem: selectedItemId,
    actionsMenuRef,
    updateSelectedItem,
    onLeave
  } = useChartActionsMenu();
  const { hoveredLayerId, data, position, visible, enabled } = useMapTooltipState();
  const pinned = useMapTooltipPinnedState();
  const dotData = useRef();
  const forceHideTooltip = !pinned && (hoveredLayerId !== layerId || !visible || !enabled);
  if (!tooltipTemplate || forceHideTooltip || !position) {
    return null;
  }
  if (!pinned && data?.[0]) {
    const { __color: color, __bearing: bearing, data: customData } = data[0];
    dotData.current = {
      color,
      bearing,
      data: customData
    };
  }
  return /* @__PURE__ */ React.createElement(
    ChartTooltip,
    {
      position,
      pinned,
      onMouseLeave: onLeave,
      actionSelectionValue: {
        selectedItemId,
        actionsMenuRef,
        updateSelectedItem
      }
    },
    dotData.current ? tooltipTemplate(dotData.current) : null
  );
};
DotLayerTooltip["displayName"] = "DotLayerTooltip";
export {
  DotLayerTooltip
};
//# sourceMappingURL=DotLayerTooltip.js.map
