import { getCurrentInstance as L, inject as M, unref as X, watch as D, isRef as k, shallowRef as R, ref as C, computed as b } from "vue";
const U = {
  create: () => Promise.resolve({ data: null }),
  // avoids adding a context in tests
  deleteOne: () => Promise.resolve({ data: null }),
  // avoids adding a context in tests
  getList: () => Promise.resolve({
    data: Array.from({ length: 30 }).map((e, n) => ({
      name: n,
      id: n
    })),
    total: 20
  }),
  // avoids adding a context in tests
  getMany: () => Promise.resolve({ data: [] }),
  // avoids adding a context in tests
  getManyReference: () => Promise.resolve({ data: [], total: 0 }),
  // avoids adding a context in tests
  getOne: () => Promise.resolve({ data: null }),
  // avoids adding a context in tests
  update: () => Promise.resolve({ data: null })
  // avoids adding a context in tests
}, E = /* @__PURE__ */ new WeakMap(), B = (...e) => {
  var n;
  const r = e[0], a = (n = L()) == null ? void 0 : n.proxy;
  if (a == null)
    throw new Error("injectLocal must be called in setup");
  return E.has(a) && r in E.get(a) ? E.get(a)[r] : M(...e);
};
function S(e) {
  return typeof e == "function" ? e() : X(e);
}
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const N = () => {
};
function x(e, n = !1, r = "Timeout") {
  return new Promise((a, h) => {
    setTimeout(n ? () => h(r) : a, e);
  });
}
function F(e, n = !1) {
  function r(t, { flush: o = "sync", deep: s = !1, timeout: c, throwOnTimeout: w } = {}) {
    let f = null;
    const v = [new Promise((y) => {
      f = D(
        e,
        (d) => {
          t(d) !== n && (f == null || f(), y(d));
        },
        {
          flush: o,
          deep: s,
          immediate: !0
        }
      );
    })];
    return c != null && v.push(
      x(c, w).then(() => S(e)).finally(() => f == null ? void 0 : f())
    ), Promise.race(v);
  }
  function a(t, o) {
    if (!k(t))
      return r((d) => d === t, o);
    const { flush: s = "sync", deep: c = !1, timeout: w, throwOnTimeout: f } = o ?? {};
    let l = null;
    const y = [new Promise((d) => {
      l = D(
        [e, t],
        ([u, A]) => {
          n !== (u === A) && (l == null || l(), d(u));
        },
        {
          flush: s,
          deep: c,
          immediate: !0
        }
      );
    })];
    return w != null && y.push(
      x(w, f).then(() => S(e)).finally(() => (l == null || l(), S(e)))
    ), Promise.race(y);
  }
  function h(t) {
    return r((o) => !!o, t);
  }
  function g(t) {
    return a(null, t);
  }
  function T(t) {
    return a(void 0, t);
  }
  function p(t) {
    return r(Number.isNaN, t);
  }
  function _(t, o) {
    return r((s) => {
      const c = Array.from(s);
      return c.includes(t) || c.includes(S(t));
    }, o);
  }
  function m(t) {
    return i(1, t);
  }
  function i(t = 1, o) {
    let s = -1;
    return r(() => (s += 1, s >= t), o);
  }
  return Array.isArray(S(e)) ? {
    toMatch: r,
    toContains: _,
    changed: m,
    changedTimes: i,
    get not() {
      return F(e, !n);
    }
  } : {
    toMatch: r,
    toBe: a,
    toBeTruthy: h,
    toBeNull: g,
    toBeNaN: p,
    toBeUndefined: T,
    changed: m,
    changedTimes: i,
    get not() {
      return F(e, !n);
    }
  };
}
function j(e) {
  return F(e);
}
const q = Symbol("DATA_PROVIDER_CONTEXT"), G = () => B(q, U), I = {
  rowKey: "id",
  title: "Fast Start",
  routerMode: "hash",
  basename: "/"
}, V = Symbol("FAST_START_CONTEXT"), W = () => B(V, I), K = {};
function H(e) {
  const {
    initialData: n,
    shallow: r,
    onSuccess: a = N,
    onError: h = N,
    immediate: g,
    resetOnExecute: T = !1,
    queryFn: p,
    queryKey: _
  } = e, m = (r ? R : C)(n), i = C(!1), t = C(!1), o = C(!1), s = R(), c = (u) => {
    t.value = u, i.value = !u;
  }, w = () => {
    T && (m.value = n);
  }, f = () => new Promise((u, A) => {
    j(i).toBe(!0).then(() => s.value ? A(s.value) : u(d));
  }), l = {
    then: (...u) => f().then(...u),
    catch: (...u) => f().catch(...u)
  };
  let v = 0;
  const y = (u) => {
    if (s.value = void 0, t.value)
      return l;
    if (p === void 0)
      return i.value = !0, l;
    w(), c(!0), v += 1;
    const A = v;
    return p(u).then((P) => {
      const O = P;
      m.value = O, a(O);
    }).catch((P) => {
      s.value = P, h(P);
    }).finally(() => {
      var P;
      (P = e.onFinish) == null || P.call(e), A === v && c(!1);
    }), l;
  };
  g && y();
  const d = {
    data: m,
    error: s,
    isFinished: i,
    isLoading: t,
    isAborted: o,
    isCanceled: o,
    execute: y
  };
  return {
    ...d,
    ...l
  };
}
const J = (e, n = {}, r) => {
  const { pagination: a = { page: 1, perPage: 20 }, filter: h = K } = n, g = G();
  W();
  const T = H({
    immediate: r,
    // queryKey: [filter, resource, pagination],
    queryFn: () => new Promise((m, i) => {
      g.getList(e, {
        pagination: a,
        filter: h
      }).then(({ data: t, total: o }) => ({
        data: t,
        total: o
      })).then(m).catch(i);
    }),
    initialData: {
      data: [],
      total: 0
    }
  }), p = b(() => T.data.value.data), _ = b(() => T.data.value.total);
  return {
    ...T,
    data: p,
    total: _
  };
};
export {
  J as useGetList
};
//# sourceMappingURL=useGetList.mjs.map
