import getParentNode from './getParentNode.mjs';
import isScrollParent from './isScrollParent.mjs';
import getNodeName from './getNodeName.mjs';
import { isHTMLElement } from './instanceOf.mjs';

function getScrollParent(node) {
  if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
    // $FlowFixMe[incompatible-return]: assume body is always available
    return node.ownerDocument.body;
  }

  if (isHTMLElement(node) && isScrollParent(node)) {
    return node;
  }

  return getScrollParent(getParentNode(node));
}

export { getScrollParent as default };
//# sourceMappingURL=getScrollParent.mjs.map
