import { redirect } from 'next/navigation'
import { AppShell } from '@/components/app/app-shell'
import { getProfile, getSessionUser } from '@/lib/auth'
import { PilotAssignmentWorkspace } from '@/components/app/pilot-assignment/pilot-assignment-workspace'

/**
 * Admin design review: the carrier's or broker's "My Pilot" tab on a demo
 * pilot assignment (`?as=carrier|broker`). Internal only — an intentional
 * admin/developer testing action, not a customer route.
 */
export default async function Page({
  params,
  searchParams,
}: {
  params: Promise<{ ref: string }>
  searchParams: Promise<{ as?: string }>
}) {
  const user = await getSessionUser()
  if (!user) redirect('/login')
  if (!user.internal) redirect('/dashboard')
  const profile = (await getProfile())!
  const { ref } = await params
  const { as } = await searchParams
  return (
    <AppShell profile={profile}>
      <PilotAssignmentWorkspace assignmentKey={decodeURIComponent(ref)} as={as === 'broker' ? 'broker' : 'carrier'} isAdmin />
    </AppShell>
  )
}
