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

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

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

// src/test/spy.ts
var I = globalThis.__STORYBOOK_TEST_SPY_LISTENERS__ || /* @__PURE__ */ new Set();
globalThis.__STORYBOOK_TEST_SPY_LISTENERS__ = I;
function H(t) {
  return I.add(t), () => void I.delete(t);
}
n(H, "onMockCall");
var J = /* @__PURE__ */ n((...t) => {
  let e = E(...t);
  return F(e);
}, "spyOn");
function Q(t) {
  let e = t ? P(t) : P();
  return F(e);
}
n(Q, "fn");
function F(t) {
  let e = D(t), r = e.mockImplementation.bind(null);
  return e.mockImplementation = (s) => D(r(s)), e;
}
n(F, "reactiveMock");
function D(t) {
  let e = M(t), r = e.impl;
  return e.willCall(function(...s) {
    return I.forEach((l) => l(t, s)), r?.apply(this, s);
  }), t;
}
n(D, "listenWhenCalled");
function X() {
  v.forEach((t) => t.mockClear());
}
n(X, "clearAllMocks");
function Z() {
  v.forEach((t) => t.mockReset());
}
n(Z, "resetAllMocks");
function ee() {
  v.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,
  v as mocks,
  H as onMockCall,
  Z as resetAllMocks,
  ee as restoreAllMocks,
  J as spyOn
};
