import * as i from "react";
import { w as M } from "../../../../../../_virtual/with-selector.js";
function j(n) {
  n();
}
function T() {
  let n = null, o = null;
  return {
    clear() {
      n = null, o = null;
    },
    notify() {
      j(() => {
        let e = n;
        for (; e; )
          e.callback(), e = e.next;
      });
    },
    get() {
      const e = [];
      let t = n;
      for (; t; )
        e.push(t), t = t.next;
      return e;
    },
    subscribe(e) {
      let t = !0;
      const r = o = {
        callback: e,
        next: null,
        prev: o
      };
      return r.prev ? r.prev.next = r : n = r, function() {
        !t || n === null || (t = !1, r.next ? r.next.prev = r.prev : o = r.prev, r.prev ? r.prev.next = r.next : n = r.next);
      };
    }
  };
}
var R = {
  notify() {
  },
  get: () => []
};
function U(n, o) {
  let e, t = R, r = 0, s = !1;
  function f(x) {
    u();
    const m = t.subscribe(x);
    let y = !1;
    return () => {
      y || (y = !0, m(), b());
    };
  }
  function d() {
    t.notify();
  }
  function c() {
    a.onStateChange && a.onStateChange();
  }
  function p() {
    return s;
  }
  function u() {
    r++, e || (e = n.subscribe(c), t = T());
  }
  function b() {
    r--, e && r === 0 && (e(), e = void 0, t.clear(), t = R);
  }
  function S() {
    s || (s = !0, u());
  }
  function h() {
    s && (s = !1, b());
  }
  const a = {
    addNestedSub: f,
    notifyNestedSubs: d,
    handleChangeWrapper: c,
    isSubscribed: p,
    trySubscribe: S,
    tryUnsubscribe: h,
    getListeners: () => t
  };
  return a;
}
var _ = () => typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", H = /* @__PURE__ */ _(), I = () => typeof navigator < "u" && navigator.product === "ReactNative", P = /* @__PURE__ */ I(), z = () => H || P ? i.useLayoutEffect : i.useEffect, O = /* @__PURE__ */ z(), g = /* @__PURE__ */ Symbol.for("react-redux-context"), C = typeof globalThis < "u" ? globalThis : (
  /* fall back to a per-module scope (pre-8.1 behaviour) if `globalThis` is not available */
  {}
);
function Y() {
  if (!i.createContext) return {};
  const n = C[g] ?? (C[g] = /* @__PURE__ */ new Map());
  let o = n.get(i.createContext);
  return o || (o = i.createContext(
    null
  ), process.env.NODE_ENV !== "production" && (o.displayName = "ReactRedux"), n.set(i.createContext, o)), o;
}
var l = /* @__PURE__ */ Y();
function F(n) {
  const { children: o, context: e, serverState: t, store: r } = n, s = i.useMemo(() => {
    const c = U(r), p = {
      store: r,
      subscription: c,
      getServerState: t ? () => t : void 0
    };
    if (process.env.NODE_ENV === "production")
      return p;
    {
      const { identityFunctionCheck: u = "once", stabilityCheck: b = "once" } = n;
      return /* @__PURE__ */ Object.assign(p, {
        stabilityCheck: b,
        identityFunctionCheck: u
      });
    }
  }, [r, t]), f = i.useMemo(() => r.getState(), [r]);
  O(() => {
    const { subscription: c } = s;
    return c.onStateChange = c.notifyNestedSubs, c.trySubscribe(), f !== r.getState() && c.notifyNestedSubs(), () => {
      c.tryUnsubscribe(), c.onStateChange = void 0;
    };
  }, [s, f]);
  const d = e || l;
  return /* @__PURE__ */ i.createElement(d.Provider, { value: s }, o);
}
var J = F;
function E(n = l) {
  return function() {
    const e = i.useContext(n);
    if (process.env.NODE_ENV !== "production" && !e)
      throw new Error(
        "could not find react-redux context value; please ensure the component is wrapped in a <Provider>"
      );
    return e;
  };
}
var D = /* @__PURE__ */ E();
function V(n = l) {
  const o = n === l ? D : (
    // @ts-ignore
    E(n)
  ), e = () => {
    const { store: t } = o();
    return t;
  };
  return Object.assign(e, {
    withTypes: () => e
  }), e;
}
var W = /* @__PURE__ */ V();
function A(n = l) {
  const o = n === l ? W : V(n), e = () => o().dispatch;
  return Object.assign(e, {
    withTypes: () => e
  }), e;
}
var Q = /* @__PURE__ */ A(), B = (n, o) => n === o;
function q(n = l) {
  const o = n === l ? D : E(n), e = (t, r = {}) => {
    const { equalityFn: s = B } = typeof r == "function" ? { equalityFn: r } : r;
    if (process.env.NODE_ENV !== "production") {
      if (!t)
        throw new Error("You must pass a selector to useSelector");
      if (typeof t != "function")
        throw new Error("You must pass a function as a selector to useSelector");
      if (typeof s != "function")
        throw new Error(
          "You must pass a function as an equality function to useSelector"
        );
    }
    const f = o(), { store: d, subscription: c, getServerState: p } = f, u = i.useRef(!0), b = i.useCallback(
      {
        [t.name](h) {
          const a = t(h);
          if (process.env.NODE_ENV !== "production") {
            const { devModeChecks: x = {} } = typeof r == "function" ? {} : r, { identityFunctionCheck: m, stabilityCheck: y } = f, {
              identityFunctionCheck: k,
              stabilityCheck: N
            } = {
              stabilityCheck: y,
              identityFunctionCheck: m,
              ...x
            };
            if (N === "always" || N === "once" && u.current) {
              const v = t(h);
              if (!s(a, v)) {
                let w;
                try {
                  throw new Error();
                } catch (L) {
                  ({ stack: w } = L);
                }
                console.warn(
                  "Selector " + (t.name || "unknown") + ` returned a different result when called with the same parameters. This can lead to unnecessary rerenders.
Selectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization`,
                  {
                    state: h,
                    selected: a,
                    selected2: v,
                    stack: w
                  }
                );
              }
            }
            if ((k === "always" || k === "once" && u.current) && a === h) {
              let v;
              try {
                throw new Error();
              } catch (w) {
                ({ stack: v } = w);
              }
              console.warn(
                "Selector " + (t.name || "unknown") + ` returned the root state when called. This can lead to unnecessary rerenders.
Selectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.`,
                { stack: v }
              );
            }
            u.current && (u.current = !1);
          }
          return a;
        }
      }[t.name],
      [t]
    ), S = M.useSyncExternalStoreWithSelector(
      c.addNestedSub,
      d.getState,
      p || d.getState,
      b,
      s
    );
    return i.useDebugValue(S), S;
  };
  return Object.assign(e, {
    withTypes: () => e
  }), e;
}
var X = /* @__PURE__ */ q();
export {
  J as Provider,
  l as ReactReduxContext,
  A as createDispatchHook,
  q as createSelectorHook,
  V as createStoreHook,
  Q as useDispatch,
  X as useSelector,
  W as useStore
};
//# sourceMappingURL=react-redux.js.map
