import { tabbable as r } from "../../../../../../../tabbable@6.4.0/node_modules/tabbable/dist/index.esm.js";
import { contains as d, getDocument as b, activeElement as f } from "./element.js";
const s = () => ({
  getShadowRoot: !0,
  displayCheck: (
    // JSDOM does not support the `tabbable` library. To solve this we can
    // check if `ResizeObserver` is a real function (not polyfilled), which
    // determines if the current environment is JSDOM-like.
    typeof ResizeObserver == "function" && ResizeObserver.toString().includes("[native code]") ? "full" : "none"
  )
});
function u(t, a) {
  const e = r(t, s()), n = e.length;
  if (n === 0)
    return;
  const i = f(b(t)), o = e.indexOf(i), c = o === -1 ? a === 1 ? 0 : n - 1 : o + a;
  return e[c];
}
function T(t) {
  return u(b(t).body, 1) || t;
}
function m(t) {
  return u(b(t).body, -1) || t;
}
function l(t, a) {
  if (!t)
    return null;
  const e = r(b(t).body, s()), n = e.length;
  if (n === 0)
    return null;
  const i = e.indexOf(t);
  if (i === -1)
    return null;
  const o = (i + a + n) % n;
  return e[o];
}
function v(t) {
  return l(t, 1);
}
function h(t) {
  return l(t, -1);
}
function p(t, a) {
  const e = a || t.currentTarget, n = t.relatedTarget;
  return !n || !d(e, n);
}
function y(t) {
  r(t, s()).forEach((e) => {
    e.dataset.tabindex = e.getAttribute("tabindex") || "", e.setAttribute("tabindex", "-1");
  });
}
function A(t) {
  t.querySelectorAll("[data-tabindex]").forEach((e) => {
    const n = e.dataset.tabindex;
    delete e.dataset.tabindex, n ? e.setAttribute("tabindex", n) : e.removeAttribute("tabindex");
  });
}
export {
  y as disableFocusInside,
  A as enableFocusInside,
  T as getNextTabbable,
  m as getPreviousTabbable,
  v as getTabbableAfterElement,
  h as getTabbableBeforeElement,
  s as getTabbableOptions,
  p as isOutsideEvent
};
