import type { ReactNode } from "react";
import { requireRole } from "@/lib/authorization";
import { UserRole } from "@/generated/prisma/enums";
import { Sidebar } from "@/components/admin/Sidebar";
import { TopBar } from "@/components/admin/TopBar";
import { Breadcrumbs } from "@/components/admin/Breadcrumbs";
import { CommandPalette } from "@/components/admin/CommandPalette";

export const dynamic = "force-dynamic";

export default async function AdminLayout({ children }: { children: ReactNode }) {
  const session = await requireRole([UserRole.ADMIN]);
  return (
    <div data-admin className="flex h-screen w-full overflow-hidden bg-zinc-50">
      <Sidebar />
      <div className="flex min-w-0 flex-1 flex-col">
        <TopBar userEmail={session.user.email ?? ""} />
        <Breadcrumbs />
        <main className="flex-1 overflow-y-auto px-4 pb-12 pt-3">{children}</main>
      </div>
      <CommandPalette />
    </div>
  );
}
