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