import { getCurrentScope as y, onScopeDispose as x, unref as F, toRef as P, readonly as R, customRef as b, ref as S } from "vue";
function C(e) {
  return y() ? (x(e), !0) : !1;
}
function w(e) {
  return typeof e == "function" ? e() : F(e);
}
const N = typeof window < "u", f = () => {
}, I = /* @__PURE__ */ O();
function O() {
  var e;
  return N && ((e = window == null ? void 0 : window.navigator) == null ? void 0 : e.userAgent) && /* @__PURE__ */ /iP(ad|hone|od)/.test(window.navigator.userAgent);
}
function v(e, n) {
  function r(...t) {
    return new Promise((i, o) => {
      Promise.resolve(e(() => n.apply(this, t), { fn: n, thisArg: this, args: t })).then(i).catch(o);
    });
  }
  return r;
}
function g(e, n = {}) {
  let r, t, i = f;
  const o = (u) => {
    clearTimeout(u), i(), i = f;
  };
  return (u) => {
    const l = w(e), s = w(n.maxWait);
    return r && o(r), l <= 0 || s !== void 0 && s <= 0 ? (t && (o(t), t = null), Promise.resolve(u())) : new Promise((a, p) => {
      i = n.rejectOnCancel ? p : a, s && !t && (t = setTimeout(() => {
        r && o(r), t = null, a(u());
      }, s)), r = setTimeout(() => {
        t && o(t), t = null, a(u());
      }, l);
    });
  };
}
function j(e, n = !0, r = !0, t = !1) {
  let i = 0, o, c = !0, u = f, l;
  const s = () => {
    o && (clearTimeout(o), o = void 0, u(), u = f);
  };
  return (p) => {
    const m = w(e), h = Date.now() - i, d = () => l = p();
    return s(), m <= 0 ? (i = Date.now(), d()) : (h > m && (r || !c) ? (i = Date.now(), d()) : n && (l = new Promise((T, D) => {
      u = t ? D : T, o = setTimeout(() => {
        i = Date.now(), c = !0, T(d()), s();
      }, Math.max(0, m - h));
    })), !r && !o && (o = setTimeout(() => c = !0, m)), c = !1, l);
  };
}
function W(e, n) {
  var r;
  if (typeof e == "number")
    return e + n;
  const t = ((r = e.match(/^-?[0-9]+\.?[0-9]*/)) == null ? void 0 : r[0]) || "", i = e.slice(t.length), o = Number.parseFloat(t) + n;
  return Number.isNaN(o) ? e : o + i;
}
function _(...e) {
  if (e.length !== 1)
    return P(...e);
  const n = e[0];
  return typeof n == "function" ? R(b(() => ({ get: n, set: f }))) : S(n);
}
function V(e, n = 200, r = {}) {
  return v(
    g(n, r),
    e
  );
}
function E(e, n = 200, r = !1, t = !0, i = !1) {
  return v(
    j(n, r, t, i),
    e
  );
}
export {
  v as createFilterWrapper,
  g as debounceFilter,
  W as increaseWithUnit,
  N as isClient,
  I as isIOS,
  f as noop,
  j as throttleFilter,
  _ as toRef,
  w as toValue,
  C as tryOnScopeDispose,
  V as useDebounceFn,
  E as useThrottleFn
};
