import e,{useEffect as S,useState as u}from"react";import y from"styled-components";import{Menu as E}from"@redocly/theme/components/Menu/Menu";import{SidebarActions as I}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 T}from"@redocly/theme/components/Button/Button";import{ArrowLeftIcon as w}from"@redocly/theme/icons/ArrowLeftIcon/ArrowLeftIcon";import{otelTelemetry as p}from"../telemetry/otel/telemetry";import{usePreloadHistory as B}from"../usePreloadHistory";import{useTranslate as P}from"../hooks";import{usePageSharedData as D,usePageVersions as x}from"../../providers/page-data/hooks";import{useSidebarItems as R}from"./useSidebarItems";import{renderAdmonition as V,RequestAccessButton as q}from"./RequestAccessButton";function Y({layoutControls:r}){const{versions:s=[]}=x()||{},f=s.find(t=>t?.active),{translate:a}=P(),{currentItems:b,backLink:n,pushDrilldownState:h,popDrilldownState:k}=R(f),[m,v]=u(),{collapsedSidebar:o}=r,c=D("openAPIDocsStore")?.definition.info?.["x-metadata"]?.apiId,g=B(),[l,i]=u(void 0);return S(()=>{const t=setTimeout(()=>i(void 0),350);return()=>clearTimeout(t)},[l]),e.createElement(e.Fragment,null,e.createElement(A,{collapsed:o,menuItemsAnimation:l,versions:e.createElement(L,{versions:s,onChange:t=>{p.send({type:"version_picker_selection.change",payload:{action:"change"}});const d=location.hash?t?.link+location.hash:t?.link;d&&g.push(d)}}),menu:e.createElement(E,{items:b,onDrilldownOpen:t=>{i("slideInRight"),h(t)}}),footer:e.createElement("div",{style:{width:"100%"}},!o&&V(m),e.createElement(I,{...r,requestAccessButton:c?e.createElement(q,{apiId:c,status:m,setStatus:v}):null})),header:n&&e.createElement(J,{icon:e.createElement(w,null),iconPosition:"left",variant:"ghost",size:"medium","data-component-name":"Sidebar/BackButton",to:n.slug,onClick:()=>{i("slideInLeft"),k(),p.send({type:n.event,payload:{action:"click"}})}},o?"":n.label?e.createElement("div",{"data-translation-key":"sidebar.menu.backToLabel"},a("sidebar.menu.backToLabel",{value:a(n.labelTranslationKey,n.label)})):e.createElement("div",{"data-translation-key":"sidebar.menu.backLabel"},a("sidebar.menu.backLabel")))}))}const J=y(T)`
  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{Y as Sidebar};
