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

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

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

  return (
    <AdminResourceList
      title="Permissions"
      endpoint="/api/dashboard/admin/permissions"
      responseCollectionKeys={["permissions", "data", "items"]}
      primaryLabelKeys={["name", "permissionName", "title", "description"]}
      chipKeys={["status", "scope", "category"]}
      addModalFields={PERMISSION_FIELDS as IAddModalField[]}
      showEnabledToggle={true}
      initialData={initialData}
    />
  );
}
