"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.OperationsNavigation=exports.OperationsNavigationComponent=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),react_router_dom_1=require("react-router-dom"),theme_1=require("@redocly/theme"),styled_components_1=__importDefault(require("styled-components")),index_1=require("jotai/index"),common_1=require("../common"),utils_1=require("../../utils"),services_1=require("../../services"),app_1=require("../../jotai/app"),MAX_OPERATIONS=8;function OperationsNavigationComponent({items:e,routingBasePath:t}){const[n,o]=(0,react_1.useState)(!1),r=(0,react_router_dom_1.useNavigate)(),i=(0,index_1.useAtomValue)(app_1.layoutAtom)===theme_1.LayoutVariant.STACKED,{operations:a,webhooks:s,count:l}=(0,react_1.useMemo)((()=>{const t=e.filter((e=>"operation"===e.type)),o=n?t:t.slice(0,MAX_OPERATIONS),{operations:r,webhooks:i}=o.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:i,count:!n&&t.length>MAX_OPERATIONS?t.length-MAX_OPERATIONS:0}}),[n,e]);if(!a.length&&!s.length)return null;const c=e=>{r(e)};return(0,jsx_runtime_1.jsxs)(Wrapper,{isStacked:i,"data-testid":"operation-navigation-list",children:[a.length>0&&(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsx)(Heading,{children:"Operations"}),a.map((({id:e,href:n,httpVerb:o,path:r})=>(0,jsx_runtime_1.jsx)(Item,{variant:"outlined",size:"large",onClick:()=>c((0,services_1.joinWithSeparator)(t,(0,utils_1.encodeBackSlashes)(n))),children:(0,jsx_runtime_1.jsxs)("span",{children:[(0,jsx_runtime_1.jsx)(common_1.HttpVerb,{color:o,children:o}),(0,jsx_runtime_1.jsx)(Path,{children:r})]})},e)))]}),s.length>0&&(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsx)(Heading,{children:"Webhooks"}),s.map((({id:e,href:n,httpVerb:o,path:r})=>(0,jsx_runtime_1.jsx)(Item,{variant:"outlined",size:"large",onClick:()=>c((0,services_1.joinWithSeparator)(t,(0,utils_1.encodeBackSlashes)(n))),children:(0,jsx_runtime_1.jsxs)("span",{children:[(0,jsx_runtime_1.jsx)(common_1.HttpVerb,{color:o,children:o}),(0,jsx_runtime_1.jsx)(Path,{children:r})]})},e)))]}),!n&&Boolean(l)&&(0,jsx_runtime_1.jsxs)(StyledButton,{variant:"link",size:"large","data-testid":"show-more-operations",fullWidth:!0,onClick:()=>o(!0),children:["Show ",l," more..."]})]})}exports.OperationsNavigationComponent=OperationsNavigationComponent,exports.OperationsNavigation=(0,react_1.memo)(OperationsNavigationComponent);const Wrapper=(0,styled_components_1.default)(common_1.SamplesPanel)`
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xxs);
  padding-top: var(--spacing-xxl);
`,Heading=styled_components_1.default.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=(0,styled_components_1.default)(theme_1.Button)`
  & + & {
    margin-left: 0;
  }
`,Item=(0,styled_components_1.default)(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_components_1.default.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