import { useEffect, useRef } from 'react';
import { useLocation } from 'react-router-dom';
import { removeLeadingSlash } from '@redocly/theme/core/openapi';
import { getElementById } from '../Content/useAutoScroll.js';
function useScrollOnRender(item, routingBasePath) {
    const ref = useRef(null);
    const location = useLocation();
    const pathname = removeLeadingSlash(location.pathname.replace(routingBasePath, ''));
    useEffect(() => {
        if (ref.current && item.href && removeLeadingSlash(item.href) === pathname) {
            if (typeof ref?.current?.scrollIntoView === 'function') {
                ref.current.scrollIntoView();
            }
            if (location.hash) {
                const element = getElementById(location.hash.replace('#', '').toLowerCase());
                if (element) {
                    element.scrollIntoView();
                }
            }
        }
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    return ref;
}
export default useScrollOnRender;
//# sourceMappingURL=useScrollOnRender.js.map