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 ConnectionLayerTooltip = (props) => {
  const { layerId, tooltipTemplate } = props;
  const {
    selectedItem: selectedItemId,
    actionsMenuRef,
    updateSelectedItem,
    onLeave
  } = useChartActionsMenu();
  const { hoveredLayerId, data, position, visible, enabled } = useMapTooltipState();
  const pinned = useMapTooltipPinnedState();
  const connectionData = useRef();
  const forceHideTooltip = !pinned && (hoveredLayerId !== layerId || !visible || !enabled);
  if (!tooltipTemplate || forceHideTooltip || !position) {
    return null;
  }
  if (!pinned && data?.[0]) {
    const { __lineColor: color, __lineWidth: thickness, ...rest } = data[0];
    connectionData.current = { color, thickness, data: rest };
  }
  return /* @__PURE__ */ React.createElement(
    ChartTooltip,
    {
      position,
      pinned,
      onMouseLeave: onLeave,
      actionSelectionValue: {
        selectedItemId,
        actionsMenuRef,
        updateSelectedItem
      }
    },
    connectionData.current ? tooltipTemplate(connectionData.current) : null
  );
};
ConnectionLayerTooltip["displayName"] = "ConnectionLayerTooltip";
export {
  ConnectionLayerTooltip
};
//# sourceMappingURL=ConnectionLayerTooltip.js.map
