import{a as e,n as t,t as n}from"./jsx-runtime-CutOxEx1.js";import"./src-nEMn5Fcu.js";import{t as r}from"./client-DBCWmf5H.js";import{t as i}from"./runtimeTheme-Cf77mCZn.js";import{t as a}from"./Popup-ygCpWSXN.js";import{a as o}from"./db-C6LpVSNZ.js";var s=e(t(),1),c=e(r(),1),l=n();function u(){let[e,t]=(0,s.useState)(0),n=(0,s.useRef)(!1),r=(0,s.useRef)(null),c=(0,s.useRef)(0),u=(0,s.useRef)(0),d=(0,s.useRef)([]),f=`dashboard_hidden_jobs_v1`;return(0,s.useEffect)(()=>{i(`light`),chrome.storage?.local?.get?.({popup_jobs_count:0,[f]:null},e=>{let n=e?.[f]||null,r=Array.isArray(n?.hiddenIds)?n.hiddenIds.filter(Boolean):[],i=Number(n?.hiddenBeforeTs||0);d.current=r,u.current=Number.isFinite(i)?i:0;let a=Number(e?.popup_jobs_count||0);!(u.current>0||d.current.length>0)&&Number.isFinite(a)&&a>=0?t(a):t(0)});let e=e=>{let t=e?.created_at;if(typeof t==`number`&&Number.isFinite(t))return t;if(typeof t==`string`){let e=Date.parse(t);if(Number.isFinite(e))return e}return 0},a=async()=>{if(!n.current){n.current=!0;try{let n=await o(),r=new Set(d.current||[]),i=Number(u.current||0),a=n.filter(t=>{if(!t?.id||r.size>0&&r.has(t.id))return!1;if(i>0){let n=e(t);if(n>0&&n<=i)return!1}return!0}).length;t(a),chrome.storage?.local?.set?.({popup_jobs_count:a})}catch{}finally{n.current=!1}}},s=(e=900)=>{let t=Date.now();t-c.current<e||(c.current=t,r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{a()},180))},l=e=>{if(String(e?.type||``)===`JOBS_UPDATED`){let n=Number(e?.count??e?.payload?.count??0);if(Number.isFinite(n)&&n===0){t(0),chrome.storage?.local?.set?.({popup_jobs_count:0}),s(0);return}Number.isFinite(n)&&n>0&&t(e=>{let t=Math.max(0,e)+n;return chrome.storage?.local?.set?.({popup_jobs_count:t}),t}),s();return}},p=(e,t)=>{if(t===`local`&&e?.[f]){let t=e[f]?.newValue||null,n=Array.isArray(t?.hiddenIds)?t.hiddenIds.filter(Boolean):[],r=Number(t?.hiddenBeforeTs||0);d.current=n,u.current=Number.isFinite(r)?r:0,s(0)}},m=()=>{document.visibilityState===`visible`&&a()};return chrome.runtime?.onMessage?.addListener?.(l),chrome.storage?.onChanged?.addListener?.(p),document.addEventListener(`visibilitychange`,m),a(),()=>{chrome.runtime?.onMessage?.removeListener?.(l),chrome.storage?.onChanged?.removeListener?.(p),document.removeEventListener(`visibilitychange`,m),r.current&&clearTimeout(r.current)}},[]),(0,l.jsx)(a,{jobsCount:e})}var d=document.getElementById(`root`);d&&c.createRoot(d).render((0,l.jsx)(s.StrictMode,{children:(0,l.jsx)(u,{})}));