/**
 * Dashboard Dev Tools Layout
 *
 * Gates everything under /dashboard/dev/* to admin/superadmin, since these
 * are internal reference pages (e.g. the component style guide) rather than
 * dealer-facing dashboard features.
 */

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

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

  if (!session?.user?.id) {
    redirect('/auth/signin?callbackUrl=/dashboard/dev/style-guide');
  }

  const role = session.user.role;
  if (role !== 'admin' && role !== 'superadmin') {
    redirect('/dashboard');
  }

  return <>{children}</>;
}
