import i,{useContext as a}from"react";import{useLocation as p}from"react-router-dom";import{removeLeadingSlash as m,removeTrailingSlash as f}from"@redocly/theme/core/utils";import{findDeepFirst as g}from"../../../utils/tree/find-deep-first.js";import{getSiblingPages as y}from"../../utils";import{PageDataContext as s}from"./PageDataContext.js";import{Loader as b}from"../../runtime/loader";import{useRawSidebarItems as v}from"../../app/Sidebar/useSidebarItems";import{usePageSharedData as u}from"./use-page-shared-data";export*from"./use-page-shared-data";function d(){return a(s)}function F(){return a(s)?.props||{}}function C(){const t=k(),{versions:n=[]}=a(s)||{};return{versions:i.useMemo(()=>n.map(e=>{const r=!!g(t,o=>o.version===e.version&&typeof o.link=="string"&&m(f(o.link))===m(f(e.link))),l=g(t,o=>o.version===e.version&&!!o.link);return{...e,link:(r?e.link:l?.link)||e.link}}),[n,t])}}function k(){const t=u("sidebar")?.items;return i.useMemo(()=>t||[],[t])}function R(){const t=u("sidebar")?.catalogEntity,n=d()?.props.entity;return t?{key:t.key,version:t.version}:n?.key?{key:n.key,version:n.version}:void 0}function w(){const t=u("sidebar")?.catalogEntity;return d()?.props?.catalogConfig||t?.catalogConfig}function T(){const t=p(),{versions:n=[]}=C()||{},c=n.find(r=>r?.active),e=v(c);return i.useMemo(()=>{if(e)return y(e,t.pathname)},[t.pathname,e])}function V(){const t=p();return b.loadSync(t.pathname)}export{d as usePageData,V as usePageDataLoader,F as usePageProps,C as usePageVersions,w as useSidebarConnectedCatalogConfig,R as useSidebarConnectedCatalogEntity,k as useSidebarItemsData,T as useSidebarSiblingsData};
