import { useEffect } from "react";
import { useSelector } from "react-redux";

/**
 * This hook will only highlight specific set of features that are part
 * of the current feature infos. See iSB popup for exmaple of use.
 *
 * Works only with MapboxStyleLayer.
 */
const useHighlightSomeFeatures = (features, layer) => {
  const featureInfo = useSelector(state => state.app.featureInfo);
  // Highlight only one feature at a time.
  useEffect(() => {
    if (!layer || !(features !== null && features !== void 0 && features.length)) {
      return () => {};
    }
    featureInfo === null || featureInfo === void 0 || featureInfo.forEach(_ref => {
      let {
        layer: l
      } = _ref;
      if (l !== layer) {
        var _l$highlight;
        l === null || l === void 0 || (_l$highlight = l.highlight) === null || _l$highlight === void 0 || _l$highlight.call(l);
      }
    });
    layer === null || layer === void 0 || layer.highlight(features);
    return () => {
      layer === null || layer === void 0 || layer.highlight();
    };
  }, [layer, features, featureInfo]);
};
export default useHighlightSomeFeatures;
//# sourceMappingURL=useHighlightSomeFeatures.js.map