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

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

  if (!session) {
    redirect('/driver-login');
  }

  if (session.user.role !== 'DRIVER') {
    redirect('/dashboard');
  }

  return <>{children}</>;
}
