import { useQuery } from "@tanstack/react-query";
import { STATUSES } from "../../../config";
import { exportPoints } from "../../../api";
import { handleExportSuccess } from "../ExportButton";
import { useFilters } from "../../../stores/useFilters";

export const useExportApproveAndWorkingData = (enabled, onSettled) => {
  const {
    filters: { region },
  } = useFilters();

  return useQuery(
    ["export-approve-working", region],
    async () => {
      const params = new URLSearchParams({
        "status[]": [STATUSES.approve, STATUSES.working],
      });

      return await exportPoints(params, region);
    },
    {
      enabled,
      onSuccess: handleExportSuccess,
      onSettled,
    }
  );
};
