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 g(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: l = !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: l,
          immediate: !0
        }
      );
    })];
    return i != null && h.push(
      F(i, p).then(() => g(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: l = "sync", deep: i = !1, timeout: p, throwOnTimeout: c } = u ?? {};
    let a = null;
    const v = [new Promise((f) => {
      a = B(
        [e, t],
        ([s, T]) => {
          n !== (s === T) && (a == null || a(), f(s));
        },
        {
          flush: l,
          deep: i,
          immediate: !0
        }
      );
    })];
    return p != null && v.push(
      F(p, c).then(() => g(e)).finally(() => (a == null || a(), g(e)))
    ), Promise.race(v);
  }
  function m(t) {
    return r((u) => !!u, t);
  }
  function w(t) {
    return o(null, t);
  }
  function O(t) {
    return o(void 0, t);
  }
  function D(t) {
    return r(Number.isNaN, t);
  }
  function b(t, u) {
    return r((l) => {
      const i = Array.from(l);
      return i.includes(t) || i.includes(g(t));
    }, u);
  }
  function P(t) {
    return d(1, t);
  }
  function d(t = 1, u) {
    let l = -1;
    return r(() => (l += 1, l >= t), u);
  }
  return Array.isArray(g(e)) ? {
    toMatch: r,
    toContains: b,
    changed: P,
    changedTimes: d,
    get not() {
      return E(e, !n);
    }
  } : {
    toMatch: r,
    toBe: o,
    toBeTruthy: m,
    toBeNull: w,
    toBeNaN: D,
    toBeUndefined: O,
    changed: P,
    changedTimes: d,
    get not() {
      return E(e, !n);
    }
  };
}
function q(e) {
  return E(e);
}
const I = Symbol("DATA_PROVIDER_CONTEXT"), U = () => j(I, L);
function V(e) {
  const {
    initialData: n,
    shallow: r,
    onSuccess: o = _,
    onError: m = _,
    immediate: w,
    resetOnExecute: O = !1,
    queryFn: D,
    queryKey: b
  } = e, P = (r ? R : A)(n), d = A(!1), t = A(!1), u = A(!1), l = R(), i = (s) => {
    t.value = s, d.value = !s;
  }, p = () => {
    O && (P.value = n);
  }, c = () => new Promise((s, T) => {
    q(d).toBe(!0).then(() => l.value ? T(l.value) : s(f));
  }), a = {
    then: (...s) => c().then(...s),
    catch: (...s) => c().catch(...s)
  };
  let h = 0;
  const v = (s) => {
    if (l.value = void 0, t.value)
      return a;
    if (D === void 0)
      return d.value = !0, a;
    p(), i(!0), h += 1;
    const T = h;
    return D(s).then((y) => {
      const x = y;
      P.value = x, o(x);
    }).catch((y) => {
      l.value = y, m(y);
    }).finally(() => {
      var y;
      (y = e.onFinish) == null || y.call(e), T === h && i(!1);
    }), a;
  };
  w && v();
  const f = {
    data: P,
    error: l,
    isFinished: d,
    isLoading: t,
    isAborted: u,
    isCanceled: u,
    execute: v
  };
  return {
    ...f,
    ...a
  };
}
const G = (e, n = !1) => {
  const { deleteOne: r } = U(), o = V({
    immediate: n,
    queryFn: (w) => r(e, w)
  }), m = o.execute;
  return { ...o, sendDelete: m };
};
export {
  G as useDelete
};
//# sourceMappingURL=useDelete.mjs.map
