import { AuthOption } from "@/app/api/auth/[...nextauth]/models/AuthOption";
import CallToast from "@/components/CallToast";
import { getDictionary } from "@/dictionaries";
import { getLocale } from "@/lib/locales";
import { UserPermissions } from "@/models/permissions";
import { getServerSession } from "next-auth";
import Users from "./components";

export default async function UsersPage() {
  const dict = await getDictionary(getLocale());

  const { user }: any = await getServerSession(AuthOption);

  const permissions = new UserPermissions({ permissions: user.permissions });

  if (!permissions.canViewUserList()) {
    return (
      <CallToast
        notify={{
          message: dict.pages.general.error[403],
          type: "warning",
        }}
        target="/dashboard"
      />
    );
  }

  return <Users />;
}
