var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var use_legend_interaction_highlighting_exports = {};
__export(use_legend_interaction_highlighting_exports, {
  useLegendInteractionHighlighting: () => useLegendInteractionHighlighting
});
module.exports = __toCommonJS(use_legend_interaction_highlighting_exports);
var import_lodash_es = require("lodash");
var import_maplibre = require("react-map-gl/maplibre");
var import_selectors = require("../store/selectors.js");
var import_coloring = require("../types/coloring.js");
const useLegendInteractionHighlighting = (props, sourceId) => {
  const { highlightedSeries } = (0, import_selectors.useMapSelectionState)();
  const { current: map } = (0, import_maplibre.useMap)();
  if ((0, import_coloring.isLegendColoring)(props) && !(0, import_lodash_es.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 }
        )
      );
    }
  }
};
