import e from"../../../@babel/runtime/helpers/esm/extends.js";import t from"../../../@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js";import r from"../../../hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js";import o,{useMemo as n,useContext as i,useReducer as a,useRef as c}from"react";import"../../../react-is/index.js";import u from"../utils/Subscription.js";import{useIsomorphicLayoutEffect as s}from"../utils/useIsomorphicLayoutEffect.js";import{ReactReduxContext as d}from"./Context.js";import{r as p}from"../../../../_virtual/index3.js_commonjs-module";var m=[],f=[null,null];function l(e,t){var r=e[1];return[t.payload,r+1]}function v(e,t,r){s((function(){return e.apply(void 0,t)}),r)}function h(e,t,r,o,n,i,a){e.current=o,t.current=n,r.current=!1,i.current&&(i.current=null,a())}function y(e,t,r,o,n,i,a,c,u,s){if(e){var d=!1,p=null,m=function(){if(!d){var e,r,m=t.getState();try{e=o(m,n.current)}catch(e){r=e,p=e}r||(p=null),e===i.current?a.current||u():(i.current=e,c.current=e,a.current=!0,s({type:"STORE_UPDATED",payload:{error:r}}))}};r.onStateChange=m,r.trySubscribe(),m();return function(){if(d=!0,r.tryUnsubscribe(),r.onStateChange=null,p)throw p}}}var x=function(){return[null,0]};function C(s,C){void 0===C&&(C={});var w=C,R=w.getDisplayName,E=void 0===R?function(e){return"ConnectAdvanced("+e+")"}:R,N=w.methodName,b=void 0===N?"connectAdvanced":N,g=w.renderCountProp,S=void 0===g?void 0:g,j=w.shouldHandleStateChanges,P=void 0===j||j,D=w.storeKey,T=void 0===D?"store":D,_=w.withRef,B=void 0!==_&&_,O=w.forwardRef,K=void 0!==O&&O,V=w.context,W=void 0===V?d:V,A=t(w,["getDisplayName","methodName","renderCountProp","shouldHandleStateChanges","storeKey","withRef","forwardRef","context"]);if("production"!==process.env.NODE_ENV){if(void 0!==S)throw new Error("renderCountProp is removed. render counting is built into the latest React Dev Tools profiling extension");if(B)throw new Error("withRef is removed. To access the wrapped instance, use a ref on the connected component");if("store"!==T)throw new Error("storeKey has been removed and does not do anything. To use a custom Redux store for specific components, create a custom React context with React.createContext(), and pass the context object to React Redux's Provider and specific components like: <Provider context={MyContext}><ConnectedComponent context={MyContext} /></Provider>. You may also pass a {context : MyContext} option to connect")}var F=W;return function(d){if("production"!==process.env.NODE_ENV&&!p.exports.isValidElementType(d))throw new Error("You must pass a component to the function returned by "+b+". Instead received "+function(e){try{return JSON.stringify(e)}catch(t){return String(e)}}(d));var C=d.displayName||d.name||"Component",w=E(C),R=e({},A,{getDisplayName:E,methodName:b,renderCountProp:S,shouldHandleStateChanges:P,storeKey:T,displayName:w,wrappedComponentName:C,WrappedComponent:d}),N=A.pure;var g=N?n:function(e){return e()};function j(r){var C=n((function(){var e=r.reactReduxForwardedRef,o=t(r,["reactReduxForwardedRef"]);return[r.context,e,o]}),[r]),E=C[0],N=C[1],b=C[2],S=n((function(){return E&&E.Consumer&&p.exports.isContextConsumer(o.createElement(E.Consumer,null))?E:F}),[E,F]),j=i(S),D=Boolean(r.store)&&Boolean(r.store.getState)&&Boolean(r.store.dispatch),T=Boolean(j)&&Boolean(j.store);if("production"!==process.env.NODE_ENV&&!D&&!T)throw new Error('Could not find "store" in the context of "'+w+'". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to '+w+" in connect options.");var _=D?r.store:j.store,B=n((function(){return function(e){return s(e.dispatch,R)}(_)}),[_]),O=n((function(){if(!P)return f;var e=new u(_,D?null:j.subscription),t=e.notifyNestedSubs.bind(e);return[e,t]}),[_,D,j]),K=O[0],V=O[1],W=n((function(){return D?j:e({},j,{subscription:K})}),[D,j,K]),A=a(l,m,x),H=A[0][0],M=A[1];if(H&&H.error)throw H.error;var I=c(),L=c(b),U=c(),Y=c(!1),k=g((function(){return U.current&&b===L.current?U.current:B(_.getState(),b)}),[_,H,b]);v(h,[L,I,Y,b,k,U,V]),v(y,[P,_,K,B,L,I,Y,U,V,M],[_,K,B]);var J=n((function(){return o.createElement(d,e({},k,{ref:N}))}),[N,d,k]);return n((function(){return P?o.createElement(S.Provider,{value:W},J):J}),[S,J,W])}var D=N?o.memo(j):j;if(D.WrappedComponent=d,D.displayName=j.displayName=w,K){var _=o.forwardRef((function(t,r){return o.createElement(D,e({},t,{reactReduxForwardedRef:r}))}));return _.displayName=w,_.WrappedComponent=d,r(_,d)}return r(D,d)}}export default C;
//# sourceMappingURL=connectAdvanced.js.map
