import { getServerSession } from 'next-auth'
import { redirect } from 'next/navigation'
import { authOptions } from '@/lib/auth'
import DashboardShell from './DashboardShell'

export const metadata = {
  title: 'Dashboard | LexMind',
  description: 'Painel de controle da plataforma LexMind',
}

export default async function DashboardLayout({
  children,
}: {
  children: React.ReactNode
}) {
  const session = await getServerSession(authOptions)

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

  return (
    <DashboardShell
      user={{
        name: session.user.name,
        email: session.user.email,
        plan: session.user.plan,
        avatar: session.user.avatar,
        oabNumber: session.user.oabNumber,
        oabState: session.user.oabState,
      }}
    >
      {children}
    </DashboardShell>
  )
}
