{"version":3,"file":"active.mjs","names":[],"sources":["../../../src/dashboard/ConsoleNav/active.ts"],"sourcesContent":["import type { ConsoleNavGroup, ConsoleNavItem } from './type';\n\nexport function matchesNavPath(pathname: string, item: Pick<ConsoleNavItem, 'end' | 'href'>) {\n  if (item.end || item.href === '/') return pathname === item.href;\n  return pathname === item.href || pathname.startsWith(`${item.href}/`);\n}\n\n/** Longest matching href wins, so `/resources/new` does not also light up `/`. */\nexport function resolveActiveHref(pathname: string, items: readonly ConsoleNavItem[]) {\n  return items\n    .filter((item) => matchesNavPath(pathname, item))\n    .sort((left, right) => right.href.length - left.href.length)[0]?.href;\n}\n\nexport function collectNavItems(groups: readonly ConsoleNavGroup[]): ConsoleNavItem[] {\n  return groups.flatMap((group) => [\n    ...(group.items ?? []),\n    ...collectNavItems(group.groups ?? []),\n  ]);\n}\n\n/**\n * Keys of the groups on the path to the active page, outermost first. A group\n * overview page (`href`) counts as being inside that group.\n */\nexport function findActiveBranch(\n  pathname: string,\n  groups: readonly ConsoleNavGroup[],\n  activeHref: string | undefined,\n): string[] {\n  for (const group of groups) {\n    if (group.href && pathname === group.href) return [group.key];\n    const nested = findActiveBranch(pathname, group.groups ?? [], activeHref);\n    if (nested.length > 0) return [group.key, ...nested];\n    if (activeHref && group.items?.some((item) => item.href === activeHref)) return [group.key];\n  }\n  return [];\n}\n"],"mappings":";AAEA,SAAgB,eAAe,UAAkB,MAA4C;CAC3F,IAAI,KAAK,OAAO,KAAK,SAAS,KAAK,OAAO,aAAa,KAAK;CAC5D,OAAO,aAAa,KAAK,QAAQ,SAAS,WAAW,GAAG,KAAK,KAAK,EAAE;AACtE;;AAGA,SAAgB,kBAAkB,UAAkB,OAAkC;CACpF,OAAO,MACJ,QAAQ,SAAS,eAAe,UAAU,IAAI,CAAC,CAAC,CAChD,MAAM,MAAM,UAAU,MAAM,KAAK,SAAS,KAAK,KAAK,MAAM,CAAC,CAAC,EAAE,EAAE;AACrE;AAEA,SAAgB,gBAAgB,QAAsD;CACpF,OAAO,OAAO,SAAS,UAAU,CAC/B,GAAI,MAAM,SAAS,CAAC,GACpB,GAAG,gBAAgB,MAAM,UAAU,CAAC,CAAC,CACvC,CAAC;AACH;;;;;AAMA,SAAgB,iBACd,UACA,QACA,YACU;CACV,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,MAAM,QAAQ,aAAa,MAAM,MAAM,OAAO,CAAC,MAAM,GAAG;EAC5D,MAAM,SAAS,iBAAiB,UAAU,MAAM,UAAU,CAAC,GAAG,UAAU;EACxE,IAAI,OAAO,SAAS,GAAG,OAAO,CAAC,MAAM,KAAK,GAAG,MAAM;EACnD,IAAI,cAAc,MAAM,OAAO,MAAM,SAAS,KAAK,SAAS,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG;CAC5F;CACA,OAAO,CAAC;AACV"}