"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get getAllScrollableParents () {
        return getAllScrollableParents;
    },
    get getScrollParent () {
        return getScrollParent;
    }
});
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] !== void 0 ? arguments[1] : defaultRoot;
    var node = el;
    while(node && node !== root && isElement(node)){
        if (node === document.body) {
            return root;
        }
        var overflowY = window.getComputedStyle(node).overflowY;
        if (overflowStylePatterns.includes(overflowY) && node.scrollHeight > node.clientHeight) {
            return node;
        }
        node = node.parentNode;
    }
    return root;
}
function getAllScrollableParents(element) {
    var scrollableParents = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
    if (!element) {
        return scrollableParents;
    }
    // 检查元素是否具有滚动条
    var isScrollable = element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
    if (isScrollable) {
        // 如果当前元素具有滚动条，则将其添加到数组中
        if (element.nodeName === 'HTML') {
            // @ts-ignore
            scrollableParents.push(document);
        } else {
            scrollableParents.push(element);
        }
    }
    // 递归检查父元素
    return getAllScrollableParents(element.parentElement, scrollableParents);
}
