// app/admin/allowed-students/page.tsx
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth-options';
import { redirect } from 'next/navigation';
import { SidebarProvider } from '@/components/ui/sidebar';
import { AppSidebar } from '@/components/app-sidebar';
import { SiteHeader } from '@/components/site-header';
import { SidebarInset } from '@/components/ui/sidebar';
import AllowedStudentsClient from './admin-client';

export const dynamic = 'force-dynamic';

export default async function AllowedStudentsPage() {
  const session = await getServerSession(authOptions);
  const role = (session as any)?.user?.role ?? null;

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

  if (!(role === 'admin' || role === 'superadmin')) {
    redirect('/dashboard');
  }

  return (
    <SidebarProvider>
      <AppSidebar />
      <SidebarInset>
        <SiteHeader />
        <AllowedStudentsClient />
      </SidebarInset>
    </SidebarProvider>
  );
}
