import { unref as k, watch as E, isRef as q, shallowRef as N, ref as P } from "vue";
function B(n) {
  return typeof n == "function" ? n() : k(n);
}
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const S = () => {
};
function U(n, l = !1, o = "Timeout") {
  return new Promise((h, p) => {
    setTimeout(l ? () => p(o) : h, n);
  });
}
function A(n, l = !1) {
  function o(e, { flush: t = "sync", deep: r = !1, timeout: c, throwOnTimeout: v } = {}) {
    let s = null;
    const d = [new Promise((m) => {
      s = E(
        n,
        (a) => {
          e(a) !== l && (s == null || s(), m(a));
        },
        {
          flush: t,
          deep: r,
          immediate: !0
        }
      );
    })];
    return c != null && d.push(
      U(c, v).then(() => B(n)).finally(() => s == null ? void 0 : s())
    ), Promise.race(d);
  }
  function h(e, t) {
    if (!q(e))
      return o((a) => a === e, t);
    const { flush: r = "sync", deep: c = !1, timeout: v, throwOnTimeout: s } = t ?? {};
    let i = null;
    const m = [new Promise((a) => {
      i = E(
        [n, e],
        ([u, T]) => {
          l !== (u === T) && (i == null || i(), a(u));
        },
        {
          flush: r,
          deep: c,
          immediate: !0
        }
      );
    })];
    return v != null && m.push(
      U(v, s).then(() => B(n)).finally(() => (i == null || i(), B(n)))
    ), Promise.race(m);
  }
  function p(e) {
    return o((t) => !!t, e);
  }
  function b(e) {
    return h(null, e);
  }
  function x(e) {
    return h(void 0, e);
  }
  function g(e) {
    return o(Number.isNaN, e);
  }
  function C(e, t) {
    return o((r) => {
      const c = Array.from(r);
      return c.includes(e) || c.includes(B(e));
    }, t);
  }
  function w(e) {
    return f(1, e);
  }
  function f(e = 1, t) {
    let r = -1;
    return o(() => (r += 1, r >= e), t);
  }
  return Array.isArray(B(n)) ? {
    toMatch: o,
    toContains: C,
    changed: w,
    changedTimes: f,
    get not() {
      return A(n, !l);
    }
  } : {
    toMatch: o,
    toBe: h,
    toBeTruthy: p,
    toBeNull: b,
    toBeNaN: g,
    toBeUndefined: x,
    changed: w,
    changedTimes: f,
    get not() {
      return A(n, !l);
    }
  };
}
function D(n) {
  return A(n);
}
function O(n) {
  const {
    initialData: l,
    shallow: o,
    onSuccess: h = S,
    onError: p = S,
    immediate: b,
    resetOnExecute: x = !1,
    queryFn: g,
    queryKey: C
  } = n, w = (o ? N : P)(l), f = P(!1), e = P(!1), t = P(!1), r = N(), c = (u) => {
    e.value = u, f.value = !u;
  }, v = () => {
    x && (w.value = l);
  }, s = () => new Promise((u, T) => {
    D(f).toBe(!0).then(() => r.value ? T(r.value) : u(a));
  }), i = {
    then: (...u) => s().then(...u),
    catch: (...u) => s().catch(...u)
  };
  let d = 0;
  const m = (u) => {
    if (r.value = void 0, e.value)
      return i;
    if (g === void 0)
      return f.value = !0, i;
    v(), c(!0), d += 1;
    const T = d;
    return g(u).then((y) => {
      const F = y;
      w.value = F, h(F);
    }).catch((y) => {
      r.value = y, p(y);
    }).finally(() => {
      var y;
      (y = n.onFinish) == null || y.call(n), T === d && c(!1);
    }), i;
  };
  b && m();
  const a = {
    data: w,
    error: r,
    isFinished: f,
    isLoading: e,
    isAborted: t,
    isCanceled: t,
    execute: m
  };
  return {
    ...a,
    ...i
  };
}
export {
  O as useHttp
};
//# sourceMappingURL=useHttp.mjs.map
