import{jsx as i,jsxs as y}from"react/jsx-runtime";import{useMemo as N,memo as j,useState as E,useCallback as W}from"react";import{useNavigate as B}from"react-router-dom";import{LayoutVariant as _}from"@redocly/config";import{useAtomValue as V}from"jotai/index";import{SamplesPanel as z}from"../common/index.js";import{layoutAtom as D}from"../../jotai/app.js";import{OperationNavigationItems as p}from"./OperationNavigationItems.js";import{StyledButton as K}from"./styled.js";import{useTranslate as L}from"../../hooks/index.js";import{styled as X}from"../../styled-components.js";import{isRenderableMenuItem as q}from"../../utils/menu.js";const m=8;function F({items:c,routingBasePath:n}){const o=L(),[r,O]=E(!1),u=B(),P=V(D)===_.STACKED,{operations:h,webhooks:d,schemas:f,mcpTools:g,showMoreCount:k,totalCount:w,mcpResources:C,mcpPrompts:x}=N(()=>{const s=c.filter(e=>q(e)),b=r?s:s.slice(0,m),{operations:v,additionalOperations:S,webhooks:M,schemas:T,mcpTools:R,mcpResources:A,mcpPrompts:I}=b.reduce((e,t)=>{if(t.type==="operation"&&t.isWebhook)e.webhooks.push(t);else if(t.type==="operation"){const l=t;l.isAdditionalOperation?e.additionalOperations.push(l):e.operations.push(l)}else t.type==="schema"?e.schemas.push(t):t.type==="tool"?e.mcpTools.push(t):t.type==="rsrc"?e.mcpResources.push(t):t.type==="prompt"&&e.mcpPrompts.push(t);return e},{operations:[],additionalOperations:[],webhooks:[],schemas:[],mcpTools:[],mcpResources:[],mcpPrompts:[]});return{operations:[...v,...S],schemas:T,mcpTools:R,webhooks:M,mcpResources:A,mcpPrompts:I,showMoreCount:!r&&s.length>m?s.length-m:0,totalCount:s.length}},[r,c]),a=W(s=>u(s),[u]);return w?y(G,{isStacked:P,"data-testid":"operation-navigation-list",children:[f.length>0&&i(p,{items:f,onClick:a,routingBasePath:n,translate:o,title:o("openapi.schemas","Schemas")}),g.length>0&&i(p,{items:g,onClick:a,routingBasePath:n,translate:o,title:o("openapi.mcp.tools","MCP Tools")}),C.length>0&&i(p,{items:C,onClick:a,routingBasePath:n,translate:o,title:o("openapi.mcp.resources","MCP Resources")}),x.length>0&&i(p,{items:x,onClick:a,routingBasePath:n,translate:o,title:o("openapi.mcp.prompts","MCP Prompts")}),h.length>0&&i(p,{items:h,onClick:a,routingBasePath:n,translate:o,title:o("openapi.operations","Operations")}),d.length>0&&i(p,{items:d,onClick:a,routingBasePath:n,translate:o,title:o("openapi.webhooks","Webhooks")}),!r&&!!k&&y(K,{variant:"link",size:"large","data-testid":"show-more-operations",fullWidth:!0,onClick:()=>O(!0),children:[o("openapi.actions.show","Show")," ",k," ",o("openapi.actions.more","more"),"..."]})]}):null}const io=j(F),G=X(z)`
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xxs);
  padding-top: var(--spacing-xxl);
`;export{io as OperationsNavigation,F as OperationsNavigationComponent};
