import{G as e,W as t,h as n,z as r}from"./vscode-api-DjORcpSo.js";var i={logProductEvent__DEPRECATED_DO_NOT_USE:()=>{},logProductEvent:()=>{},trackCounter:async()=>{},flush:async()=>{},submitCodexAnalyticsEvent:null},a=t(n,i);function o(e,t,n){e.get(a).logProductEvent(t,n)}function s(e,t){e.get(a).logProductEvent__DEPRECATED_DO_NOT_USE(t)}var c=`codex:persisted-atom:`,l=new Map,u=new Map,d=null;function f(){let e=d;if(e)return e;throw Error(`Persisted atom store accessed before initialization`)}function p(e){let t=u.get(e);if(!t)return;let n=l.has(e),r=n?l.get(e):void 0;t.forEach(e=>{if(n){e.callback(r);return}e.callback(e.fallback)})}function m(e,t,n){let r=f();t===void 0?l.delete(e):l.set(e,t),n&&r(e,t),p(e)}function h(e,t){let n=new Set([...l.keys(),...Object.keys(e)]);l.clear(),Object.entries(e).forEach(([e,t])=>{t!==void 0&&l.set(e,t)}),d=t,n.forEach(e=>p(e))}function g(){return{getItem:(e,t)=>(f(),l.has(e)?l.get(e):t),setItem:(e,t)=>{if(f(),t===void 0){m(e,void 0,!0);return}m(e,t,!0)},removeItem:e=>{f(),m(e,void 0,!0)},subscribe:(e,t,n)=>{f();let r={callback:t,fallback:n},i=u.get(e)??new Set;return i.add(r),u.set(e,i),()=>{let t=u.get(e);t&&(t.delete(r),t.size===0&&u.delete(e))}}}}function _(e,t){return g().getItem(e,t)}function v(e,t){g().setItem(e,t)}function y(e,t,n){let r=g().subscribe;if(r==null)return()=>{};let i=r(e,n,t);return()=>{i?.()}}function b(e,t){f(),m(e,t,!1)}function x(){f();let e=Array.from(l.keys());l.clear();let t=d;t&&e.forEach(e=>t(e,void 0)),e.forEach(e=>p(e)),C()}function S(){if(typeof window>`u`||!window.localStorage)return{};let e={};for(let t=0;t<window.localStorage.length;t+=1){let n=window.localStorage.key(t);if(!n||!n.startsWith(`codex:persisted-atom:`))continue;let r=window.localStorage.getItem(n);if(r!=null)try{let t=JSON.parse(r);e[n.replace(c,``)]=t}catch{window.localStorage.removeItem(n)}}return e}function C(){if(typeof window>`u`||!window.localStorage)return;let e=[];for(let t=0;t<window.localStorage.length;t+=1){let n=window.localStorage.key(t);!n||!n.startsWith(`codex:persisted-atom:`)||e.push(n)}e.forEach(e=>window.localStorage.removeItem(e))}function w(e,t){return M({initialValue:t,key:e}),{cache:`signal`,resolve(t,n){return A.resolve(t,n,e).value$.atom},scope:n}}function T(t,r){let i=e(n,e=>_(t(e),r),{onMount(e,n){let a=t(n.key),o=!1,s=_(a,r);e(s);let c=y(a,r,t=>{o=!0,s=t;try{e(t)}finally{o=!1}}),l=n.watch(({get:e})=>{let t=e(i,n.key);o||Object.is(t,s)||(s=t,v(a,t))});return()=>{c(),l()}}});return i}var E=new Map,D=new Set,O=!1,k=t(n,[]),A=r(n,(e,{signal:t})=>({key:e,value$:t(void 0)}));function j(e){return D.add(e),e(Array.from(E.values())),()=>{D.delete(e)}}function M(e){E.has(e.key)||(E.set(e.key,e),N())}function N(){O||(O=!0,queueMicrotask(()=>{O=!1,P()}))}function P(){let e=Array.from(E.values());D.forEach(t=>t(e))}export{i as _,j as a,g as c,S as d,x as f,s as g,o as h,A as i,_ as l,y as m,T as n,b as o,v as p,k as r,C as s,w as t,h as u,a as v};
//# sourceMappingURL=persisted-signal-CweW-bgN.js.map