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 b}from"../../utils";import{PageDataContext as s}from"./PageDataContext.js";import{Loader as y}from"../../runtime/loader";import{useRawSidebarItems as C}from"../../app/Sidebar/useSidebarItems";import{usePageSharedData as c}from"./use-page-shared-data";export*from"./use-page-shared-data";function l(){return a(s)}function F(){return a(s)?.props||{}}function x(){const t=S(),{versions:o=[]}=a(s)||{};return{versions:i.useMemo(()=>o.map(e=>{const r=!!g(t,n=>n.version===e.version&&typeof n.link=="string"&&m(f(n.link))===m(f(e.link))),d=g(t,n=>n.version===e.version&&!!n.link);return{...e,link:(r?e.link:d?.link)||e.link}}),[o,t])}}function S(){const t=c("sidebar")?.items;return i.useMemo(()=>t||[],[t])}function R(){const t=c("sidebar")?.catalogEntity?.key,o=l()?.props.entity;return t||o?.key}function w(){const t=c("sidebar")?.catalogEntity;return l()?.props?.catalogConfig||t?.catalogConfig}function K(){const t=p(),{versions:o=[]}=x()||{},u=o.find(r=>r?.active),e=C(u);return i.useMemo(()=>{if(e)return b(e,t.pathname)},[t.pathname,e])}function T(){const t=p();return y.loadSync(t.pathname)}export{l as usePageData,T as usePageDataLoader,F as usePageProps,x as usePageVersions,w as useSidebarConnectedCatalogConfig,R as useSidebarConnectedCatalogEntity,S as useSidebarItemsData,K as useSidebarSiblingsData};
