import{ae as E,P as T,am as b,ai as C}from"./index.8706e7a3.js";import{w as x}from"./index.8b48d14e.js";const f={};function m(e){return e==="local"?localStorage:sessionStorage}function N(e,c,t){const r=(t==null?void 0:t.serializer)??JSON,a=(t==null?void 0:t.storage)??"local",s=typeof window<"u"&&typeof document<"u";function S(i,u){s&&m(a).setItem(i,r.stringify(u))}if(!f[e]){const i=x(c,n=>{const o=s?m(a).getItem(e):null;if(o&&n(r.parse(o)),s){const w=g=>{g.key===e&&n(g.newValue?r.parse(g.newValue):null)};return window.addEventListener("storage",w),()=>window.removeEventListener("storage",w)}}),{subscribe:u,set:l}=i;f[e]={set(n){S(e,n),l(n)},update(n){const o=n(E(i));S(e,o),l(o)},subscribe:u}}return f[e]}const d="SETTINGS_CONTEXT",O="settingsStore";function I(){const e={},{subscribe:c,set:t,update:r}=N(O,e,{storage:"session"});return{subscribe:c,set:t,update:r,reset(){t(JSON.parse(JSON.stringify(e)))},setEmbedding(a){r(s=>(s.embedding=a,s))}}}function h(e){T(d,e)}function J(){if(!b(d))throw new Error("SettingsContext not found");return C(d)}export{I as c,J as g,h as s};
