import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{memo,useRef}from"react";import{GlobalStyle as ThemeCommonStyle,LayoutVariant,SidebarLogo,ThreePanelLayout,useMount}from"@redocly/theme";import{useSetAtom}from"jotai";import{AppProvider,StoreProvider}from"./Providers";import{Overlay}from"../Overlay";import{RedocWrap}from"./styled";import{StickyResponsiveSidebar}from"../StickySidebar";import{SideMenu}from"../SideMenu";import{Content}from"../Content";import{useContentItems,useUppercase2LowercaseRedirect,useOtelTelemetry,usePerformanceMetrics}from"../../hooks";import{withRouter}from"../../hoc/withRouter";import{withStore}from"../../hoc/withStore";import{compose}from"../../utils";import{useLicense}from"../../hooks/useLicense";import{allOperationsAtom}from"../../jotai/replay";const RedoclyOpenAPIDocsComponent=compose(withRouter,withStore,memo)((({licenseKey:e,onLoaded:o,children:t,options:i,layout:n,collapsedSidebar:r,parser:s,withCommonStyles:a})=>{var l,d,c,m,p;const u=useRef(null),{isValid:f,licenseInfo:y}=useLicense(e),v=useSetAtom(allOperationsAtom),h=useOtelTelemetry();useUppercase2LowercaseRedirect();const{contentItems:S,flatItems:j}=useContentItems({parser:s,options:i});usePerformanceMetrics({sendTelemetry:e=>{const o=Object.fromEntries(Object.entries(e).map((([e,o])=>[e.toLowerCase(),o])));h.send({type:"openapi_docs.performance_metrics",payload:{cls:o.cls,lcp:o.lcp,fcp:o.fcp,ttfb:o.ttfb}})}}),useMount((()=>{if(null==o||o(),h.send({type:"openapi_docs.viewed",payload:{layout:n}}),!i.hideReplay){const e=j.filter((e=>"operation"===e.type));v(e)}}));const{hideSidebar:x,scrollYOffset:L}=i||{},_=null===(d=null===(l=s.definition)||void 0===l?void 0:l.info)||void 0===d?void 0:d["x-logo"];return _jsxs(_Fragment,{children:[a&&_jsx(ThemeCommonStyle,{}),_jsxs(RedocWrap,{className:"redoc-wrap",ref:u,children:[!f&&_jsx(Overlay,{licenseInfo:y}),!x&&_jsxs(StickyResponsiveSidebar,{scrollYOffset:L,className:"menu-content",collapsedSidebar:!r,children:[_jsx(SidebarLogo,{imageUrl:null==_?void 0:_.url,href:(null==_?void 0:_.href)||(null===(p=null===(m=null===(c=s.definition)||void 0===c?void 0:c.info)||void 0===m?void 0:m.contact)||void 0===p?void 0:p.url),altText:null==_?void 0:_.altText,backgroundColor:null==_?void 0:_.backgroundColor}),_jsx(SideMenu,{items:f?S:[]})]}),_jsxs(ThreePanelLayout,{className:"api-content",id:"api-content",layout:n===LayoutVariant.THREE_PANEL?LayoutVariant.THREE_PANEL:LayoutVariant.STACKED,collapsedSidebar:r,children:[_jsx(Content,{items:f?S:[],routingBasePath:i.routingBasePath}),t]})]})]})}));export function RedoclyOpenAPIDocs({onLoaded:e,children:o,store:t,withCommonStyles:i}){var n,r,s;return(null==t?void 0:t.definition)?_jsx(StoreProvider,Object.assign({},t,{children:_jsx(RedoclyOpenAPIDocsComponent,{onLoaded:e,basePath:null===(n=t.options)||void 0===n?void 0:n.routingBasePath,licenseKey:null===(r=t.options)||void 0===r?void 0:r.licenseKey,disableRouter:null===(s=t.options)||void 0===s?void 0:s.disableRouter,withCommonStyles:i,children:o})})):null}export function RedoclyOpenAPIDocsStandalone({definition:e,definitionUrl:o,options:t={},activeItemId:i,activeSampleLanguage:n,activeDeepLink:r}){return _jsx(AppProvider,{definition:e,definitionUrl:o,options:t,activeItemId:i,activeSampleLanguage:n,activeDeepLink:r,children:_jsx(RedoclyOpenAPIDocs,{withCommonStyles:!0})})}
//# sourceMappingURL=RedoclyOpenAPIDocs.js.map