"use client";
import { useQueries as c } from "@tanstack/react-query";
import { n as f } from "./utils-Cfv96A32.js";
import { u as l } from "./useConfig-BBfpOnV-.js";
import { b as d } from "./fetcher-D4o2k9tU.js";
const T = ({
  userAddresses: i,
  pageSize: o,
  pageNumber: s,
  enabled: u = !0
}) => {
  const {
    apiKey: n,
    affiliateId: p,
    baseUrl: m
  } = l();
  return c({
    queries: i.map((t) => ({
      queryKey: ["bungee-order-history", n, t, s],
      queryFn: async () => {
        const a = `${m}/bungee-auto/history?sender=${t}&pageSize=${o}&pageNumber=${s}`;
        return (await d({
          query: a,
          apiKey: n,
          affiliateId: p
        })).result.data;
      },
      enabled: !!(t && u),
      refetchOnWindowFocus: !1,
      retry: !1,
      staleTime: 1e4
    })),
    combine: (t) => {
      const a = t.flatMap((e) => e.data?.requests || []).map((e) => {
        const r = e.destTimestamp ? e.destTimestamp - e.srcTimestamp : 0;
        return {
          ...e,
          primaryInput: e.input?.[0],
          primaryOutput: e.output?.[0],
          swapTime: r,
          isSwapRoute: e.requestType === "SWAP_REQUEST",
          routingMode: "auto"
        };
      });
      return {
        error: t.find((e) => e.isError)?.error.message,
        isError: t.some((e) => e.isError),
        isLoading: t.some((e) => e.isLoading),
        isSuccess: t.every((e) => e.isSuccess),
        data: a?.map(f),
        totalPages: Math.ceil(
          t.reduce((e, r) => e + (r.data?.totalRequests || 0), 0) / (o * t.length)
          // If we have 2 users, and each user has 100 requests, and pageSize is 10, then we have 200 requests in total. So totalPages is `200 / (10 * 2) = 10`.
        ),
        refetch: (e) => Promise.all(t.map((r) => r.refetch(e)))
      };
    }
  });
};
export {
  T as u
};
//# sourceMappingURL=useAutoHistory-BNoxLAtu.js.map
