import { isUndefined } from "lodash-es";
import { useMap } from "react-map-gl/maplibre";
import { useMapSelectionState } from "../store/selectors.js";
import { isLegendColoring } from "../types/coloring.js";
const useLegendInteractionHighlighting = (props, sourceId) => {
  const { highlightedSeries } = useMapSelectionState();
  const { current: map } = useMap();
  if (isLegendColoring(props) && !isUndefined(map)) {
    const hoveredByLegend = map.querySourceFeatures(sourceId, {
      filter: ["all"]
    });
    hoveredByLegend?.map(
      (ft) => map.setFeatureState(
        { source: sourceId, id: ft.id },
        { legendHover: true }
      )
    );
    if (highlightedSeries) {
      const highlightedSeriesNames = highlightedSeries.map((s) => s.name);
      const hoveredByLegend2 = map.querySourceFeatures(sourceId, {
        filter: ["!in", props.valueAccessor, ...highlightedSeriesNames]
      });
      hoveredByLegend2?.map(
        (ft) => map.setFeatureState(
          { source: sourceId, id: ft.id },
          { legendHover: false }
        )
      );
    }
  }
};
export {
  useLegendInteractionHighlighting
};
//# sourceMappingURL=use-legend-interaction-highlighting.js.map
