function N(e,i){if(e==null)return;let r=e;for(let t=0;t<i.length;t++){if(r===void 0||r[i[t]]===void 0)return;if(r===null||r[i[t]]===null)return null;r=r[i[t]]}return r}function y(e,i,r){if(r.length===0)return i;const t=r[0];return r.length>1&&(i=y(typeof e!="object"||e===null||!Object.prototype.hasOwnProperty.call(e,t)?Number.isInteger(Number(r[1]))?[]:{}:e[t],i,Array.prototype.slice.call(r,1))),Number.isInteger(Number(t))&&Array.isArray(e)?e.slice()[t]:Object.assign({},e,{[t]:i})}function A(e,i){if(e==null||i.length===0)return e;if(i.length===1){if(e==null)return e;if(Number.isInteger(i[0])&&Array.isArray(e))return Array.prototype.slice.call(e,0).splice(i[0],1);const r={};for(const t in e)r[t]=e[t];return delete r[i[0]],r}if(e[i[0]]==null){if(Number.isInteger(i[0])&&Array.isArray(e))return Array.prototype.concat.call([],e);const r={};for(const t in e)r[t]=e[t];return r}return y(e,A(e[i[0]],Array.prototype.slice.call(i,1)),[i[0]])}function S(e,i){return i.map(r=>r.split(".")).map(r=>[r,N(e,r)]).filter(r=>r[1]!==void 0).reduce((r,t)=>y(r,t[1],t[0]),{})}function $(e,i){return i.map(r=>r.split(".")).reduce((r,t)=>A(r,t),e)}function m(e,{storage:i,serializer:r,key:t,debug:s,pick:l,omit:c,beforeHydrate:n,afterHydrate:u},a,d=!0){try{d&&(n==null||n(a));const f=i.getItem(t);if(f){const g=r.deserialize(f),o=l?S(g,l):g,z=c?$(o,c):o;e.$patch(z)}d&&(u==null||u(a))}catch(f){s&&console.error("[pinia-plugin-persistedstate]",f)}}function p(e,{storage:i,serializer:r,key:t,debug:s,pick:l,omit:c}){try{const n=l?S(e,l):e,u=c?$(n,c):n,a=r.serialize(u);i.setItem(t,a)}catch(n){s&&console.error("[pinia-plugin-persistedstate]",n)}}function O(e,i){return typeof e=="function"?e(i):typeof e=="string"?e:i}function P(e,i,r){const{pinia:t,store:s,options:{persist:l=r}}=e;if(!l)return;if(!(s.$id in t.state.value)){const n=t._s.get(s.$id.replace("__hot:",""));n&&Promise.resolve().then(()=>n.$persist());return}const c=(Array.isArray(l)?l:l===!0?[{}]:[l]).map(i);s.$hydrate=({runHooks:n=!0}={})=>{c.forEach(u=>{m(s,u,e,n)})},s.$persist=()=>{c.forEach(n=>{p(s.$state,n)})},c.forEach(n=>{m(s,n,e),s.$subscribe((u,a)=>p(a,n),{detached:!0})})}function v(e={}){return function(i){var r;P(i,t=>{var l,c,n,u,a,d,f,g;const s=O(t.key,i.store.$id);return{key:(e.key?e.key:o=>o)(s),debug:(c=(l=t.debug)!=null?l:e.debug)!=null?c:!1,serializer:(u=(n=t.serializer)!=null?n:e.serializer)!=null?u:{serialize:o=>JSON.stringify(o),deserialize:o=>JSON.parse(o)},storage:(d=(a=t.storage)!=null?a:e.storage)!=null?d:window.localStorage,beforeHydrate:(f=t.beforeHydrate)!=null?f:e.beforeHydrate,afterHydrate:(g=t.afterHydrate)!=null?g:e.afterHydrate,pick:t.pick,omit:t.omit}},(r=e.auto)!=null?r:!1)}}export{v as createPersistedState};
