import { getServerSession } from 'next-auth'
import { redirect } from 'next/navigation'
import { authOptions } from '@/lib/auth'
import AdminNav from '@/components/admin/AdminNav'

export default async function AdminLayout({ children }: { children: React.ReactNode }) {
  const session = await getServerSession(authOptions)
  const role = (session?.user as { role?: string })?.role
  if (!session || (role !== 'SUPER_ADMIN' && role !== 'ADMIN')) {
    redirect('/dashboard')
  }

  return (
    <div className="flex flex-col min-h-full">
      <AdminNav />
      <div className="flex-1">{children}</div>
    </div>
  )
}
