var D = Object.defineProperty;
var n = (t, e) => D(t, "name", { value: e, configurable: !0 });

// ../node_modules/tinyspy/dist/index.js
function v(t, e) {
  if (!t)
    throw new Error(e);
}
n(v, "d");
function g(t, e) {
  return typeof e === t;
}
n(g, "y");
function F(t) {
  return t instanceof Promise;
}
n(F, "w");
function R(t, e, r) {
  Object.defineProperty(t, e, r);
}
n(R, "f");
function M(t, e, r) {
  Object.defineProperty(t, e, { value: r });
}
n(M, "l");
var h = Symbol.for("tinyspy:spy"), L = /* @__PURE__ */ new Set(), Y = /* @__PURE__ */ n((t) => {
  t.called = !1, t.callCount = 0, t.calls = [], t.results = [], t.resolves = [], t.next = [];
}, "P"), N = /* @__PURE__ */ n((t) => (R(t, h, { value: { reset: /* @__PURE__ */ n(() => Y(t[h]), "reset") } }), t[h]), "K"), T = /* @__PURE__ */ n(
(t) => t[h] || N(t), "T");
function K(t) {
  v(
    g("function", t) || g("undefined", t),
    "cannot spy on a non-function value"
  );
  let e = /* @__PURE__ */ n(function(...l) {
    let s = T(e);
    s.called = !0, s.callCount++, s.calls.push(l);
    let p = s.next.shift();
    if (p) {
      s.results.push(p);
      let [i, f] = p;
      if (i === "ok")
        return f;
      throw f;
    }
    let c, y = "ok", a = s.results.length;
    if (s.impl)
      try {
        new.target ? c = Reflect.construct(s.impl, l, new.target) : c = s.impl.apply(this, l), y = "ok";
      } catch (i) {
        throw c = i, y = "error", s.results.push([y, i]), i;
      }
    let m = [y, c];
    return F(c) && c.then(
      (i) => s.resolves[a] = ["ok", i],
      (i) => s.resolves[a] = ["error", i]
    ), s.results.push(m), c;
  }, "t");
  M(e, "_isMockFunction", !0), M(e, "length", t ? t.length : 0), M(e, "name", t && t.name || "spy");
  let r = T(e);
  return r.reset(), r.impl = t, e;
}
n(K, "m");
var P = /* @__PURE__ */ n((t, e) => Object.getOwnPropertyDescriptor(t, e), "k"), C = /* @__PURE__ */ n((t, e) => {
  e != null && typeof e == "function" && e.prototype != null && Object.setPrototypeOf(t.prototype, e.prototype);
}, "O");
function S(t, e, r) {
  v(
    !g("undefined", t),
    "spyOn could not find an object to spy upon"
  ), v(
    g("object", t) || g("function", t),
    "cannot spyOn on a primitive value"
  );
  let [l, s] = (() => {
    if (!g("object", e))
      return [e, "value"];
    if ("getter" in e && "setter" in e)
      throw new Error("cannot spy on both getter and setter");
    if ("getter" in e)
      return [e.getter, "get"];
    if ("setter" in e)
      return [e.setter, "set"];
    throw new Error("specify getter or setter to spy on");
  })(), p = P(t, l), c = Object.getPrototypeOf(t), y = c && P(c, l), a = p || y;
  v(
    a || l in t,
    `${String(l)} does not exist`
  );
  let m = !1;
  s === "value" && a && !a.value && a.get && (s = "get", m = !0, r = a.get());
  let i;
  a ? i = a[s] : s !== "value" ? i = /* @__PURE__ */ n(() => t[l], "o") : i = t[l];
  let f = /* @__PURE__ */ n((k) => {
    let { value: b, ...d } = a || {
      configurable: !0,
      writable: !0
    };
    s !== "value" && delete d.writable, d[s] = k, R(t, l, d);
  }, "g"), I = /* @__PURE__ */ n(() => a ? R(t, l, a) : f(i), "b");
  r || (r = i);
  let o = K(r);
  s === "value" && C(o, i);
  let u = o[h];
  return M(u, "restore", I), M(u, "getOriginal", () => m ? i() : i), M(u, "willCall", (k) => (u.impl = k, o)), f(
    m ? () => (C(o, r), o) : o
  ), L.add(o), o;
}
n(S, "C");

