import{useActiveSectionId}from"@redocly/theme";import{useMemo}from"react";import{useLocation}from"react-router-dom";import{pathMatchedLink}from"../../../utils";export function useMenuItems({items:e}){const t=useLocation(),i=useActiveSectionId(t,!1,!1);return useMemo((()=>mapAndSetActiveItems(e,i,t)),[i,e,t])}function mapAndSetActiveItems(e,t="",i){const s=[];return convertOpenAPIDocs2Sidebar({contentItems:e,sidebarItems:s,activeItemId:t,location:i}),s}function isItemActive(e,t="",i){return!!e.href&&(t?e.id===t:pathMatchedLink(i,e.href))}function isSubItemActive(e,t="",i){return(e.items||[]).some((e=>isItemActive(e,t,i)||isSubItemActive(e,t,i)))}function convertOpenAPIDocs2Sidebar(e){const{contentItems:t,sidebarItems:i,activeItemId:s,location:c}=e;let o=!0;for(const n of t){const t=isItemActive(n,s,c),a=isSubItemActive(n,s,c);switch(n.type){case"group":i.push({type:"separator",label:n.name,active:t,hasActiveSubItem:a}),convertOpenAPIDocs2Sidebar(Object.assign(Object.assign({},e),{contentItems:n.items,sidebarItems:i}));break;case"tag":const m={type:"group",label:n.name,items:[],link:n.href,active:t,hasActiveSubItem:a,modified:!0};i.push(m),convertOpenAPIDocs2Sidebar({contentItems:n.items,sidebarItems:m.items||[],activeItemId:s,location:c});break;case"operation":case"schema":n.isWebhook&&o&&(i.push({type:"separator",label:"Webhooks",variant:"secondary"}),o=!1),i.push({type:"link",label:n.name,httpVerb:"schema"===n.type?"schema":n.httpVerb,link:n.href,badges:n.badges,active:t,hasActiveSubItem:a,modified:!0,deprecated:n.deprecated});break;case"section":if(-1===n.depth)continue;const r={type:n.items.length?"group":"link",label:n.name,link:n.href,items:[],active:t,hasActiveSubItem:a,modified:!0};i.push(r),n.items.length&&convertOpenAPIDocs2Sidebar({contentItems:n.items,sidebarItems:r.items,activeItemId:s,location:c})}}}
//# sourceMappingURL=useMenuItems.js.map