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

export const useExportWorkingData = (enabled, onSettled) => {
  const {
    filters: { region, deltaTraffic, factTraffic, age },
  } = useFilters();

  return useQuery(
    ["export-working", region, deltaTraffic, factTraffic, age],
    async () => {
      const params = new URLSearchParams({
        "status[]": [STATUSES.working],
        "delta_current[]": deltaTraffic,
        "fact[]": factTraffic,
        "age_day[]": age,
      });

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