// ../node_modules/@vitest/spy/dist/index.js
var x = /* @__PURE__ */ new Set();
function B(t) {
  return typeof t == "function" && "_isMockFunction" in t && t._isMockFunction;
}
n(B, "isMockFunction");
function E(t, e, r) {
  let s = r ? { [{
    get: "getter",
    set: "setter"
  }[r]]: e } : e, p = S(t, s);
  return j(p);
}
n(E, "spyOn");
var U = 0;
function j(t) {
  let e = t, r, l = [], s = [], p = [], c = T(t), y = {
    get calls() {
      return c.calls;
    },
    get contexts() {
      return s;
    },
    get instances() {
      return l;
    },
    get invocationCallOrder() {
      return p;
    },
    get results() {
      return c.results.map(([o, u]) => ({ type: o === "error" ? "throw" : "return", value: u }));
    },
    get settledResults() {
      return c.resolves.map(([o, u]) => ({ type: o === "error" ? "rejected" : "fulfilled", value: u }));
    },
    get lastCall() {
      return c.calls[c.calls.length - 1];
    }
  }, a = [], m = !1;
  function i(...o) {
    return l.push(this), s.push(this), p.push(++U), (m ? r : a.shift() || r || c.getOriginal() || (() => {
    })).apply(this, o);
  }
  n(i, "mockCall");
  let f = e.name;
  e.getMockName = () => f || "vi.fn()", e.mockName = (o) => (f = o, e), e.mockClear = () => (c.reset(), l = [], s = [], p = [], e), e.mockReset =
  () => (e.mockClear(), r = void 0, a = [], e), e.mockRestore = () => (e.mockReset(), c.restore(), e), e.getMockImplementation = () => m ? r :
  a.at(0) || r, e.mockImplementation = (o) => (r = o, c.willCall(i), e), e.mockImplementationOnce = (o) => (a.push(o), e);
  function I(o, u) {
    let k = r;
    r = o, c.willCall(i), m = !0;
    let b = /* @__PURE__ */ n(() => {
      r = k, m = !1;
    }, "reset"), d = u();
    return d instanceof Promise ? d.then(() => (b(), e)) : (b(), e);
  }
  return n(I, "withImplementation"), e.withImplementation = I, e.mockReturnThis = () => e.mockImplementation(function() {
    return this;
  }), e.mockReturnValue = (o) => e.mockImplementation(() => o), e.mockReturnValueOnce = (o) => e.mockImplementationOnce(() => o), e.mockResolvedValue =
  (o) => e.mockImplementation(() => Promise.resolve(o)), e.mockResolvedValueOnce = (o) => e.mockImplementationOnce(() => Promise.resolve(o)),
  e.mockRejectedValue = (o) => e.mockImplementation(() => Promise.reject(o)), e.mockRejectedValueOnce = (o) => e.mockImplementationOnce(() => Promise.
  reject(o)), Object.defineProperty(e, "mock", {
    get: /* @__PURE__ */ n(() => y, "get")
  }), c.willCall(i), x.add(e), e;
}
n(j, "enhanceSpy");
function w(t) {
  let e = j(S({
    spy: t || function() {
    }
  }, "spy"));
  return t && e.mockImplementation(t), e;
}
n(w, "fn");

// src/test/spy.ts
var O = globalThis.__STORYBOOK_TEST_SPY_LISTENERS__ || /* @__PURE__ */ new Set();
globalThis.__STORYBOOK_TEST_SPY_LISTENERS__ = O;
function H(t) {
  return O.add(t), () => void O.delete(t);
}
n(H, "onMockCall");
var J = /* @__PURE__ */ n((...t) => {
  let e = E(...t);
  return V(e);
}, "spyOn");
function Q(t) {
  let e = t ? w(t) : w();
  return V(e);
}
n(Q, "fn");
function V(t) {
  let e = A(t), r = e.mockImplementation.bind(null);
  return e.mockImplementation = (l) => A(r(l)), e;
}
n(V, "reactiveMock");
function A(t) {
  let e = T(t), r = e.impl;
  return e.willCall(function(...l) {
    return O.forEach((s) => s(t, l)), r?.apply(this, l);
  }), t;
}
n(A, "listenWhenCalled");
function X() {
  x.forEach((t) => t.mockClear());
}
n(X, "clearAllMocks");
function Z() {
  x.forEach((t) => t.mockReset());
}
n(Z, "resetAllMocks");
function ee() {
  x.forEach((t) => t.mockRestore());
}
n(ee, "restoreAllMocks");
function te(t, e = {}) {
  return t;
}
n(te, "mocked");
export {
  X as clearAllMocks,
  Q as fn,
  B as isMockFunction,
  te as mocked,
  x as mocks,
  H as onMockCall,
  Z as resetAllMocks,
  ee as restoreAllMocks,
  J as spyOn
};
