import{withPathPrefix as p}from"@redocly/theme/core/utils";import{removeTrailingSlash as a}from"../../../utils/url/remove-trailing-slash";import{isAbsoluteUrl as c}from"../../../utils/url/is-absolute-url";function P(t,n,r=""){return t.map(e=>{const s=m(e,r,n),o=u(e,r,n);return{...e,items:P(e.items||[],n,r),active:s&&!o,hasActiveSubItem:o}}).filter(Boolean)}function m(t,n="",r){if(!t.link||c(t.link))return!1;const[e,s]=t.link.split("#"),o=r.pathname,i=k(o,e),h=decodeURIComponent(a(p(i))),l=decodeURIComponent(a(o));if(n)return h===a(n)||s===n;if(s){const f=r.hash?r.hash.substring(1):"";return s===f}else return h===l}function u(t,n="",r){return(t.items||[]).some(s=>m(s,n,r)||u(s,n,r))}function k(t,n){const r=new URL(t,"http://localhost");return new URL(n,r.href).pathname}export{P as mapItemsPropsToState};
