var N = (e, n, s) => {
  if (n.length === 1 && n[0] === s) {
    let r = !1;
    try {
      const t = {};
      e(t) === t && (r = !0);
    } catch {
    }
    if (r) {
      let t;
      try {
        throw new Error();
      } catch (c) {
        ({ stack: t } = c);
      }
      console.warn(
        `The result function returned its own inputs without modification. e.g
\`createSelector([state => state.todos], todos => todos)\`
This could lead to inefficient memoization and unnecessary re-renders.
Ensure transformation logic is in the result function, and extraction logic is in the input selectors.`,
        { stack: t }
      );
    }
  }
}, x = (e, n, s) => {
  const { memoize: r, memoizeOptions: t } = n, { inputSelectorResults: c, inputSelectorResultsCopy: i } = e, o = r(() => ({}), ...t);
  if (!(o.apply(null, c) === o.apply(null, i))) {
    let a;
    try {
      throw new Error();
    } catch (u) {
      ({ stack: a } = u);
    }
    console.warn(
      `An input selector returned a different result when passed same arguments.
This means your output selector will likely run more frequently than intended.
Avoid returning a new reference inside your input selector, e.g.
\`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)\``,
      {
        arguments: s,
        firstInputs: c,
        secondInputs: i,
        stack: a
      }
    );
  }
}, A = {
  inputStabilityCheck: "once",
  identityFunctionCheck: "once"
};
function F(e, n = `expected a function, instead received ${typeof e}`) {
  if (typeof e != "function")
    throw new TypeError(n);
}
function D(e, n = `expected an object, instead received ${typeof e}`) {
  if (typeof e != "object")
    throw new TypeError(n);
}
function $(e, n = "expected all items to be functions, instead received the following types: ") {
  if (!e.every((s) => typeof s == "function")) {
    const s = e.map(
      (r) => typeof r == "function" ? `function ${r.name || "unnamed"}()` : typeof r
    ).join(", ");
    throw new TypeError(`${n}[${s}]`);
  }
}
var S = (e) => Array.isArray(e) ? e : [e];
function W(e) {
  const n = Array.isArray(e[0]) ? e[0] : e;
  return $(
    n,
    "createSelector expects all input-selectors to be functions, but received the following types: "
  ), n;
}
function E(e, n) {
  const s = [], { length: r } = e;
  for (let t = 0; t < r; t++)
    s.push(e[t].apply(null, n));
  return s;
}
var q = (e, n) => {
  const { identityFunctionCheck: s, inputStabilityCheck: r } = {
    ...A,
    ...n
  };
  return {
    identityFunctionCheck: {
      shouldRun: s === "always" || s === "once" && e,
      run: N
    },
    inputStabilityCheck: {
      shouldRun: r === "always" || r === "once" && e,
      run: x
    }
  };
}, V = class {
  constructor(e) {
    this.value = e;
  }
  deref() {
    return this.value;
  }
}, K = typeof WeakRef < "u" ? WeakRef : V, P = 0, I = 1;
function v() {
  return {
    s: P,
    v: void 0,
    o: null,
    p: null
  };
}
function z(e, n = {}) {
  let s = v();
  const { resultEqualityCheck: r } = n;
  let t, c = 0;
  function i() {
    var h;
    let o = s;
    const { length: y } = arguments;
    for (let p = 0, m = y; p < m; p++) {
      const d = arguments[p];
      if (typeof d == "function" || typeof d == "object" && d !== null) {
        let l = o.o;
        l === null && (o.o = l = /* @__PURE__ */ new WeakMap());
        const f = l.get(d);
        f === void 0 ? (o = v(), l.set(d, o)) : o = f;
      } else {
        let l = o.p;
        l === null && (o.p = l = /* @__PURE__ */ new Map());
        const f = l.get(d);
        f === void 0 ? (o = v(), l.set(d, o)) : o = f;
      }
    }
    const a = o;
    let u;
    if (o.s === I)
      u = o.v;
    else if (u = e.apply(null, arguments), c++, r) {
      const p = ((h = t == null ? void 0 : t.deref) == null ? void 0 : h.call(t)) ?? t;
      p != null && r(p, u) && (u = p, c !== 0 && c--), t = typeof u == "object" && u !== null || typeof u == "function" ? new K(u) : u;
    }
    return a.s = I, a.v = u, u;
  }
  return i.clearCache = () => {
    s = v(), i.resetResultsCount();
  }, i.resultsCount = () => c, i.resetResultsCount = () => {
    c = 0;
  }, i;
}
function U(e, ...n) {
  const s = typeof e == "function" ? {
    memoize: e,
    memoizeOptions: n
  } : e, r = (...t) => {
    let c = 0, i = 0, o, y = {}, a = t.pop();
    typeof a == "object" && (y = a, a = t.pop()), F(
      a,
      `createSelector expects an output function after the inputs, but received: [${typeof a}]`
    );
    const u = {
      ...s,
      ...y
    }, {
      memoize: h,
      memoizeOptions: p = [],
      argsMemoize: m = z,
      argsMemoizeOptions: d = [],
      devModeChecks: l = {}
    } = u, f = S(p), M = S(d), g = W(t), R = h(function() {
      return c++, a.apply(
        null,
        arguments
      );
    }, ...f);
    let w = !0;
    const O = m(function() {
      i++;
      const C = E(
        g,
        arguments
      );
      if (o = R.apply(null, C), process.env.NODE_ENV !== "production") {
        const { identityFunctionCheck: k, inputStabilityCheck: b } = q(w, l);
        if (k.shouldRun && k.run(
          a,
          C,
          o
        ), b.shouldRun) {
          const j = E(
            g,
            arguments
          );
          b.run(
            { inputSelectorResults: C, inputSelectorResultsCopy: j },
            { memoize: h, memoizeOptions: f },
            arguments
          );
        }
        w && (w = !1);
      }
      return o;
    }, ...M);
    return Object.assign(O, {
      resultFunc: a,
      memoizedResultFunc: R,
      dependencies: g,
      dependencyRecomputations: () => i,
      resetDependencyRecomputations: () => {
        i = 0;
      },
      lastResult: () => o,
      recomputations: () => c,
      resetRecomputations: () => {
        c = 0;
      },
      memoize: h,
      argsMemoize: m
    });
  };
  return Object.assign(r, {
    withTypes: () => r
  }), r;
}
var _ = /* @__PURE__ */ U(z), B = Object.assign(
  (e, n = _) => {
    D(
      e,
      `createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof e}`
    );
    const s = Object.keys(e), r = s.map(
      (c) => e[c]
    );
    return n(
      r,
      (...c) => c.reduce((i, o, y) => (i[s[y]] = o, i), {})
    );
  },
  { withTypes: () => B }
);
export {
  _ as createSelector,
  U as createSelectorCreator,
  B as createStructuredSelector,
  z as weakMapMemoize
};
//# sourceMappingURL=reselect.js.map
