import { useRef as a, useState as E, useEffect as I } from "react";
const L = ({
  ref: d,
  onFocusWithin: u = () => {
  },
  onBlurWithin: o = () => {
  },
  delay: c = 0
} = {}) => {
  const m = a(null), n = d ?? m, [r, i] = E(!1), t = a(null), s = () => {
    t.current !== null && (window.clearTimeout(t.current), t.current = null);
  };
  return I(() => {
    const e = n.current;
    if (!e)
      return;
    const f = () => {
      s(), r || (i(!0), u());
    }, l = (v) => {
      s(), t.current = setTimeout(() => {
        e.contains(v.relatedTarget) || (i(!1), o()), t.current = null;
      }, c);
    };
    return e.addEventListener("focusin", f), e.addEventListener("focusout", l), () => {
      e.removeEventListener("focusin", f), e.removeEventListener("focusout", l), s();
    };
  }, [n, c, u, o, r]), {
    ref: n,
    isFocusedWithin: r
  };
};
export {
  L as default
};
//# sourceMappingURL=useIsFocusWithin.js.map
