import{c as u}from"./logger-CvfM-6aa.js";const c=u("RemoteConfig"),h="https://wpics.oss-cn-shanghai.aliyuncs.com/wechatsync-config.json",i="remoteBanners",f="remoteBanners_lastFetch",r="dismissedBanners",m=6;function d(t,e){const s=t.match(/^>=(.+)$/);if(!s)return t===e;const o=s[1].split(".").map(Number),n=e.split(".").map(Number);for(let a=0;a<3;a++){if((n[a]||0)>(o[a]||0))return!0;if((n[a]||0)<(o[a]||0))return!1}return!0}function g(t){const e=Date.now();return!(t.startDate&&new Date(t.startDate).getTime()>e||t.endDate&&new Date(t.endDate).getTime()<e)}async function l(){try{const t=await fetch(h,{cache:"no-cache",headers:{Accept:"application/json"}});if(!t.ok){c.warn("Config fetch failed:",t.status);return}const e=await t.json(),s=chrome.runtime.getManifest().version,o=(e.banners||[]).filter(n=>g(n)).filter(n=>!n.targetVersion||d(n.targetVersion,s)).sort((n,a)=>(a.priority||0)-(n.priority||0));await chrome.storage.local.set({[i]:o,[f]:Date.now()}),c.debug("Config updated:",o.length,"banners")}catch(t){c.warn("Failed to fetch config:",t)}}async function p(){try{const e=(await chrome.storage.local.get(f))[f];(!e||Date.now()-e>=m*60*60*1e3)&&await l()}catch{await l()}}async function y(){try{const t=await chrome.storage.local.get([i,r]),e=t[i]||[],s=t[r]||[],o=new Set(s);return e.find(n=>!o.has(n.id)&&g(n))||null}catch{return null}}async function D(t){try{const s=(await chrome.storage.local.get(r))[r]||[];s.includes(t)||await chrome.storage.local.set({[r]:[...s,t]})}catch{}}export{p as a,D as d,l as f,y as g};
