import{d as z}from"./destr-BPvN1X9m.js";import{d as m,a as h}from"./deep-pick-omit-CegYQlcN.js";function y(e,{storage:n,serializer:r,key:i,debug:s,pick:a,omit:d,beforeHydrate:o,afterHydrate:t},c,f=!0){try{f&&o?.(c);const l=n.getItem(i);if(l){const u=r.deserialize(l),g=a?m(u,a):u,$=d?h(g,d):g;e.$patch($)}f&&t?.(c)}catch(l){s&&console.error("[pinia-plugin-persistedstate]",l)}}function p(e,{storage:n,serializer:r,key:i,debug:s,pick:a,omit:d}){try{const o=a?m(e,a):e,t=d?h(o,d):o,c=r.serialize(t);n.setItem(i,c)}catch(o){s&&console.error("[pinia-plugin-persistedstate]",o)}}function S(e,n,r){const{pinia:i,store:s,options:{persist:a=r}}=e;if(!a)return;if(!(s.$id in i.state.value)){const t=i._s.get(s.$id.replace("__hot:",""));t&&Promise.resolve().then(()=>t.$persist());return}const o=(Array.isArray(a)?a:a===!0?[{}]:[a]).map(n);s.$hydrate=({runHooks:t=!0}={})=>{o.forEach(c=>{y(s,c,e,t)})},s.$persist=()=>{o.forEach(t=>{p(s.$state,t)})},o.forEach(t=>{y(s,t,e),s.$subscribe((c,f)=>p(f,t),{detached:!0})})}function b(e={}){return function(n){S(n,r=>({key:(e.key?e.key:i=>i)(r.key??n.store.$id),debug:r.debug??e.debug??!1,serializer:r.serializer??e.serializer??{serialize:i=>JSON.stringify(i),deserialize:i=>z(i)},storage:r.storage??e.storage??window.localStorage,beforeHydrate:r.beforeHydrate,afterHydrate:r.afterHydrate,pick:r.pick,omit:r.omit}),e.auto??!1)}}var v=b();export{v as i};
