import{jsx as e,jsxs as c,Fragment as x}from"react/jsx-runtime";import{memo as E,useRef as C,useEffect as O,useMemo as j}from"react";import{LayoutVariant as u}from"@redocly/config";import{useSetAtom as A}from"jotai";import{ThreePanelLayout as I}from"@redocly/theme/layouts/ThreePanelLayout";import{SidebarLogo as M}from"@redocly/theme/components/SidebarLogo/SidebarLogo";import{GlobalStyle as v,useMount as N}from"@redocly/theme/core/openapi";import{RedocTelemetry as _}from"../../telemetry/RedocTelemetry.js";import{StoreProvider as D}from"./Providers.js";import{Overlay as V}from"../Overlay.js";import{RedocWrap as k}from"./styled.js";import{StickyResponsiveSidebar as B}from"../StickySidebar/index.js";import{SideMenu as K}from"../SideMenu/index.js";import{Content as F}from"../Content/index.js";import{useContentItems as H,useUppercase2LowercaseRedirect as U,useTelemetry as Y,usePerformanceMetrics as G}from"../../hooks/index.js";import{withRouter as W}from"../../hoc/withRouter.js";import{withStore as q}from"../../hoc/withStore.js";import{compose as z}from"../../utils/index.js";import{useLicense as J}from"../../hooks/useLicense.js";import{allOperationsAtom as Q}from"../../jotai/replay.js";import{TelemetryContext as X}from"../../contexts/telemetry.js";const Z=z(W,q,E)(({licenseKey:a,onLoaded:l,children:o,options:t,layout:s,collapsedSidebar:i,parser:n,withCommonStyles:b})=>{const R=C(null),{isValid:f,licenseInfo:g}=J(a),h=A(Q),y=Y();U();const{contentItems:w,flatItems:p}=H({parser:n,options:t});G({sendTelemetry:d=>{const r=Object.fromEntries(Object.entries(d).map(([T,L])=>[T.toLowerCase(),L]));y.sendPerformanceMetricsMessage([{id:"metrics",object:"metrics",uri:typeof window<"u"?window.location.href:"",cls:r.cls,lcp:r.lcp,fcp:r.fcp,ttfb:r.ttfb}])}}),O(()=>{if(!t.hideReplay&&p.length>0){const d=p.filter(r=>r.type==="operation");h(d)}},[p,t.hideReplay,h]),N(()=>{l?.(),y.sendViewedMessage([{id:window.location.href,object:"page",uri:window.location.href,layout:s}])});const{hideSidebar:P,scrollYOffset:S}=t||{},m=n.definition?.info?.["x-logo"];return c(x,{children:[b&&e(v,{}),c(k,{className:"redoc-wrap",ref:R,children:[!f&&e(V,{licenseInfo:g}),!P&&c(B,{scrollYOffset:S,className:"menu-content",collapsedSidebar:!i,children:[e(M,{imageUrl:m?.url,href:m?.href||n.definition?.info?.contact?.url,altText:m?.altText,backgroundColor:m?.backgroundColor}),e(K,{items:f?w:[]})]}),c(I,{className:"api-content",id:"api-content",layout:s===u.THREE_PANEL?u.THREE_PANEL:u.STACKED,collapsedSidebar:i,children:[e(F,{items:f?w:[],routingBasePath:t.routingBasePath}),o]})]})]})});function ge({onLoaded:a,children:l,store:o,withCommonStyles:t,router:s,telemetryConfig:i}){const n=j(()=>new _({specType:"openapi",serviceName:"realm-ui",...i}),[i]);return o?.definition?e(X.Provider,{value:n,children:e(D,{...o,children:e(Z,{onLoaded:a,basePath:o.options?.routingBasePath,licenseKey:o.options?.licenseKey,disableRouter:o.options?.disableRouter,withCommonStyles:t,router:s,children:l})})}):null}export{ge as RedoclyOpenAPIDocs};
