var F = (e, n, t) => {
  if (n.length === 1 && n[0] === t) {
    let r = !1;
    try {
      const s = {};
      e(s) === s && (r = !0);
    } catch {
    }
    if (r) {
      let s;
      try {
        throw new Error();
      } catch (c) {
        ({ stack: s } = 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: s }
      );
    }
  }
}, x = (e, n, t) => {
  const { memoize: r, memoizeOptions: s } = n, { inputSelectorResults: c, inputSelectorResultsCopy: l } = e, o = r(() => ({}), ...s);
  if (!(o.apply(null, c) === o.apply(null, l))) {
    let u;
    try {
      throw new Error();
    } catch (i) {
      ({ stack: u } = i);
    }
    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: t,
        firstInputs: c,
        secondInputs: l,
        stack: u
      }
    );
  }
}, A = {
  inputStabilityCheck: "once",
  identityFunctionCheck: "once"
}, v = /* @__PURE__ */ Symbol("NOT_FOUND");
function D(e, n = `expected a function, instead received ${typeof e}`) {
  if (typeof e != "function")
    throw new TypeError(n);
}
function q(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((t) => typeof t == "function")) {
    const t = e.map(
      (r) => typeof r == "function" ? `function ${r.name || "unnamed"}()` : typeof r
    ).join(", ");
    throw new TypeError(`${n}[${t}]`);
  }
}
var E = (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 I(e, n) {
  const t = [], { length: r } = e;
  for (let s = 0; s < r; s++)
    t.push(e[s].apply(null, n));
  return t;
}
var U = (e, n) => {
  const { identityFunctionCheck: t, inputStabilityCheck: r } = {
    ...A,
    ...n
  };
  return {
    identityFunctionCheck: {
      shouldRun: t === "always" || t === "once" && e,
      run: F
    },
    inputStabilityCheck: {
      shouldRun: r === "always" || r === "once" && e,
      run: x
    }
  };
};
function _(e) {
  let n;
  return {
    get(t) {
      return n && e(n.key, t) ? n.value : v;
    },
    put(t, r) {
      n = { key: t, value: r };
    },
    getEntries() {
      return n ? [n] : [];
    },
    clear() {
      n = void 0;
    }
  };
}
function K(e, n) {
  let t = [];
  function r(o) {
    const a = t.findIndex((u) => n(o, u.key));
    if (a > -1) {
      const u = t[a];
      return a > 0 && (t.splice(a, 1), t.unshift(u)), u.value;
    }
    return v;
  }
  function s(o, a) {
    r(o) === v && (t.unshift({ key: o, value: a }), t.length > e && t.pop());
  }
  function c() {
    return t;
  }
  function l() {
    t = [];
  }
  return { get: r, put: s, getEntries: c, clear: l };
}
var V = (e, n) => e === n;
function L(e) {
  return function(t, r) {
    if (t === null || r === null || t.length !== r.length)
      return !1;
    const { length: s } = t;
    for (let c = 0; c < s; c++)
      if (!e(t[c], r[c]))
        return !1;
    return !0;
  };
}
function X(e, n) {
  const t = typeof n == "object" ? n : { equalityCheck: n }, {
    equalityCheck: r = V,
    maxSize: s = 1,
    resultEqualityCheck: c
  } = t, l = L(r);
  let o = 0;
  const a = s <= 1 ? _(l) : K(s, l);
  function u() {
    let i = a.get(arguments);
    if (i === v) {
      if (i = e.apply(null, arguments), o++, c) {
        const p = a.getEntries().find(
          (m) => c(m.value, i)
        );
        p && (i = p.value, o !== 0 && o--);
      }
      a.put(arguments, i);
    }
    return i;
  }
  return u.clearCache = () => {
    a.clear(), u.resetResultsCount();
  }, u.resultsCount = () => o, u.resetResultsCount = () => {
    o = 0;
  }, u;
}
var P = class {
  constructor(e) {
    this.value = e;
  }
  deref() {
    return this.value;
  }
}, B = typeof WeakRef < "u" ? WeakRef : P, G = 0, z = 1;
function g() {
  return {
    s: G,
    v: void 0,
    o: null,
    p: null
  };
}
function N(e, n = {}) {
  let t = g();
  const { resultEqualityCheck: r } = n;
  let s, c = 0;
  function l() {
    var h;
    let o = t;
    const { length: a } = arguments;
    for (let p = 0, m = a; p < m; p++) {
      const d = arguments[p];
      if (typeof d == "function" || typeof d == "object" && d !== null) {
        let f = o.o;
        f === null && (o.o = f = /* @__PURE__ */ new WeakMap());
        const y = f.get(d);
        y === void 0 ? (o = g(), f.set(d, o)) : o = y;
      } else {
        let f = o.p;
        f === null && (o.p = f = /* @__PURE__ */ new Map());
        const y = f.get(d);
        y === void 0 ? (o = g(), f.set(d, o)) : o = y;
      }
    }
    const u = o;
    let i;
    if (o.s === z)
      i = o.v;
    else if (i = e.apply(null, arguments), c++, r) {
      const p = ((h = s == null ? void 0 : s.deref) == null ? void 0 : h.call(s)) ?? s;
      p != null && r(p, i) && (i = p, c !== 0 && c--), s = typeof i == "object" && i !== null || typeof i == "function" ? new B(i) : i;
    }
    return u.s = z, u.v = i, i;
  }
  return l.clearCache = () => {
    t = g(), l.resetResultsCount();
  }, l.resultsCount = () => c, l.resetResultsCount = () => {
    c = 0;
  }, l;
}
function H(e, ...n) {
  const t = typeof e == "function" ? {
    memoize: e,
    memoizeOptions: n
  } : e, r = (...s) => {
    let c = 0, l = 0, o, a = {}, u = s.pop();
    typeof u == "object" && (a = u, u = s.pop()), D(
      u,
      `createSelector expects an output function after the inputs, but received: [${typeof u}]`
    );
    const i = {
      ...t,
      ...a
    }, {
      memoize: h,
      memoizeOptions: p = [],
      argsMemoize: m = N,
      argsMemoizeOptions: d = [],
      devModeChecks: f = {}
    } = i, y = E(p), T = E(d), C = W(s), R = h(function() {
      return c++, u.apply(
        null,
        arguments
      );
    }, ...y);
    let w = !0;
    const M = m(function() {
      l++;
      const k = I(
        C,
        arguments
      );
      if (o = R.apply(null, k), process.env.NODE_ENV !== "production") {
        const { identityFunctionCheck: S, inputStabilityCheck: b } = U(w, f);
        if (S.shouldRun && S.run(
          u,
          k,
          o
        ), b.shouldRun) {
          const j = I(
            C,
            arguments
          );
          b.run(
            { inputSelectorResults: k, inputSelectorResultsCopy: j },
            { memoize: h, memoizeOptions: y },
            arguments
          );
        }
        w && (w = !1);
      }
      return o;
    }, ...T);
    return Object.assign(M, {
      resultFunc: u,
      memoizedResultFunc: R,
      dependencies: C,
      dependencyRecomputations: () => l,
      resetDependencyRecomputations: () => {
        l = 0;
      },
      lastResult: () => o,
      recomputations: () => c,
      resetRecomputations: () => {
        c = 0;
      },
      memoize: h,
      argsMemoize: m
    });
  };
  return Object.assign(r, {
    withTypes: () => r
  }), r;
}
var J = /* @__PURE__ */ H(N), Q = Object.assign(
  (e, n = J) => {
    q(
      e,
      `createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof e}`
    );
    const t = Object.keys(e), r = t.map(
      (c) => e[c]
    );
    return n(
      r,
      (...c) => c.reduce((l, o, a) => (l[t[a]] = o, l), {})
    );
  },
  { withTypes: () => Q }
);
export {
  J as createSelector,
  H as createSelectorCreator,
  Q as createStructuredSelector,
  X as lruMemoize,
  V as referenceEqualityCheck,
  N as weakMapMemoize
};
