import e,{useEffect as y,useState as b}from"react";import h from"styled-components";import{Menu as w}from"@redocly/theme/components/Menu/Menu";import{SidebarActions as A}from"@redocly/theme/components/SidebarActions/SidebarActions";import{Sidebar as B}from"@redocly/theme/components/Sidebar/Sidebar";import{VersionPicker as I}from"@redocly/theme/components/VersionPicker/VersionPicker";import{Button as L}from"@redocly/theme/components/Button/Button";import{CatalogEntityHistoryButton as P}from"@redocly/theme/components/Catalog/CatalogEntity/CatalogEntityHistory/CatalogEntityHistoryButton";import{ArrowLeftIcon as D}from"@redocly/theme/icons/ArrowLeftIcon/ArrowLeftIcon";import{withPathPrefix as x,getBaseDataAttributes as C,generateBeforeAfterContext as T}from"@redocly/theme/core/utils";import{telemetry as v}from"../telemetry/index.js";import{usePreloadHistory as M}from"../usePreloadHistory";import{useTranslate as V}from"../hooks";import{usePageSharedData as H,usePageVersions as R}from"../../providers/page-data/hooks";import{useSidebarItems as q}from"./useSidebarItems";import{renderAdmonition as J,RequestAccessButton as j}from"./RequestAccessButton";function re({layoutControls:s}){const{versions:l=[]}=R()||{},m=l.find(t=>t?.active),{translate:o}=V(),{currentItems:c,backLink:n,versionLabel:r,pushDrilldownState:g,popDrilldownState:k}=q(m),[d,E]=b(),{collapsedSidebar:i}=s,u=H("openAPIDocsStore")?.definition.info?.["x-metadata"]?.apiId,S=M(),[f,a]=b(void 0);return y(()=>{const t=setTimeout(()=>a(void 0),350);return()=>clearTimeout(t)},[f]),c.length?e.createElement(e.Fragment,null,e.createElement(B,{collapsed:i,menuItemsAnimation:f,versions:e.createElement(I,{versions:l,onChange:t=>{v.sendVersionPickerChangedMessage([...T("versionPicker","dropdown",{version:m?.version||""},{version:t?.version||""})]);const p=location.hash?t?.link+location.hash:t?.link;p&&S.push(x(p))}}),menu:e.createElement(w,{items:c,onDrilldownOpen:t=>{a("slideInRight"),g(t)}}),footer:e.createElement("div",{style:{width:"100%"}},!i&&J(d),e.createElement(A,{...s,requestAccessButton:u?e.createElement(j,{apiId:u,status:d,setStatus:E}):null})),header:(n||r)&&e.createElement(z,null,n&&e.createElement(F,{icon:e.createElement(D,null),iconPosition:"left",variant:"ghost",size:"medium","data-component-name":"Sidebar/BackButton",to:n.slug,onClick:()=>{a("slideInLeft"),k(),v.sendSidebarDrilldownBackClickedMessage([C("sidebarDrilldownBack","button")])}},i?"":n.label?e.createElement("div",{"data-translation-key":"sidebar.menu.backToLabel"},o("sidebar.menu.backToLabel",{value:o(n.labelTranslationKey,n.label)})):e.createElement("div",{"data-translation-key":"sidebar.menu.backLabel"},o("sidebar.menu.backLabel"))),r&&!i&&e.createElement(P,{version:r}))})):null}const z=h.div`
  display: flex;
  flex-direction: column;
  gap: var(--menu-header-container-gap);
  width: 100%;
`,F=h(L)`
  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{re as Sidebar};
