import AdminResourceList from "@/app/features/AdminList/AdminResourceList";
import { IAddModalField } from "@/app/components/AddModal/types";
import { GROUP_FIELDS } from "../constants";
import { fetchAdminResource } from "@/app/services/adminResources";

export default async function GroupsPage() {
  let initialData = null;

  try {
    initialData = await fetchAdminResource({
      resource: "groups",
      pagination: { page: 1, limit: 100 },
    });
  } catch (error) {
    console.error("Failed to fetch groups:", error);
    // Continue without initial data - component will fetch client-side
  }

  return (
    <AdminResourceList
      title="Groups"
      endpoint="/api/dashboard/admin/groups"
      responseCollectionKeys={["groups", "data", "items"]}
      primaryLabelKeys={["name", "groupName", "title"]}
      chipKeys={["status", "role", "permissions"]}
      addModalFields={GROUP_FIELDS as IAddModalField[]}
      showEnabledToggle={true}
      initialData={initialData}
    />
  );
}
