import p from"react";var E=e=>{let t,n=new Set,s=(l,u)=>{let d=typeof l=="function"?l(t):l;if(!Object.is(d,t)){let g=t;t=u??(typeof d!="object"||d===null)?d:Object.assign({},t,d),n.forEach(m=>m(t,g))}},i=()=>t,c={setState:s,getState:i,getInitialState:()=>v,subscribe:l=>(n.add(l),()=>n.delete(l))},v=t=e(s,i,c);return c},T=(e=>e?E(e):E);var x=e=>e;function R(e,t=x){let n=p.useSyncExternalStore(e.subscribe,p.useCallback(()=>t(e.getState()),[e,t]),p.useCallback(()=>t(e.getInitialState()),[e,t]));return p.useDebugValue(n),n}var C=e=>{let t=T(e),n=s=>R(t,s);return Object.assign(n,t),n},A=(e=>e?C(e):C);function k(e,t){let n;try{n=e()}catch{return}return{getItem:i=>{var o;let S=v=>v===null?null:JSON.parse(v,t?.reviver),c=(o=n.getItem(i))!=null?o:null;return c instanceof Promise?c.then(S):S(c)},setItem:(i,o)=>n.setItem(i,JSON.stringify(o,t?.replacer)),removeItem:i=>n.removeItem(i)}}var O=e=>t=>{try{let n=e(t);return n instanceof Promise?n:{then(s){return O(s)(n)},catch(s){return this}}}catch(n){return{then(s){return this},catch(s){return O(s)(n)}}}},N=(e,t)=>(n,s,i)=>{let o={storage:k(()=>localStorage),partialize:r=>r,version:0,merge:(r,h)=>({...h,...r}),...t},S=!1,c=0,v=new Set,l=new Set,u=o.storage;if(!u)return e((...r)=>{console.warn(`[zustand persist middleware] Unable to update item '${o.name}', the given storage is currently unavailable.`),n(...r)},s,i);let d=()=>{let r=o.partialize({...s()});return u.setItem(o.name,{state:r,version:o.version})},g=i.setState;i.setState=(r,h)=>(g(r,h),d());let m=e((...r)=>(n(...r),d()),s,i);i.getInitialState=()=>m;let y,w=()=>{var r,h;if(!u)return;let I=++c;S=!1,v.forEach(a=>{var f;return a((f=s())!=null?f:m)});let b=((h=o.onRehydrateStorage)==null?void 0:h.call(o,(r=s())!=null?r:m))||void 0;return O(u.getItem.bind(u))(o.name).then(a=>{if(a)if(typeof a.version=="number"&&a.version!==o.version){if(o.migrate){let f=o.migrate(a.state,a.version);return f instanceof Promise?f.then(_=>[!0,_]):[!0,f]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,a.state];return[!1,void 0]}).then(a=>{var f;if(I!==c)return;let[_,j]=a;if(y=o.merge(j,(f=s())!=null?f:m),n(y,!0),_)return d()}).then(()=>{I===c&&(b?.(y,void 0),y=s(),S=!0,l.forEach(a=>a(y)))}).catch(a=>{I===c&&b?.(void 0,a)})};return i.persist={setOptions:r=>{o={...o,...r},r.storage&&(u=r.storage)},clearStorage:()=>{u?.removeItem(o.name)},getOptions:()=>o,rehydrate:()=>w(),hasHydrated:()=>S,onHydrate:r=>(v.add(r),()=>{v.delete(r)}),onFinishHydration:r=>(l.add(r),()=>{l.delete(r)})},o.skipHydration||w(),y||m},P=N;export{A as a,P as b};
//# sourceMappingURL=chunk-3XIZD54N.js.map
