import{useLocation as i,useNavigate as s}from"react-router-dom";import{useEffect as h,useRef as m}from"react";import{useActiveSectionId as u}from"@redocly/theme/core/hooks";import{isBrowser as f}from"../../../utils/env/is-browser";import{pathnameMatchesActiveSection as p}from"./utils/pathname-matches-active-section.js";let c=!0;function g(){const t=i(),o=s(),e=u(t,!1,!1),a=m(null);h(()=>{if(e&&c){c=!1,a.current=e;return}const n=a.current!==e,r=p(window.location.pathname,e);f()&&e&&!t.hash&&n&&!r&&o({pathname:t.pathname,search:t.search,hash:`#${e}`},{replace:!0}),a.current=e},[e,t.pathname,t.search,t.hash,o])}export{g as useAutoScroll};
