/**
 * The `Scroller` class.
 *
 * @public
 */
export class Scroller {
    // #region Ctor
    /**
     * Constructs a new instance of the `Scroller` class.
     *
     * @public
     */
    constructor() {
    }
    // #endregion
    // #region Methods
    /**
     * Scrolls the given element to the top.
     *
     * @param element - The element to scroll.
     * @param options - Optional scroll options.
     * @public
     */
    scrollToTop(element, options) {
        element.scroll({
            top: 0,
            behavior: 'smooth',
            ...options
        });
    }
    /**
     * Scrolls the given element to the bottom.
     *
     * @param element - The element to scroll.
     * @param options - Optional scroll options.
     * @public
     */
    scrollToBottom(element, options) {
        element.scroll({
            top: element.scrollHeight,
            behavior: 'smooth',
            ...options
        });
    }
    /**
     * Scrolls the given element to the left.
     *
     * @param element - The element to scroll.
     * @param options - Optional scroll options.
     * @public
     */
    scrollToLeft(element, options) {
        element.scroll({
            left: 0,
            behavior: 'smooth',
            ...options
        });
    }
    /**
     * Scrolls the given element to the right.
     *
     * @param element - The element to scroll.
     * @param options - Optional scroll options.
     * @public
     */
    scrollToRight(element, options) {
        element.scroll({
            left: element.scrollWidth,
            behavior: 'smooth',
            ...options
        });
    }
    /**
     * Scrolls the given element into view.
     *
     * @param element - The element to scroll into view.
     * @param options - Optional scroll options.
     * @public
     */
    scrollToElement(element, options) {
        element.scrollIntoView({
            behavior: 'smooth',
            block: 'start',
            inline: 'nearest',
            ...options
        });
    }
    /**
     * Scrolls the given element into view within a specific container.
     *
     * @param container - The container element to scroll within.
     * @param element - The element to scroll into view.
     * @param options - Optional scroll options.
     * @public
     */
    scrollToElementInContainer(container, element, options) {
        const containerTop = container.getBoundingClientRect().top;
        const itemTop = element.getBoundingClientRect().top;
        const scrollPosition = container.scrollTop + (itemTop - containerTop);
        container.scroll({
            top: scrollPosition,
            behavior: 'smooth',
            ...options
        });
    }
    /**
     * Finds the nearest scrollable parent of the given element,
     * supporting Shadow DOM and slotting.
     *
     * @param element - The element to find the scroll parent for.
     * @returns The nearest scrollable parent element, or `null` if none found.
     * @public
     */
    tryFindScrollParent(element) {
        let current = element;
        while (current && current !== document) {
            if (current instanceof HTMLElement) {
                const style = window.getComputedStyle(current);
                const overflowY = style.overflowY;
                const isScrollable = (/(auto|scroll|overlay)/).test(overflowY);
                if (isScrollable && current.scrollHeight > current.clientHeight) {
                    return current;
                }
            }
            // If inside a shadow root, climb to the host
            if (current instanceof ShadowRoot) {
                current = current.host;
            }
            else if (current instanceof HTMLElement && current.assignedSlot) {
                current = current.assignedSlot;
            }
            else {
                current = current.parentNode;
            }
        }
        return document.scrollingElement;
    }
}
/**
 * @public
 */
export class ScrollerServiceLocator {
    // #region Fields
    static _current = null;
    // #endregion
    // #region Properties
    static get current() {
        if (!ScrollerServiceLocator.isSet()) {
            throw new Error('\'Scroller\' not set.');
        }
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        return ScrollerServiceLocator._current;
    }
    // #endregion
    // #region Methods
    static isSet() {
        return ScrollerServiceLocator._current !== null;
    }
    static set(current) {
        ScrollerServiceLocator._current = current;
    }
}
ScrollerServiceLocator.set(new Scroller());
//# sourceMappingURL=Scroller.js.map