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