import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2022-2025 GoodData Corporation
import { useEffect, useRef } from "react";
import { useScrollContext } from "./ScrollContext.js";
/**
 * @internal
 */
export function ScrollableItem({ scrollIntoView, bottomMargin, isElementInvisibleCheck, className, children, onItemScrolled, tagName: TagName = "div", }) {
    const item = useRef(null);
    const scroll = useScrollContext();
    useEffect(() => {
        if (scrollIntoView) {
            const element = item.current;
            if (element) {
                scroll.scrollIntoView(element, bottomMargin, isElementInvisibleCheck);
            }
            if (onItemScrolled) {
                onItemScrolled();
            }
        }
    }, [bottomMargin, isElementInvisibleCheck, scroll, scrollIntoView, item, onItemScrolled]);
    return (_jsx(TagName, { className: className, ref: item, children: children }));
}
