import { getSessionUser } from '@/lib/auth'
import { isRoleSwitchEnabled } from '@/lib/auth/env-users'
import { RoleSwitcher } from './role-switcher'
import { AdminPreviewBarClient } from './admin-preview-bar-client'

/**
 * Compact admin status bar (Nash, 2026-09-22): "Admin Preview Mode — Viewing
 * Carrier Dashboard — Exit Preview". Replaces the permanent Pilot Testing
 * bar; the dashboard shortcuts now live in the Admin menu under View As.
 * Internal accounts only. ADMIN_LEGACY_TESTING_BAR=true brings the old bar
 * back while the new navigation is being tested; its code stays until then.
 */
export async function AdminPreviewBar() {
  const user = await getSessionUser()
  if (!user?.internal) return null
  if (process.env.ADMIN_LEGACY_TESTING_BAR === 'true' && isRoleSwitchEnabled()) return <RoleSwitcher currentRole={user.role} />
  return <AdminPreviewBarClient />
}
