import { AppShell } from '@/components/app/app-shell'
import { requireRoleRoute } from '@/lib/role-route'
import { loadUnitPhotos } from '@/lib/data/pilot-units'
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
  const unitPhotos = await loadUnitPhotos(user.id)
  return (
    <AppShell profile={profile}>
      {/* `onboarding=new` = the just-validated-email state the signup replica hands off to. */}
      <PilotDriverView fresh={onboarding === 'new'} unitPhotos={unitPhotos} />
    </AppShell>
  )
}
