import{useLocation as p}from"react-router-dom";import{useEffect as s}from"react";import{addLeadingSlash as d,removeLeadingSlash as l,useActiveSectionId as u}from"@redocly/theme/core/openapi";import{compose as f,encodeBackSlashes as h,tryDecodeURIComponent as w}from"../../utils/index.js";import{IS_BROWSER as S}from"../../utils/dom.js";let m=!0;function v(t){const e=p(),o=t||"/";s(()=>{if(e.pathname===o&&e.hash===""){window.scrollTo(0,0);return}const a=l(e.pathname.replace(o,"")),r=g(e.hash),i=r?c(a+r)||document.querySelector(`[id$="${l(r)}"]`):c(e.hash.replace("#",""))||c(a);i&&i.scrollIntoView()},[e,o]);const n=u(e,!1,!1);s(()=>{if(n&&m){m=!1;return}if(S&&!window.location.pathname.includes(n)&&!window.location.hash.includes(n)){const a=f(d,h)(n);window.history.replaceState({},"",a)}},[n])}function c(t){return document.getElementById(w(t))}function g(t){const e=["#tag","#operation","#paths"];for(const o of e)if(t.includes(o))return t.replace(o,"").toLowerCase();return""}export{c as getElementById,g as getLegacyHash,v as useAutoScroll};
