import { parseTooltipData } from "../functions/parse-tooltip-data.js";
import {
  useSetStateOverlay,
  useSetStateTooltip,
  useToggleStatePinnedTooltip
} from "../store/store.js";
const useOverlayEvents = () => {
  const setOverlayState = useSetStateOverlay();
  const setTooltipState = useSetStateTooltip();
  const toggleTooltipPinnedState = useToggleStatePinnedTooltip();
  const hideTooltip = () => {
    setTooltipState({ visible: false });
  };
  const handleMouseEnter = () => {
    setOverlayState({
      mouseInBounds: true
    });
  };
  const handleMouseMove = (event) => {
    if (event.features && event.features.length) {
      const { clientX, clientY } = event.originalEvent;
      const position = {
        x: clientX,
        y: clientY
      };
      const hoveredLayerId = event.features[0].layer.id;
      const hoveredFeatures = event.features.filter(
        (feature) => feature.layer.id === hoveredLayerId
      );
      const data = parseTooltipData(hoveredFeatures);
      setTooltipState({
        visible: true,
        hoveredLayerId,
        data,
        position
      });
    } else {
      hideTooltip();
    }
  };
  const handleMouseLeave = () => {
    setOverlayState({
      mouseInBounds: false
    });
    hideTooltip();
  };
  const handleMouseClick = (event) => {
    event.originalEvent.stopPropagation();
    toggleTooltipPinnedState();
  };
  const handleDrag = () => {
    hideTooltip();
  };
  const handleZoom = () => {
    hideTooltip();
  };
  return {
    handleMouseEnter,
    handleMouseMove,
    handleMouseLeave,
    handleMouseClick,
    handleZoom,
    handleDrag
  };
};
export {
  useOverlayEvents
};
//# sourceMappingURL=use-overlay-events.js.map
