import{a as l,W as c}from"./v_7_4_3_72_6a457bf5-eeae-4570-8821-bd6fa39c89264.js";import"./v_7_4_3_72_6a457bf5-eeae-4570-8821-bd6fa39c89265.js";import{c as d}from"./v_7_4_3_72_6a457bf5-eeae-4570-8821-bd6fa39c89262.js";const n=d((t,a)=>({relatorio:[],setRelatorio:async e=>{await c("relatorio",e),chrome.runtime.sendMessage({action:"setRelatorio",dados:{relatorio:e}}),t(()=>({relatorio:e}))},updateRelatorio:e=>{t(r=>{if(r.relatorio.find(o=>o.id===e.id)){const o=r.relatorio.map(i=>i.id===e.id?{...i,send:[...i.send,...e.send]}:i);return c("relatorio",o),{relatorio:o}}else{const o=[...r.relatorio];o.length>=30&&o.pop();const i=[e,...o];return c("relatorio",i),{relatorio:i}}})},getRelatorio:e=>{const{relatorio:r}=a(),s=r.find(o=>o.id===e);return s?s.send:[]}})),u=async t=>{n.setState({relatorio:t}),await c("relatorio",t),chrome.runtime.sendMessage({action:"relatorio-backup-update"})},S=t=>{const a=[...n.getState().relatorio];t.forEach(e=>{const r=a.findIndex(s=>s.id===e.id);r===-1?a.push(e):a[r]=e}),u(a)},p=async()=>{const t=await l("relatorio")||[];n.setState({relatorio:t})},{setRelatorio:g}=n.getState();chrome.runtime.onMessage.addListener(t=>{switch(t.action){case"setRelatorio":chrome.storage.local.get("relatorio",a=>{JSON.stringify(a.relatorio)!==JSON.stringify(n.getState().relatorio)&&g(a.relatorio)});break;case"relatorio-backup-update":p();break}});export{S as M,u as R,p as i,n as u};
