import { faker as i } from "@faker-js/faker";
const a = 20, y = async (e, c, t, l) => {
  if (e.delay) {
    e.showLog && console.log("genMock pause", e.delay);
    const { sleep: o } = await import("../utils/system.js");
    let s = o(e.delay);
    l && (s = Promise.race([
      s,
      // обработчик отмены
      new Promise((n, d) => {
        l.addEventListener("abort", () => {
          d(new DOMException("The operation was aborted from API mocker.", "AbortError"));
        });
      })
    ])), await s;
  }
  const r = {
    result: g(e, c, t),
    errors: void 0,
    nextOffset: void 0,
    total: void 0
  };
  if (delete r.errors, delete r.nextOffset, delete r.total, Array.isArray(r.result) && e.total && t && t.limit) {
    e.useFilter && (r.result = r.result.filter((s) => e.useFilter?.(s, t)));
    const o = t.offset ?? 0;
    r.result.length > t.limit + o && (r.nextOffset = t.limit + o, r.total = e.total), r.result = r.result.slice(o, o + t.limit);
  }
  return e.showLog && console.log("genMock complete", r), r;
}, g = (e, c, t) => {
  let l = e.seed ?? 0;
  if (l === -1 && (l = Math.random()), e.result instanceof Function)
    return i.seed(l), f(e.result, 0, c, t);
  if (Array.isArray(e.result)) {
    const r = e.result[0], o = [], s = e.total ?? t?.limit ?? a;
    for (let n = 0; n < s; n++)
      o.push(u(r, n, l, c, t));
    return o;
  }
  return u(e.result, 0, l, c, t);
}, u = (e, c, t, l, r) => {
  const o = {};
  for (const s in e) {
    const n = e[s];
    l && !l.includes(s) || (i.seed(t + c), o[s] = f(n, c, l, r));
  }
  return o;
}, f = (e, c = 0, t, l) => e(c, t, l);
export {
  u as genMockItem,
  y as genMockResponse,
  g as genMockResult,
  f as genMockValue
};
//# sourceMappingURL=index-DkQWJkMc.es.js.map
