/**
 * Walks up the DOM from `element` collecting every ancestor whose computed
 * overflow makes it a scroll container, and appends `window` at the end.
 *
 * Used to scope scroll listeners to elements that actually contain the
 * picker, so scrolling an unrelated part of the page doesn't trigger side
 * effects (e.g. closing the menu).
 */
export const getScrollableAncestors = (element) => {
    const ancestors = [];
    if (!element)
        return [window];
    let current = element.parentElement;
    while (current && current !== document.body) {
        const { overflow, overflowX, overflowY } = window.getComputedStyle(current);
        if (/(auto|scroll|overlay)/.test(`${overflow}${overflowX}${overflowY}`)) {
            ancestors.push(current);
        }
        current = current.parentElement;
    }
    ancestors.push(window);
    return ancestors;
};
