import{useMemo as p}from"react";import{useLocation as k}from"react-router-dom";import{useThemeConfig as g}from"@redocly/theme";import{usePageVersions as v,useTranslate as x,usePageSharedData as f}from"../hooks";import{useSidebarItems as B}from"./useSidebarItems";function L(){const l=f("sidebar")?.relatedNavbarItem,i=f("current-catalog-info"),e=g(),{translate:n}=x(),{versions:r=[]}=v()||{},s=r.find(h=>h?.active),{allSidebarItems:o}=B(s),t=k().pathname,c=i?.item,a=i?.catalog,m=e.breadcrumbs?.prefixItems,b=e.breadcrumbs?.hide;return p(()=>T({allSidebarItems:o,pathname:t,catalogItemInfo:c,relatedNavbarItem:l,catalogInfo:a,prefixItems:m,hide:b,translate:n}),[t,l,o,c,a,m,b,n])}const T=({allSidebarItems:l,pathname:i,catalogItemInfo:e,relatedNavbarItem:n,catalogInfo:r,prefixItems:s,hide:o,translate:u})=>{if(o===!0)return[];const t=d(l,i);if(t.length===0)return[];if(e&&t.unshift({label:e.label,link:e.link}),n&&n.label!==t[0].label&&t.unshift(n),r&&t.unshift({label:u(r.labelTranslationKey,r.label),link:r.link}),s?.length){const c=s.map(a=>({label:u(a.labelTranslationKey,a.label),link:a.link}));t.unshift(...c)}return t.length===1&&(!t[0]?.link||t[0]?.link===i)?[]:t},d=(l,i)=>{const e=l.find(({active:r,hasActiveSubItem:s})=>r||s);if(!e?.label)return[];const n={label:e.label,link:e.link};return e.type==="group"&&e.selectFirstItemOnExpand&&e.items?.[0]?.link&&(n.link=e.items[0].link),e.items?.length||(n.link=void 0),[n,...d(e.items||[],i)]};export{T as generateBreadcrumbs,L as useBreadcrumbs};
