"use strict";

require("core-js/modules/es.object.define-property.js");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getScrollParent = getScrollParent;
require("core-js/modules/es.array.includes.js");
var _canUseDom = require("./can-use-dom");
var defaultRoot = _canUseDom.canUseDom ? window : undefined;
var overflowStylePatterns = ['scroll', 'auto', 'overlay'];
function isElement(node) {
  var ELEMENT_NODE_TYPE = 1;
  return node.nodeType === ELEMENT_NODE_TYPE;
}
function getScrollParent(el) {
  var root = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultRoot;
  var node = el;
  while (node && node !== root && isElement(node)) {
    if (node === document.body) {
      return root;
    }
    var _window$getComputedSt = window.getComputedStyle(node),
      overflowY = _window$getComputedSt.overflowY;
    if (overflowStylePatterns.includes(overflowY) && node.scrollHeight > node.clientHeight) {
      return node;
    }
    node = node.parentNode;
  }
  return root;
}