import { auth } from "@/lib/auth";
import { redirect } from "next/navigation";
import { AdminShell } from "@/components/admin/AdminShell";

export default async function AdminLayout({ children }: { children: React.ReactNode }) {
  const session = await auth();
  const role = (session?.user as any)?.role;

  if (!["ADMIN", "SUPERADMIN", "MODERATOR", "EDITOR"].includes(role)) {
    redirect("/login?callbackUrl=/admin");
  }

  const user = session?.user
    ? {
        name: session.user.name,
        email: session.user.email,
        image: session.user.image,
        role: (session.user as any)?.role,
      }
    : undefined;

  return (
    <AdminShell
      user={user}
      siteName="MTBR"
      brandShort="MT"
      brandAccentColor="#2563eb"
    >
      {children}
    </AdminShell>
  );
}
