function e(e){return`${l}${e}`}function t(){return Date.now()}function s(e){return!!e.ttl&&t()-e.ts>e.ttl}function a(e,t){n("DASHBOARD",`[LocalCache] ${e}`,t)}import{d as o,a as n,g as r}from"./platform-core.tlhrBXt0.js";const i=new Map,l="fleekdash:cache:",c={get(t){const a=i.get(t);if(a){if(!s(a))return a.v;i.delete(t)}try{const a=sessionStorage.getItem(e(t));if(!a)return null;const o=JSON.parse(a);return!o||s(o)?(sessionStorage.removeItem(e(t)),null):(i.set(t,o),o.v)}catch{return null}},set(s,o,n){const r={v:o,ts:t(),ttl:Math.max(0,n?.ttlMs||0),tags:n?.tags?.slice()};i.set(s,r);try{sessionStorage.setItem(e(s),JSON.stringify(r))}catch(l){a(`Failed to persist entry "${s}" to sessionStorage`,l)}},remove(t){i.delete(t);try{sessionStorage.removeItem(e(t))}catch(s){a(`Failed to remove entry "${t}" from sessionStorage`,s)}},invalidateTags(e){const t=new Set(Array.isArray(e)?e:[e]);for(const[a,o]of i.entries())o.tags?.some(e=>t.has(e))&&i.delete(a);try{const e=[];for(let t=0;t<sessionStorage.length;t++){const s=sessionStorage.key(t);s?.startsWith(l)&&e.push(s)}for(const o of e)try{const e=JSON.parse(sessionStorage.getItem(o)||"null");e?.tags?.some(e=>t.has(e))&&sessionStorage.removeItem(o)}catch(s){a(`Failed to evaluate sessionStorage entry "${o}" during tag invalidation`,s)}}catch(s){a("Failed to invalidate tags in sessionStorage",s)}},clearAll(){o("DASHBOARD","LocalCache: Clearing ALL cache data..."),i.clear();try{const e=[],t=[];for(let s=0;s<sessionStorage.length;s++){const a=sessionStorage.key(s);a&&(a.startsWith(l)?e.push(a):(a.includes("fleek")||a.includes("dashboard")||a.includes("chart")||a.includes("data-source")||a.includes("fleekdash")||a.includes("growth")||a.includes("post")||a.includes("analytics"))&&t.push(a))}o("DASHBOARD",`🗑️ LocalCache: Removing ${e.length} sessionStorage entries with prefix "${l}"`);for(const s of e)o("DASHBOARD",`Removing sessionStorage key: ${s}`),sessionStorage.removeItem(s);if(t.length>0){o("DASHBOARD",`🔍 Found ${t.length} other potential FleekDash keys - also removing:`);for(const e of t)o("DASHBOARD",`Removing potential FleekDash key: ${e}`),sessionStorage.removeItem(e)}}catch(e){n("DASHBOARD","Failed to clear sessionStorage",e)}},debugSessionStorage(){o("DASHBOARD","SessionStorage Diagnostic");const e=[],t=[];try{for(let s=0;s<sessionStorage.length;s++){const a=sessionStorage.key(s);a&&(e.push(a),a.startsWith(l)&&t.push(a))}o("DASHBOARD",`Total sessionStorage keys: ${e.length}`),o("DASHBOARD",`FleekDash cache keys: ${t.length}`),o("DASHBOARD","  Other keys:",e.filter(e=>!e.startsWith(l))),t.length>0&&o("DASHBOARD","FleekDash cache key list",t)}catch(s){n("DASHBOARD","Failed to inspect sessionStorage",s)}}};(()=>{const e=r();if(e)try{globalThis.addEventListener("fleekdash:invalidate",e=>{const t=e.detail;t?.tags&&c.invalidateTags(t.tags)},{passive:!0}),e.fleekdashInvalidate=e=>c.invalidateTags(e),e.fleekdashDebugCache=()=>c.debugSessionStorage()}catch(t){a("Failed to register LocalCache global bridge",t)}})();export{c as LocalCache,c as LocalCacheDefault};
//# sourceMappingURL=platform-auth-cache.CA6sQZaC.js.map
