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 useLegendInteractionVisibility = (props, layerId) => {
  const { visible } = useMapSelectionState();
  const { current: map } = useMap();
  if (isLegendColoring(props) && !isUndefined(map)) {
    if (!isUndefined(visible)) {
      const mapInstance = map.getMap();
      const visibleCategoriesNames = visible.map(({ name }) => name);
      mapInstance.setFilter(layerId, [
        "in",
        props.valueAccessor,
        ...visibleCategoriesNames
      ]);
    } else {
      const layer = map.getLayer(layerId);
      if (!isUndefined(layer)) {
        const mapInstance = map.getMap();
        mapInstance.setFilter(layerId, null);
      }
    }
  }
};
export {
  useLegendInteractionVisibility
};
//# sourceMappingURL=use-legend-interaction-visibility.js.map
