import e,{useEffect as v,useState as f}from"react";import E from"styled-components";import{Menu as I}from"@redocly/theme/components/Menu/Menu";import{SidebarActions as y}from"@redocly/theme/components/SidebarActions/SidebarActions";import{Sidebar as A}from"@redocly/theme/components/Sidebar/Sidebar";import{VersionPicker as L}from"@redocly/theme/components/VersionPicker/VersionPicker";import{Button as P}from"@redocly/theme/components/Button/Button";import{ArrowLeftIcon as w}from"@redocly/theme/icons/ArrowLeftIcon/ArrowLeftIcon";import{withPathPrefix as B}from"@redocly/theme/core/utils";import{telemetry as p}from"../telemetry/index.js";import{usePreloadHistory as D}from"../usePreloadHistory";import{useTranslate as T}from"../hooks";import{usePageSharedData as x,usePageVersions as M}from"../../providers/page-data/hooks";import{useSidebarItems as V}from"./useSidebarItems";import{renderAdmonition as C,RequestAccessButton as R}from"./RequestAccessButton";function $({layoutControls:r}){const{versions:s=[]}=M()||{},b=s.find(t=>t?.active),{translate:i}=T(),{currentItems:m,backLink:n,pushDrilldownState:h,popDrilldownState:k}=V(b),[l,g]=f(),{collapsedSidebar:a}=r,c=x("openAPIDocsStore")?.definition.info?.["x-metadata"]?.apiId,S=D(),[d,o]=f(void 0);return v(()=>{const t=setTimeout(()=>o(void 0),350);return()=>clearTimeout(t)},[d]),m.length?e.createElement(e.Fragment,null,e.createElement(A,{collapsed:a,menuItemsAnimation:d,versions:e.createElement(L,{versions:s,onChange:t=>{p.sendVersionPickerSelectionChangeMessage({action:"change"});const u=location.hash?t?.link+location.hash:t?.link;u&&S.push(B(u))}}),menu:e.createElement(I,{items:m,onDrilldownOpen:t=>{o("slideInRight"),h(t)}}),footer:e.createElement("div",{style:{width:"100%"}},!a&&C(l),e.createElement(y,{...r,requestAccessButton:c?e.createElement(R,{apiId:c,status:l,setStatus:g}):null})),header:n&&e.createElement(q,{icon:e.createElement(w,null),iconPosition:"left",variant:"ghost",size:"medium","data-component-name":"Sidebar/BackButton",to:n.slug,onClick:()=>{o("slideInLeft"),k(),p.sendSidebarDrilldownBackButtonClickedMessage({action:"click"})}},a?"":n.label?e.createElement("div",{"data-translation-key":"sidebar.menu.backToLabel"},i("sidebar.menu.backToLabel",{value:i(n.labelTranslationKey,n.label)})):e.createElement("div",{"data-translation-key":"sidebar.menu.backLabel"},i("sidebar.menu.backLabel")))})):null}const q=E(P)`
  padding: var(--menu-item-padding-vertical) 0;
  height: calc(var(--line-height-base) + var(--menu-item-padding-vertical) * 2);
  justify-content: flex-start;
  width: 100%;
`;export{$ as Sidebar};
