import { hasPermission, Role } from "@/lib/validation/permissions";
import { auth } from "@/server/auth";
import { notFound } from "next/navigation";
import React from "react";
import AdminNavbar from "./_components/admin-navbar";
import { SidebarProvider } from "@/components/ui/sidebar";
import { AdminSidebar } from "./_components/admin-sidebar";

async function Layout({ children }: { children: React.ReactNode }) {
  const session = await auth();
  const isAdmin = session?.user
    ? hasPermission(session.user.role, Role.ADMIN)
    : false;
  if (!isAdmin) return notFound();
  return (
    <SidebarProvider>
      <AdminSidebar />
      <div className="w-full">
        {/* <AdminNavbar />  */}
        <main className="space-y-4 p-4"> {children}</main>
      </div>
    </SidebarProvider>
  );
}

export default Layout;
