import type { PageContext } from '@/lib/page-context'

/**
 * Admin → View As (Nash, 2026-09-22): the dashboard shortcuts that used to
 * live in the Pilot Testing bar, now a section of the Admin menu. Navigation
 * only — the admin keeps their identity and permissions; `requireRoleRoute`
 * already lets an internal admin open any role's pages, and every role page
 * keeps its own routes (a carrier trip opens the Carrier Trip View, never the
 * broker one).
 */
export interface ViewAsItem {
  label: string
  href: string
  /** The role environment this opens; null for admin tools. */
  context: PageContext | null
  /** Path prefixes that count as "inside" this environment. */
  activeOn: string[]
}

export const VIEW_AS_ITEMS: ViewAsItem[] = [
  { label: 'Broker Dashboard', href: '/fb-dashboard', context: 'broker', activeOn: ['/fb-dashboard', '/fb-trip-workspace', '/fb-new-trip', '/fb-new-trip-request'] },
  { label: 'Carrier Dashboard', href: '/cd-dashboard', context: 'carrier', activeOn: ['/cd-dashboard', '/cd-trip-workspace', '/cd-new-trip'] },
  { label: 'Pilot Company Dashboard', href: '/pd-dashboard', context: 'pilot-company', activeOn: ['/pd-dashboard', '/pd-trip-workspace', '/pd-new-trip'] },
  { label: 'Carrier Driver App', href: '/ct-dashboard', context: 'carrier-driver', activeOn: ['/ct-dashboard', '/ct-trip-workspace'] },
  { label: 'Pilot Driver App', href: '/pc-dashboard', context: 'pilot-driver', activeOn: ['/pc-dashboard', '/pc-trip-workspace'] },
  { label: 'Admin Dashboard', href: '/admin/users', context: null, activeOn: ['/admin/users', '/admin/company-review', '/admin/email-templates', '/admin/email-health', '/admin/pilot-invitations', '/admin/intake-security'] },
  { label: 'Moderator Tools', href: '/admin/moderation', context: null, activeOn: ['/admin/moderation'] },
]

/** Which environment a path belongs to, for the compact "Admin Preview Mode" bar. */
export function viewAsFor(pathname: string): ViewAsItem | null {
  return VIEW_AS_ITEMS.find((i) => i.activeOn.some((p) => pathname === p || pathname.startsWith(`${p}/`))) ?? null
}

/** Where "Exit Preview" goes. */
export const ADMIN_HOME = '/admin/moderation'
