import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useMemo,memo,useState}from"react";import{useNavigate}from"react-router-dom";import{Button,LayoutVariant}from"@redocly/theme";import styled from"styled-components";import{useAtomValue}from"jotai/index";import{HttpVerb,SamplesPanel}from"../common";import{encodeBackSlashes}from"../../utils";import{joinWithSeparator}from"../../services";import{layoutAtom}from"../../jotai/app";const MAX_OPERATIONS=8;export function OperationsNavigationComponent({items:e,routingBasePath:t}){const[o,a]=useState(!1),r=useNavigate(),n=useAtomValue(layoutAtom)===LayoutVariant.STACKED,{operations:i,webhooks:s,count:l}=useMemo((()=>{const t=e.filter((e=>"operation"===e.type)),a=o?t:t.slice(0,MAX_OPERATIONS),{operations:r,webhooks:n}=a.reduce(((e,t)=>t.isWebhook?Object.assign(Object.assign({},e),{webhooks:[...e.webhooks,t]}):Object.assign(Object.assign({},e),{operations:[...e.operations,t]})),{operations:[],webhooks:[]});return{operations:r,webhooks:n,count:!o&&t.length>MAX_OPERATIONS?t.length-MAX_OPERATIONS:0}}),[o,e]);if(!i.length&&!s.length)return null;const p=e=>{r(e)};return _jsxs(Wrapper,{isStacked:n,"data-testid":"operation-navigation-list",children:[i.length>0&&_jsxs(_Fragment,{children:[_jsx(Heading,{children:"Operations"}),i.map((({id:e,href:o,httpVerb:a,path:r})=>_jsx(Item,{variant:"outlined",size:"large",onClick:()=>p(joinWithSeparator(t,encodeBackSlashes(o))),children:_jsxs("span",{children:[_jsx(HttpVerb,{color:a,children:a}),_jsx(Path,{children:r})]})},e)))]}),s.length>0&&_jsxs(_Fragment,{children:[_jsx(Heading,{children:"Webhooks"}),s.map((({id:e,href:o,httpVerb:a,path:r})=>_jsx(Item,{variant:"outlined",size:"large",onClick:()=>p(joinWithSeparator(t,encodeBackSlashes(o))),children:_jsxs("span",{children:[_jsx(HttpVerb,{color:a,children:a}),_jsx(Path,{children:r})]})},e)))]}),!o&&Boolean(l)&&_jsxs(StyledButton,{variant:"link",size:"large","data-testid":"show-more-operations",fullWidth:!0,onClick:()=>a(!0),children:["Show ",l," more..."]})]})}export const OperationsNavigation=memo(OperationsNavigationComponent);const Wrapper=styled(SamplesPanel)`
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xxs);
  padding-top: var(--spacing-xxl);
`,Heading=styled.span`
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  font-weight: var(--font-weight-bold);
  color: var(--text-color-primary);
  margin: var(--spacing-sm) 0 var(--spacing-xxs) 0;
`,StyledButton=styled(Button)`
  & + & {
    margin-left: 0;
  }
`,Item=styled(StyledButton)`
  border-radius: var(--border-radius);
  background: var(--bg-color);
  justify-content: space-between;

  & > span {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-unit);
    overflow-x: hidden;
  }

  &:hover {
    background: var(--bg-color);
  }

  &:hover::after {
    content: '→';
    line-height: var(--line-height-base);
  }
`,Path=styled.span`
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--text-color-primary);
  text-decoration: none;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow-x: hidden;
`;
//# sourceMappingURL=OperationsNavigation.js.map