const r=t=>`forcedStateResetId:${t}`,n="forcedStateResetId";let c=!1;const o=t=>typeof t=="number"?t:0;async function l(t){try{const e=r(t),a=await chrome.storage.local.get([e,n]);return Math.max(o(a[e]),o(a[n]))}catch{return 0}}async function p(t,e){try{await chrome.storage.local.set({[r(t)]:e})}catch{}}async function y(t,e,a){if(typeof e!="number"||e<=0||c)return;const s=await l(t);if(!(e<=s)){c=!0;try{await p(t,e),console.warn(`[1AM] Applying ${t} state reset #${e} \u2014 clearing cache and resyncing`),await a()}catch(i){console.error("[1AM] Forced state reset failed:",i)}finally{c=!1}}}export{y as applyServerStateReset};
