import{i as e}from"./chunk-B3pr0VN8.js";import"./src-DeO5iVgv.js";import{n as t,t as n}from"./jsx-runtime-wTfS3W87.js";import{t as r}from"./client-DDZ1qWKB.js";import{t as i}from"./runtimeTheme-D84RXo8q.js";import{t as a}from"./Popup-CzzTYUju.js";import{a as o}from"./db-Cn_z-BCk.js";import{t as s}from"./ExtensionCrashBoundary-AOGiVqC0.js";var c=e(t(),1),l=e(r(),1),u=n();function d(){let[e,t]=(0,c.useState)(0),n=(0,c.useRef)(!1),r=(0,c.useRef)(null),s=(0,c.useRef)(0),l=(0,c.useRef)(0),d=(0,c.useRef)([]),f=`dashboard_hidden_jobs_v1`;return(0,c.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,l.current=Number.isFinite(i)?i:0;let a=Number(e?.popup_jobs_count||0);!(l.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(l.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}}},c=(e=900)=>{let t=Date.now();t-s.current<e||(s.current=t,r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{a()},180))},u=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}),c(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}),c();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,l.current=Number.isFinite(r)?r:0,c(0)}},m=()=>{document.visibilityState===`visible`&&a()};return chrome.runtime?.onMessage?.addListener?.(u),chrome.storage?.onChanged?.addListener?.(p),document.addEventListener(`visibilitychange`,m),a(),()=>{chrome.runtime?.onMessage?.removeListener?.(u),chrome.storage?.onChanged?.removeListener?.(p),document.removeEventListener(`visibilitychange`,m),r.current&&clearTimeout(r.current)}},[]),(0,u.jsx)(a,{jobsCount:e})}var f=document.getElementById(`root`);f&&l.createRoot(f).render((0,u.jsx)(c.StrictMode,{children:(0,u.jsx)(s,{surface:`popup`,children:(0,u.jsx)(d,{})})}));