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: "圖表報告",
};

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