import { AppShell } from '@/components/app/app-shell'
import { ViewSwitcher } from '@/components/app/view-switcher'
import { isRoleSwitchEnabled } from '@/lib/auth/env-users'
import { requireRoleRoute } from '@/lib/role-route'
import { PilotDriverView } from './pilot-driver-view'

/** Pilot Car Driver App / Dashboard (PC). Phase 1 replica on demo data — internal admins only. */
export default async function PilotDriverDashboardPage({
  searchParams,
}: {
  searchParams: Promise<{ onboarding?: string }>
}) {
  const { user, profile } = await requireRoleRoute('pilot-driver')
  const { onboarding } = await searchParams
  return (
    <AppShell profile={profile}>
      {user.internal && !isRoleSwitchEnabled() && <ViewSwitcher current="pilot-driver" />}
      {/* `onboarding=new` = the just-validated-email state the signup replica hands off to. */}
      <PilotDriverView fresh={onboarding === 'new'} />
    </AppShell>
  )
}
