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_overlay_events_exports = {};
__export(use_overlay_events_exports, {
  useOverlayEvents: () => useOverlayEvents
});
module.exports = __toCommonJS(use_overlay_events_exports);
var import_parse_tooltip_data = require("../functions/parse-tooltip-data.js");
var import_store = require("../store/store.js");
const useOverlayEvents = () => {
  const setOverlayState = (0, import_store.useSetStateOverlay)();
  const setTooltipState = (0, import_store.useSetStateTooltip)();
  const toggleTooltipPinnedState = (0, import_store.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 = (0, import_parse_tooltip_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
  };
};
