"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useAutoScroll=void 0;const react_router_dom_1=require("react-router-dom"),react_1=require("react"),theme_1=require("@redocly/theme"),utils_1=require("../../utils");let initialPageLoad=!0;function useAutoScroll(e){const t=(0,react_router_dom_1.useLocation)(),o=(0,theme_1.addTrailingSlash)(e)||"/";(0,react_1.useLayoutEffect)((()=>{if(t.pathname===o&&""===t.hash)window.scrollTo(0,0);else{const e=t.hash.replace("#","").toLowerCase()||(0,utils_1.normalizePath)(t.pathname).replace(o,""),a=document.getElementById(decodeURIComponent(e));a&&a.scrollIntoView()}}),[t,o]);const a=(0,theme_1.useActiveSectionId)(t,!1,!1);(0,react_1.useEffect)((()=>{if(a&&initialPageLoad)initialPageLoad=!1;else if(theme_1.IS_BROWSER&&!window.location.pathname.includes(a)&&!window.location.hash.includes(a)){const e=(0,utils_1.compose)(theme_1.addLeadingSlash,utils_1.encodeBackSlashes)(a);window.history.replaceState({},"",e)}}),[a])}exports.useAutoScroll=useAutoScroll;
//# sourceMappingURL=useAutoScroll.js.map