/**
 * Navigate to a route AND register/activate it in the app's browser-style tab
 * strip (`useTabs()` + localStorage), the idiom used by the modern pages
 * (my-tickets, dashboard, …). Returns `navigateTab(link, text)`.
 */
export const useNavigateTab = () => {
  const tabs = useTabs()
  const router = useRouter()

  return (link: string, text: string) => {
    tabs.value = tabs.value.map((t: any) => ({ ...t, active: false }))
    const existing = tabs.value.findIndex((t: any) => t.link === link)
    if (existing >= 0) {
      tabs.value[existing].active = true
    } else {
      tabs.value.push({ link, text, active: true })
    }
    if (typeof localStorage !== 'undefined') {
      localStorage.setItem('tabs', JSON.stringify(tabs.value))
    }
    router.push(link)
  }
}
