import { QueryObserver as b } from "./queryObserver.js";
import { infiniteQueryBehavior as g, hasPreviousPage as x, hasNextPage as p } from "./infiniteQueryBehavior.js";
var m = class extends b {
  constructor(e, t) {
    super(e, t);
  }
  bindMethods() {
    super.bindMethods(), this.fetchNextPage = this.fetchNextPage.bind(this), this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
  }
  setOptions(e) {
    super.setOptions({
      ...e,
      behavior: g()
    });
  }
  getOptimisticResult(e) {
    return e.behavior = g(), super.getOptimisticResult(e);
  }
  fetchNextPage(e) {
    return this.fetch({
      ...e,
      meta: {
        fetchMore: { direction: "forward" }
      }
    });
  }
  fetchPreviousPage(e) {
    return this.fetch({
      ...e,
      meta: {
        fetchMore: { direction: "backward" }
      }
    });
  }
  createResult(e, t) {
    var u, P;
    const { state: s } = e, i = super.createResult(e, t), { isFetching: c, isRefetching: d, isError: a, isRefetchError: v } = i, r = (P = (u = s.fetchMeta) == null ? void 0 : u.fetchMore) == null ? void 0 : P.direction, h = a && r === "forward", o = c && r === "forward", n = a && r === "backward", f = c && r === "backward";
    return {
      ...i,
      fetchNextPage: this.fetchNextPage,
      fetchPreviousPage: this.fetchPreviousPage,
      hasNextPage: p(t, s.data),
      hasPreviousPage: x(t, s.data),
      isFetchNextPageError: h,
      isFetchingNextPage: o,
      isFetchPreviousPageError: n,
      isFetchingPreviousPage: f,
      isRefetchError: v && !h && !n,
      isRefetching: d && !o && !f
    };
  }
};
export {
  m as InfiniteQueryObserver
};
//# sourceMappingURL=infiniteQueryObserver.js.map
