import { useRef, useState, useEffect, startTransition } from "react";
function useIsHovered(options = {}) {
  const { tolerance = 0, deepCheck = false } = options;
  const ref = useRef(null);
  const [isHovered, setIsHovered] = useState(false);
  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    const handleMouseMove = (event) => {
      const rect = element.getBoundingClientRect();
      const { clientX, clientY } = event;
      const withinBounds = clientX >= rect.left - tolerance && clientX <= rect.right + tolerance && clientY >= rect.top - tolerance && clientY <= rect.bottom + tolerance;
      if (!withinBounds) {
        startTransition(() => {
          setIsHovered(false);
        });
        return;
      }
      if (deepCheck) {
        const elementAtPoint = document.elementFromPoint(clientX, clientY);
        const isActuallyHovered = elementAtPoint === element || element.contains(elementAtPoint);
        startTransition(() => {
          setIsHovered(isActuallyHovered);
        });
      } else {
        startTransition(() => {
          setIsHovered(true);
        });
      }
    };
    const handleMouseLeave = () => {
      startTransition(() => {
        setIsHovered(false);
      });
    };
    const ctrl = new AbortController();
    document.addEventListener("mousemove", handleMouseMove, { signal: ctrl.signal });
    element.addEventListener("mouseleave", handleMouseLeave, { signal: ctrl.signal });
    return () => {
      ctrl.abort();
    };
  }, [tolerance, deepCheck]);
  return { ref, isHovered };
}
export {
  useIsHovered as default
};
//# sourceMappingURL=use-is-hovered.js.map
