import{a as c,W as l}from"./v_7_4_3_42_40a29d0b-9b36-4e19-997c-87ed486b67154.js";import{b as d}from"./v_7_4_3_42_40a29d0b-9b36-4e19-997c-87ed486b6715.js";const n=d((t,a)=>({relatorio:[],setRelatorio:async e=>{await l("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 l("relatorio",o),{relatorio:o}}else{const o=[...r.relatorio];o.length>=30&&o.pop();const i=[e,...o];return l("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 l("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 c("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};
