import type { V2NavItem } from '@/types/v2/nav' /** * Pure helper — determines whether a V2NavItem is "active" given the current * route name. * * Active rules (simplest correct definition): * 1. Exact match: currentRouteName === item.to.name * 2. Prefix match for nested routes: currentRouteName starts with * item.to.name + '-' (e.g. item "organisation" is active on * "organisation-settings"). The dash boundary prevents "org" from * spuriously matching "organisation-settings". * * Only `to` values that are a plain object with a string `name` property are * compared — string/array `to` values always return false (router-push * style not used in v1 nav). */ export function isNavItemActive( item: V2NavItem, currentRouteName: string | symbol | null | undefined, ): boolean { if (typeof currentRouteName !== 'string') return false const to = item.to if (typeof to !== 'object' || to === null || Array.isArray(to)) return false const itemName = (to as { name?: unknown }).name if (typeof itemName !== 'string') return false return currentRouteName === itemName || currentRouteName.startsWith(`${itemName}-`) }