import { useCallback, useEffect } from "react";
import {
  useMapTooltipPinnedState,
  useSetStateTooltip
} from "../store/store.js";
const useTooltipEventListeners = () => {
  const setTooltipState = useSetStateTooltip();
  const pinned = useMapTooltipPinnedState();
  const unpinTooltip = useCallback(() => {
    if (pinned) {
      setTooltipState({ pinned: false });
    }
  }, [pinned]);
  const onEscapeKeyPressedHandler = useCallback(
    (event) => {
      if (event.key === "Escape") {
        unpinTooltip();
      }
    },
    [unpinTooltip]
  );
  const onClick = useCallback(
    (event) => {
      unpinTooltip();
    },
    [unpinTooltip]
  );
  useEffect(() => {
    window.addEventListener("click", onClick);
    window.addEventListener("keyup", onEscapeKeyPressedHandler);
    return () => {
      window.removeEventListener("click", onClick);
      window.removeEventListener("keyup", onEscapeKeyPressedHandler);
    };
  }, [onClick, onEscapeKeyPressedHandler]);
};
export {
  useTooltipEventListeners
};
//# sourceMappingURL=use-tooltip-event-listeners.js.map
