import { getCurrentInstance as M, inject as N, unref as S, watch as B, isRef as k, shallowRef as R, ref as A } from "vue";
const L = {
  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
}, C = /* @__PURE__ */ new WeakMap(), j = (...e) => {
  var n;
  const r = e[0], o = (n = M()) == null ? void 0 : n.proxy;
  if (o == null)
    throw new Error("injectLocal must be called in setup");
  return C.has(o) && r in C.get(o) ? C.get(o)[r] : N(...e);
};
function T(e) {
  return typeof e == "function" ? e() : S(e);
}
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const _ = () => {
};
function F(e, n = !1, r = "Timeout") {
  return new Promise((o, m) => {
    setTimeout(n ? () => m(r) : o, e);
  });
}
function E(e, n = !1) {
  function r(t, { flush: u = "sync", deep: a = !1, timeout: i, throwOnTimeout: p } = {}) {
    let c = null;
    const h = [new Promise((v) => {
      c = B(
        e,
        (f) => {
          t(f) !== n && (c == null || c(), v(f));
        },
        {
          flush: u,
          deep: a,
          immediate: !0
        }
      );
    })];
    return i != null && h.push(
      F(i, p).then(() => T(e)).finally(() => c == null ? void 0 : c())
    ), Promise.race(h);
  }
  function o(t, u) {
    if (!k(t))
      return r((f) => f === t, u);
    const { flush: a = "sync", deep: i = !1, timeout: p, throwOnTimeout: c } = u ?? {};
    let l = null;
    const v = [new Promise((f) => {
      l = B(
        [e, t],
        ([s, g]) => {
          n !== (s === g) && (l == null || l(), f(s));
        },
        {
          flush: a,
          deep: i,
          immediate: !0
        }
      );
    })];
    return p != null && v.push(
      F(p, c).then(() => T(e)).finally(() => (l == null || l(), T(e)))
    ), Promise.race(v);
  }
  function m(t) {
    return r((u) => !!u, t);
  }
  function w(t) {
    return o(null, t);
  }
  function D(t) {
    return o(void 0, t);
  }
  function O(t) {
    return r(Number.isNaN, t);
  }
  function b(t, u) {
    return r((a) => {
      const i = Array.from(a);
      return i.includes(t) || i.includes(T(t));
    }, u);
  }
  function P(t) {
    return d(1, t);
  }
  function d(t = 1, u) {
    let a = -1;
    return r(() => (a += 1, a >= t), u);
  }
  return Array.isArray(T(e)) ? {
    toMatch: r,
    toContains: b,
    changed: P,
    changedTimes: d,
    get not() {
      return E(e, !n);
    }
  } : {
    toMatch: r,
    toBe: o,
    toBeTruthy: m,
    toBeNull: w,
    toBeNaN: O,
    toBeUndefined: D,
    changed: P,
    changedTimes: d,
    get not() {
      return E(e, !n);
    }
  };
}
function q(e) {
  return E(e);
}
const G = Symbol("DATA_PROVIDER_CONTEXT"), I = () => j(G, L);
function U(e) {
  const {
    initialData: n,
    shallow: r,
    onSuccess: o = _,
    onError: m = _,
    immediate: w,
    resetOnExecute: D = !1,
    queryFn: O,
    queryKey: b
  } = e, P = (r ? R : A)(n), d = A(!1), t = A(!1), u = A(!1), a = R(), i = (s) => {
    t.value = s, d.value = !s;
  }, p = () => {
    D && (P.value = n);
  }, c = () => new Promise((s, g) => {
    q(d).toBe(!0).then(() => a.value ? g(a.value) : s(f));
  }), l = {
    then: (...s) => c().then(...s),
    catch: (...s) => c().catch(...s)
  };
  let h = 0;
  const v = (s) => {
    if (a.value = void 0, t.value)
      return l;
    if (O === void 0)
      return d.value = !0, l;
    p(), i(!0), h += 1;
    const g = h;
    return O(s).then((y) => {
      const x = y;
      P.value = x, o(x);
    }).catch((y) => {
      a.value = y, m(y);
    }).finally(() => {
      var y;
      (y = e.onFinish) == null || y.call(e), g === h && i(!1);
    }), l;
  };
  w && v();
  const f = {
    data: P,
    error: a,
    isFinished: d,
    isLoading: t,
    isAborted: u,
    isCanceled: u,
    execute: v
  };
  return {
    ...f,
    ...l
  };
}
const W = (e, n = !1) => {
  const { getOne: r } = I(), o = U({
    immediate: n,
    queryFn: (w) => r(e, w)
  }), m = o.execute;
  return { ...o, getOneData: m };
};
export {
  W as useGetOne
};
//# sourceMappingURL=useGetOne.mjs.map
