import { Metadata } from "next";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
import { authOptions } from "@/config/authConfig";
import { AUTH } from "@/authorities";

export const metadata: Metadata = {
  title: "M18 Sync",
};

export default async function M18SynLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const session = await getServerSession(authOptions);
  const abilities = session?.user?.abilities ?? [];
  if (!abilities.includes(AUTH.ADMIN)) {
    redirect("/dashboard");
  }
  return <>{children}</>;
}
