import*as o from"react";import{useEffect as p}from"react";import{Outlet as E,useLocation as f,useNavigate as g}from"react-router-dom";import{components as d}from"@redocly-markdoc/components";import D from"@markdoc/markdoc/dist/react";import{InternalServerErrorLayout as h}from"@redocly/theme";import{RootLayout as P}from"@redocly/theme/layouts/RootLayout";import{PageLayout as C}from"@redocly/theme/layouts/PageLayout";import{components as l}from"@redocly/theme/markdoc/default";import{Sidebar as T}from"./app/Sidebar/Sidebar";import{loadAndNavigate as v}from"./app/utils/loadAndNavigate";import{useActions as L}from"./app/Sidebar/useActions";import{useScrollTracker as _}from"./app/hooks/useScrollTracker";import{OPENAPI_DOCS_TEMPLATE_ID as S,ASYNC_API_DOCS_TEMPLATE_ID as N}from"../constants/index.js";import*as O from"../server/plugins/markdown/markdoc/custom-components/index";import{isTag as b,removeTrailingSlash as y}from"../shared/utils";import{ErrorBubble as A}from"./app/ErrorBubble";import{DefaultStyles as I}from"./styling/default-styles";import{ThemeDataProvider as R}from"./providers/theme/ThemeDataProvider";import{PageDataContext as k}from"./providers/page-data/PageDataContext";import{SeoTags as x}from"./app/seo/SeoTags";import{useRouterForLocalLinks as V,useRunningEnvironmentCheck as B}from"./providers/hooks";import{usePageData as M,usePageDataLoader as G,useSidebarItemsData as F}from"./providers/page-data/hooks";import{ErrorBoundary as Y}from"./ErrorBoundary";import{ErrorDetails as i,Loader as j}from"./server-entry";import"@styles";import{useRouteChangeTracker as q}from"./app/hooks/useRouteChangeTracker";import{isInIframe as w}from"./utils";import{useL10n as z}from"./app/l10n";import{PostMessageProvider as H}from"./providers/post-message/PostMessageProvider";import{ScriptLoader as J}from"./ScriptLoader";import{clientRoutes as K}from"./runtime/generated/routes.js";import{PageCounter as Q}from"./app/PageCounter";globalThis.__LOADER.markdocComponents={...O,...l};function Oe(){const e=G(),[t,a]=o.useState(e),r=f(),m=g();z(),p(()=>{e?a(e):v({navigate:m,to:r.pathname+r.search+r.hash}).then(()=>a(j.loadSync(r.pathname)))},[r,m]),V();const n=B();return n?(console.log(n),o.createElement(i,{error:{message:n,name:""}})):t?o.createElement(Y,null,o.createElement(I,null),o.createElement(k.Provider,{value:e||t},o.createElement(R,null,o.createElement(H,{enabled:process.env.NODE_ENV==="development"||w()},o.createElement(E,null))))):null}function c(){q(),_();const e=M(),t=L(),{layout:a}=t,r={layout:a},m=F(),n=process.env.NODE_ENV!=="production",s=e?.props.ast&&b(e.props.ast)?D(e.props.ast,o,{components:{...globalThis.__LOADER.markdocComponents,...l,...d}}):null,u=y(e?.slug||"");return p(()=>{document.documentElement.classList.add("ready")},[]),e?.props.pagePropGetterError?.message?n?o.createElement(i,{error:{...e?.props?.pagePropGetterError}}):o.createElement(h,null):e?.props?.compilationErrors?.length?e?.Template?o.createElement(e.Template,{pageProps:e?.props,children:s}):null:o.createElement(o.Suspense,null,o.createElement(P,null,o.createElement(C,{sidebar:m.length>0&&o.createElement(T,{layoutControls:t})},o.createElement(x,{seo:e?.props.seo,slug:u}),e?.Template?o.createElement(e.Template,{pageProps:[S,N].includes(e.templateId)?{...e.props,apiOptions:r}:e?.props,children:s}):null),process.env.NODE_ENV!=="production"&&o.createElement(A,null),process.env.NODE_ENV!=="production"&&o.createElement(Q,null),o.createElement(J,null)))}const be=[...K.map(e=>({Component:c,path:e.substring(1)+"/*"})),{Component:c,path:"*"}];export{Oe as App,c as Page,be as routes};
