/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

/**
 * Checks if an element is scrollable.
 */
export function getAllScrollableParents( element, includeWindow = false ) {
	const scrollableParents = [];

	while ( element && element !== document.body ) {
		if ( isElementScrollable( element ) ) {
			scrollableParents.push( element );
		}

		element = element.parentNode;
	}

	if ( includeWindow ) {
		scrollableParents.push( window );
	}

	return scrollableParents;
}

/**
 * Checks if an element is scrollable.
 */
export function isElementScrollable( element ) {
	const overflowY = window.getComputedStyle( element ).overflowY;

	return overflowY === 'auto' || overflowY === 'scroll';
}
