import{n as e,s as t}from"./tradingview-1JMKr2Mz.js";var n=`irsp.tradingviewOverrides`,r=`irsp.tradingviewResolutionCache`,i=`irsp.tradingviewPreferences`,a=2e3,o=5e3,s={widgetOrder:{stocks:[...e.stocks],crypto:[...e.crypto],forex:[...e.forex],other:[...e.other]},hiddenWidgets:{stocks:[],crypto:[],forex:[],other:[]}};async function c(e,t=chrome.storage.local){return _((await t.get(n))[n])[e]}async function l(e,t=chrome.storage.local){let r=v(e);if(!r)throw Error(`Invalid TradingView security override.`);let i=_((await t.get(n))[n]);i[r.securityId]=r,await t.set({[n]:w(i,a,e=>e.verifiedAt)})}async function u(e,t=chrome.storage.local){let r=_((await t.get(n))[n]);delete r[e],await t.set({[n]:r})}async function d(e,t=chrome.storage.local,n=Date.now()){let i=y((await t.get(r))[r])[e];if(!(!i||Date.parse(i.expiresAt)<=n))return i}async function f(e,t=chrome.storage.local){let n=b(e);if(!n)throw Error(`Invalid TradingView resolution cache entry.`);let i=y((await t.get(r))[r]);i[n.securityId]=n,await t.set({[r]:w(i,o,e=>e.resolvedAt)})}async function p(e,t=chrome.storage.local){if(!e){await t.set({[r]:{}});return}let n=y((await t.get(r))[r]);delete n[e],await t.set({[r]:n})}async function m(e=chrome.storage.local){return x((await e.get(i))[i])}async function h(e,t=chrome.storage.local){await t.set({[i]:x(e)})}async function g(e=chrome.storage.local){await e.set({[i]:s})}function _(e){if(!D(e))return{};let t={};for(let n of Object.values(e).slice(0,a)){let e=v(n);e&&(t[e.securityId]=e)}return t}function v(e){if(!D(e))return;let n=E(e.securityId,160),r=t(E(e.quoteKey,80))?.quoteKey,i=e.source,a=T(e.verifiedAt);if(!n||!r||!a||![`user-override`,`approved`,`curated`].includes(String(i)))return;let o={securityId:n,quoteKey:r,source:i,verifiedAt:a},s=E(e.submittedByUid,128);return s&&(o.submittedByUid=s),o}function y(e){if(!D(e))return{};let t={};for(let n of Object.values(e).slice(0,o)){let e=b(n);e&&(t[e.securityId]=e)}return t}function b(e){if(!D(e))return;let n=E(e.securityId,160),r=String(e.status),i=String(e.source),a=Number(e.confidence),o=T(e.resolvedAt),s=T(e.expiresAt);if(!n||![`verified`,`unverified`,`unavailable`].includes(r)||![`user-override`,`approved`,`curated`,`deterministic`,`symbol-search`,`provider-default`,`unsupported`].includes(i)||!Number.isFinite(a)||!o||!s)return;let c={securityId:n,status:r,source:i,confidence:Math.max(0,Math.min(100,Math.round(a))),resolvedAt:o,expiresAt:s},l=t(E(e.quoteKey,80))?.quoteKey,u=E(e.warning,240),d=E(e.provider,32);return l&&(c.quoteKey=l),u&&(c.warning=u),d&&(c.provider=d),c}function x(t){let n=D(t)?t:{},r=D(n.widgetOrder)?n.widgetOrder:{},i=D(n.hiddenWidgets)?n.hiddenWidgets:{},a={},o={};for(let t of Object.keys(e)){let n=new Set(e[t]),s=S(r[t]).filter(e=>n.has(e));a[t]=[...s,...e[t].filter(e=>!s.includes(e))],o[t]=S(i[t]).filter(e=>n.has(e))}return{widgetOrder:a,hiddenWidgets:o}}function S(e){return Array.isArray(e)?[...new Set(e.map(String).filter(C))]:[]}function C(t){return Object.values(e).some(e=>e.includes(t))}function w(e,t,n){return Object.fromEntries(Object.entries(e).sort((e,t)=>Date.parse(n(t[1]))-Date.parse(n(e[1]))).slice(0,t))}function T(e){let t=E(e,40);return t&&Number.isFinite(Date.parse(t))?new Date(t).toISOString():void 0}function E(e,t){return typeof e==`string`?e.trim().slice(0,t):``}function D(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}export{m as a,f as c,c as i,l,p as n,u as o,d as r,g as s,s as t,h as u};