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

export const metadata: Metadata = {
  title: "Finished Good Management",
};

const Page = async () => {
  const session = await getServerSession(authOptions);
  const abilities = session?.user?.abilities ?? [];
  if (!abilities.includes(AUTH.ADMIN)) {
    redirect("/dashboard");
  }
  return (
    <I18nProvider namespaces={["finishedgoodmanagement","navigation","common"]}>
      <Suspense fallback={<FinishedGoodManagement.Loading />}>
        <FinishedGoodManagement />
      </Suspense>
    </I18nProvider>
  );
};

export default Page;

