import { redirect } from "next/navigation";

import { getCurrentAuthContext } from "@/modules/core/server/auth";
import { listOperationalElders } from "@/modules/core/server/operations";
import { EldersClient } from "@/modules/elders/components/EldersClient";

export default async function EldersPage(): Promise<React.ReactElement> {
  const context = await getCurrentAuthContext();
  if (!context) {
    redirect("/login");
  }

  const elders = await listOperationalElders(context.organization?.id);

  return <EldersClient initialElders={elders} permissions={context.permissions} />;
}
