var e=e=>!!e.dispatchFromDevtools&&typeof e.dispatch==`function`,t=new Map,n=e=>{let n=t.get(e);return n?Object.fromEntries(Object.entries(n.stores).map(([e,t])=>[e,t.getState()])):{}},r=(e,n,r)=>{if(e===void 0)return{type:`untracked`,connection:n.connect(r)};let i=t.get(r.name);if(i)return{type:`tracked`,store:e,...i};let a={connection:n.connect(r),stores:{}};return t.set(r.name,a),{type:`tracked`,store:e,...a}},i=(e,n)=>{if(n===void 0)return;let r=t.get(e);r&&(delete r.stores[n],Object.keys(r.stores).length===0&&t.delete(e))},a=e=>{if(!e)return;let t=e.split(`
`),n=t.findIndex(e=>e.includes(`api.setState`));if(n<0)return;let r=t[n+1]?.trim()||``;return/.+ (.+) .+/.exec(r)?.[1]},o=(t,o={})=>(c,l,u)=>{let{enabled:d,anonymousActionType:f,store:p,...m}=o,h;try{h=(d??!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!h)return t(c,l,u);let{connection:g,..._}=r(p,h,m),v=!0;u.setState=((e,t,r)=>{let i=c(e,t);if(!v)return i;let o=r===void 0?{type:f||a(Error().stack)||`anonymous`}:typeof r==`string`?{type:r}:r;return p===void 0?(g?.send(o,l()),i):(g?.send({...o,type:`${p}/${o.type}`},{...n(m.name),[p]:u.getState()}),i)}),u.devtools={cleanup:()=>{g&&typeof g.unsubscribe==`function`&&g.unsubscribe(),i(m.name,p)}};let y=(...e)=>{let t=v;v=!1,c(...e),v=t},b=t(u.setState,l,u);if(_.type===`untracked`?g?.init(b):(_.stores[_.store]=u,g?.init(Object.fromEntries(Object.entries(_.stores).map(([e,t])=>[e,e===_.store?b:t.getState()])))),e(u)){let e=u.dispatch;u.dispatch=(...t)=>{e(...t)}}return g.subscribe(t=>{switch(t.type){case`ACTION`:if(typeof t.payload!=`string`){console.error(`[zustand devtools middleware] Unsupported action format`);return}return s(t.payload,t=>{if(t.type===`__setState`){if(p===void 0){y(t.state);return}Object.keys(t.state).length!==1&&console.error(`
                    [zustand devtools middleware] Unsupported __setState action format.
                    When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
                    and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
                    `);let e=t.state[p];if(e==null)return;JSON.stringify(u.getState())!==JSON.stringify(e)&&y(e);return}e(u)&&u.dispatch(t)});case`DISPATCH`:switch(t.payload.type){case`RESET`:return y(b),p===void 0?g?.init(u.getState()):g?.init(n(m.name));case`COMMIT`:if(p===void 0){g?.init(u.getState());return}return g?.init(n(m.name));case`ROLLBACK`:return s(t.state,e=>{if(p===void 0){y(e),g?.init(u.getState());return}y(e[p]),g?.init(n(m.name))});case`JUMP_TO_STATE`:case`JUMP_TO_ACTION`:return s(t.state,e=>{if(p===void 0){y(e);return}JSON.stringify(u.getState())!==JSON.stringify(e[p])&&y(e[p])});case`IMPORT_STATE`:{let{nextLiftedState:e}=t.payload,n=e.computedStates.slice(-1)[0]?.state;if(!n)return;y(p===void 0?n:n[p]),g?.send(null,e);return}case`PAUSE_RECORDING`:return v=!v}return}}),b},s=(e,t)=>{let n;try{n=JSON.parse(e)}catch(e){console.error(`[zustand devtools middleware] Could not parse the received json`,e)}n!==void 0&&t(n)};function c(e,t){let n;try{n=e()}catch{return}return{getItem:e=>{let r=e=>e===null?null:JSON.parse(e,t?.reviver),i=n.getItem(e)??null;return i instanceof Promise?i.then(r):r(i)},setItem:(e,r)=>n.setItem(e,JSON.stringify(r,t?.replacer)),removeItem:e=>n.removeItem(e)}}var l=e=>t=>{try{let n=e(t);return n instanceof Promise?n:{then(e){return l(e)(n)},catch(e){return this}}}catch(e){return{then(e){return this},catch(t){return l(t)(e)}}}},u=(e,t)=>(n,r,i)=>{let a={storage:c(()=>window.localStorage),partialize:e=>e,version:0,merge:(e,t)=>({...t,...e}),...t},o=!1,s=0,u=new Set,d=new Set,f=a.storage;if(!f)return e((...e)=>{console.warn(`[zustand persist middleware] Unable to update item '${a.name}', the given storage is currently unavailable.`),n(...e)},r,i);let p=()=>{let e=a.partialize({...r()});return f.setItem(a.name,{state:e,version:a.version})},m=i.setState;i.setState=(e,t)=>(m(e,t),p());let h=e((...e)=>(n(...e),p()),r,i);i.getInitialState=()=>h;let g,_=()=>{if(!f)return;let e=++s;o=!1,u.forEach(e=>e(r()??h));let t=a.onRehydrateStorage?.call(a,r()??h)||void 0;return l(f.getItem.bind(f))(a.name).then(e=>{if(e)if(typeof e.version==`number`&&e.version!==a.version){if(a.migrate){let t=a.migrate(e.state,e.version);return t instanceof Promise?t.then(e=>[!0,e]):[!0,t]}console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`)}else return[!1,e.state];return[!1,void 0]}).then(t=>{if(e!==s)return;let[i,o]=t;if(g=a.merge(o,r()??h),n(g,!0),i)return p()}).then(()=>{e===s&&(t?.(r(),void 0),g=r(),o=!0,d.forEach(e=>e(g)))}).catch(n=>{e===s&&t?.(void 0,n)})};return i.persist={setOptions:e=>{a={...a,...e},e.storage&&(f=e.storage)},clearStorage:()=>{f?.removeItem(a.name)},getOptions:()=>a,rehydrate:()=>_(),hasHydrated:()=>o,onHydrate:e=>(u.add(e),()=>{u.delete(e)}),onFinishHydration:e=>(d.add(e),()=>{d.delete(e)})},a.skipHydration||_(),g||h};export{u as n,o as t};