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

export default async function ReportLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const session = await getServerSession(authOptions);
  const abilities = session?.user?.abilities ?? [];
  const canAccess =
    abilities.includes(AUTH.REPORT_MGMT) || abilities.includes(AUTH.ADMIN);

  if (!canAccess) {
    redirect("/dashboard");
  }

  return (
    <I18nProvider namespaces={["report", "navigation", "common"]}>
      {children}
    </I18nProvider>
  );
}
