import{S as t}from"./providers-HUbOKmh4.js";function y(){return new Date().toISOString().split("T")[0]}async function f(){const o=await chrome.storage.local.get([t.requestCount,t.requestDate,t.isPro]),n=o[t.requestDate],e=y();return n!==e?(await chrome.storage.local.set({[t.requestCount]:0,[t.requestDate]:e}),0):o[t.requestCount]??0}async function p(){const o=await chrome.storage.local.get([t.requestCount,t.requestDate,t.isPro]),n=o[t.requestDate],e=y();let i=0;n!==e?i=0:i=o[t.requestCount]??0;const r=i+1;return await chrome.storage.local.set({[t.requestCount]:r,[t.requestDate]:e}),r}const m=20,d=100;class w{async checkLimit(){const e=(await chrome.storage.local.get(["selectedProvider"])).selectedProvider||"free";let i=!1;if(e!=="free"&&(i=!!(await chrome.storage.local.get([`${e}ApiKey`]))[`${e}ApiKey`]),i)return{allowed:!0,remaining:1/0,limit:1/0};const r=await chrome.storage.local.get(["user_isPro","user_userType","user_dailyLimit"]),c=r.user_isPro===!0,s=r.user_userType,u=r.user_dailyLimit;if(c||s===2)return{allowed:!0,remaining:1/0,limit:1/0};const a=u||(s&&s>0?d:m),l=await f(),g=a-l;return g<=0?{allowed:!1,remaining:0,limit:a}:{allowed:!0,remaining:g,limit:a}}async incrementCount(){const e=(await chrome.storage.local.get(["selectedProvider"])).selectedProvider||"free";let i=!1;if(e!=="free"&&(i=!!(await chrome.storage.local.get([`${e}ApiKey`]))[`${e}ApiKey`]),i)return;const r=await chrome.storage.local.get(["user_isPro","user_userType"]),c=r.user_isPro===!0,s=r.user_userType;c||s===2||await p()}async getUsageStats(){const e=(await chrome.storage.local.get(["selectedProvider"])).selectedProvider||"free";let i=!1;if(e!=="free"&&(i=!!(await chrome.storage.local.get([`${e}ApiKey`]))[`${e}ApiKey`]),i)return{used:0,limit:1/0,remaining:1/0};const r=await chrome.storage.local.get(["user_isPro","user_userType","user_dailyLimit"]),c=r.user_isPro===!0,s=r.user_userType,u=r.user_dailyLimit;if(c||s===2)return{used:0,limit:1/0,remaining:1/0};const a=u||(s&&s>0?d:m),l=await f();return{used:l,limit:a,remaining:Math.max(0,a-l)}}}const I=new w;export{I as r};
