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