import { useRef as c, useEffect as a } from "react";
const p = (r) => {
  const t = c(null), s = (e) => {
    const n = (r ?? t.current)?.querySelectorAll(
      [
        "a[href]",
        "button",
        "textarea",
        "input",
        'input[type="text"]',
        'input[type="radio"]',
        'input[type="checkbox"]',
        "select"
      ].join(", ")
    ), o = n?.[0], u = n?.[n.length - 1];
    if (e.key === "Tab") {
      if (e.shiftKey) {
        document.activeElement === o && (u?.focus(), e.preventDefault());
        return;
      }
      document.activeElement === u && (o?.focus(), e.preventDefault());
    }
  };
  return a(() => {
    const e = r ?? t.current;
    return e && e.addEventListener("keydown", s), () => {
      e && e.removeEventListener("keydown", s);
    };
  }, [t.current, r]), t;
};
export {
  p as default
};
//# sourceMappingURL=useFocusTrap.js.map
