import d from "./index-getWindow.js";
import f from "./index-getNodeName.js";
import n from "./index-getComputedStyle.js";
import { isHTMLElement as a, isShadowRoot as m } from "./index-instanceOf.js";
import g from "./index-isTableElement.js";
import s from "./index-getParentNode.js";
import p from "./index-userAgent.js";
function l(r) {
  return !a(r) || // https://github.com/popperjs/popper-core/issues/837
  n(r).position === "fixed" ? null : r.offsetParent;
}
function v(r) {
  var e = /firefox/i.test(p()), t = /Trident/i.test(p());
  if (t && a(r)) {
    var u = n(r);
    if (u.position === "fixed")
      return null;
  }
  var i = s(r);
  for (m(i) && (i = i.host); a(i) && ["html", "body"].indexOf(f(i)) < 0; ) {
    var o = n(i);
    if (o.transform !== "none" || o.perspective !== "none" || o.contain === "paint" || ["transform", "perspective"].indexOf(o.willChange) !== -1 || e && o.willChange === "filter" || e && o.filter && o.filter !== "none")
      return i;
    i = i.parentNode;
  }
  return null;
}
function O(r) {
  for (var e = d(r), t = l(r); t && g(t) && n(t).position === "static"; )
    t = l(t);
  return t && (f(t) === "html" || f(t) === "body" && n(t).position === "static") ? e : t || v(r) || e;
}
export {
  O as default
};
