import{R as l,W as c}from"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab11.js";import{c as d}from"./v_7_4_3_16_fa303664-d39f-4aec-85e8-7c81b2445eab8.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"})},m=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)},g=async()=>{const t=await l("relatorio")||[];n.setState({relatorio:t})},{setRelatorio:p}=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)&&p(a.relatorio)});break;case"relatorio-backup-update":g();break}});export{m as M,u as R,g as i,n as u};
