import{h as x,i as v}from"./index-CXwCk-SR.js";function E(r,e=Date.now()){return r.retentionDeadline!==void 0&&r.retentionDeadline>e}const A="vs:debug-history:v1",g=20;let d=null;function I(){if(typeof localStorage>"u")return[];try{const r=localStorage.getItem(A);if(!r)return[];const e=JSON.parse(r);return Array.isArray(e)?e:[]}catch{return[]}}function l(r){if(typeof localStorage>"u")return;let e=r;for(;;)try{localStorage.setItem(A,JSON.stringify(e));return}catch{if(e.length===0)return;e=e.slice(0,-1)}}function C(){return d===null&&(d=x(I())),d}function N(r){const e=C(),m=v(()=>e.value.filter(t=>t.widget===r).slice().sort((t,o)=>o.savedAt-t.savedAt)),w=v(()=>e.value.slice().sort((t,o)=>o.savedAt-t.savedAt));function S(t){const o=e.value.findIndex(n=>n.widget===t.widget&&n.session.sessionId===t.session.sessionId);if(o>=0){const n=e.value[o],a=n.recordCount===t.recordCount&&n.nodeCount===t.nodeCount,D=n.retentionDeadline===t.retentionDeadline;if(a&&D)return n;const f={...n,...t,id:n.id,savedAt:n.savedAt},c=e.value.slice();return c[o]=f,e.value=c,l(c),f}const s={...t,id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,9)}`,savedAt:Date.now()};let i=[s,...e.value];const u=i.filter(n=>n.widget===s.widget);if(u.length>g){const n=new Set(u.slice(g).map(a=>a.id));i=i.filter(a=>!n.has(a.id))}return e.value=i,l(i),s}function h(t){const o=e.value.filter(s=>s.id!==t);e.value=o,l(o)}function y(){const t=e.value.filter(o=>o.widget!==r);e.value=t,l(t)}return{entries:m,all:w,save:S,remove:h,clear:y}}export{E as i,N as u};
