import { redirect } from 'next/navigation'
import { auth } from '@/lib/auth'
import { ApplicantNav } from '@/components/layouts/applicant-nav'

export const dynamic = 'force-dynamic'

export default async function ApplicantLayout({
  children,
}: {
  children: React.ReactNode
}) {
  const session = await auth()

  if (!session?.user) {
    redirect('/login')
  }

  if (session.user.role !== 'APPLICANT') {
    redirect('/login')
  }

  return (
    <div className="min-h-screen bg-background">
      <ApplicantNav
        user={{
          name: session.user.name,
          email: session.user.email,
        }}
      />
      <main className="container-app py-6 lg:py-8">{children}</main>
    </div>
  )
}
