import{a as e,f as t}from"./p-b891c2f1.js";const n=e=>!("isConnected"in e)||e.isConnected,s=(()=>{let e;return(...t)=>{e&&clearTimeout(e),e=setTimeout((()=>{e=0,(e=>{for(let t of e.keys())e.set(t,e.get(t).filter(n))})(...t)}),2e3)}})(),r=e=>"function"==typeof e?e():e,o=(n,o)=>{const c=((e,t=((e,t)=>e!==t))=>{const n=r(e);let s=new Map(Object.entries(null!=n?n:{}));const o={dispose:[],get:[],set:[],reset:[]},c=()=>{var t;s=new Map(Object.entries(null!==(t=r(e))&&void 0!==t?t:{})),o.reset.forEach((e=>e()))},u=e=>(o.get.forEach((t=>t(e))),s.get(e)),a=(e,n)=>{const r=s.get(e);t(n,r,e)&&(s.set(e,n),o.set.forEach((t=>t(e,n,r))))},l="undefined"==typeof Proxy?{}:new Proxy(n,{get:(e,t)=>u(t),ownKeys:()=>Array.from(s.keys()),getOwnPropertyDescriptor:()=>({enumerable:!0,configurable:!0}),has:(e,t)=>s.has(t),set:(e,t,n)=>(a(t,n),!0)}),i=(e,t)=>(o[e].push(t),()=>{((e,t)=>{const n=e.indexOf(t);n>=0&&(e[n]=e[e.length-1],e.length--)})(o[e],t)});return{state:l,get:u,set:a,on:i,onChange:(t,n)=>{const s=i("set",((e,s)=>{e===t&&n(s)})),o=i("reset",(()=>n(r(e)[t])));return()=>{s(),o()}},use:(...e)=>{const t=e.reduce(((e,t)=>(t.set&&e.push(i("set",t.set)),t.get&&e.push(i("get",t.get)),t.reset&&e.push(i("reset",t.reset)),t.dispose&&e.push(i("dispose",t.dispose)),e)),[]);return()=>t.forEach((e=>e()))},dispose:()=>{o.dispose.forEach((e=>e())),c()},reset:c,forceUpdate:e=>{const t=s.get(e);o.set.forEach((n=>n(e,t,t)))}}})(n,o);return c.use((()=>{if("function"!=typeof e)return{};const n=new Map;return{dispose:()=>n.clear(),get:t=>{const s=e();s&&((e,t,n)=>{const s=e.get(t);s?s.includes(n)||s.push(n):e.set(t,[n])})(n,t,s)},set:e=>{const r=n.get(e);r&&n.set(e,r.filter(t)),s(n)},reset:()=>{n.forEach((e=>e.forEach(t))),s(n)}}})()),c},c=(e,t)=>{try{return JSON.parse(e.getItem(t))}catch{return null}},u=(e,t,n,s=!1)=>{var r;const u=o(null!==(r=c(e,t))&&void 0!==r?r:n,((e,t)=>JSON.stringify(e)!==JSON.stringify(t))),a=(()=>{let n=!1;return()=>{n||(n=!0,setTimeout((()=>{e.setItem(t,JSON.stringify(u.state)),n=!1}),0))}})();return a(),s&&window.addEventListener("storage",(()=>{const n=c(e,t);if(null!==n)for(const e in n)u.set(e,n[e])})),u.use({set:a,reset:a}),u},a=((e,t,n=!1)=>u(localStorage,"surecart-local-storage",(()=>({live:{},test:{}})),n))(0,0,!0),l=(e,t)=>{var n;return null===(n=a.state[t])||void 0===n?void 0:n[e]},i=(e,t)=>{const n=(null==e?void 0:e.live_mode)?"live":"test";a.set(n,{...a.state[n],[t]:e})},f=(e,t)=>{const{[e]:n,...s}=a.state[t];return a.set(t,s)};export{f as a,o as c,l as g,i as s}