import { GraphQlBuilder } from "@contember/client";
import { useContentApiRequest } from "@contember/react-client";
import { useEffect } from "react";
import { useAbortController } from "@contember/react-utils";
const useDataGridTotalCount = (entityName, filter) => {
  const [queryState, sendQuery] = useContentApiRequest();
  const abortController = useAbortController();
  const query = new GraphQlBuilder.QueryBuilder().query((builder) => builder.object("paginate", (builder2) => {
    builder2 = builder2.name(`paginate${entityName}`).object("pageInfo", (builder3) => builder3.field("totalCount"));
    if (filter) {
      builder2 = builder2.argument("filter", filter);
    }
    return builder2;
  }));
  useEffect(() => {
    (async () => {
      try {
        await sendQuery(query, void 0, {
          signal: abortController()
        });
      } catch (e) {
        if (e.name === "AbortError") {
          return;
        }
        throw e;
      }
    })();
  }, [abortController, query, sendQuery]);
  if (queryState.readyState !== "networkSuccess") {
    return void 0;
  }
  return queryState.data.data.paginate.pageInfo.totalCount ?? void 0;
};
export { useDataGridTotalCount };
//# sourceMappingURL=useDataGridTotalCount.js.map
