import{R as g,a as c,W as r}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e10.js";import{c as f}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e19.js";import{c as u}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e7.js";const s=u((a,o)=>({notifications:[],naoVisualizadaTam:0,setNotifications:t=>{c("notifications",t),f.getState().plugin_page?r("setNotifications",{notifications:t},!1):chrome.runtime.sendMessage({action:"setNotifications",dados:{notifications:t}});const i=t.filter(e=>e.timeOut&&!e.read);return a(()=>({notifications:t,naoVisualizadaTam:i.length})),{notifications:t,naoVisualizadas:i}},setNaoVisualizadaTam:t=>a({naoVisualizadaTam:t}),removeNotification:t=>a(i=>{const e=i.notifications.filter(n=>n.id!==t);return c("notifications",e),f.getState().plugin_page?r("removeNotification",{notificationId:t,updatedNotifications:e},!1):chrome.runtime.sendMessage({action:"removeNotification",dados:{notificationId:t,updatedNotifications:e}}),{notifications:e}}),editNotification:(t,i)=>a(e=>{const n=e.notifications.map(d=>d.id===t?i:d);return c("notifications",n),f.getState().plugin_page?r("Update_Notificação",{notificationId:t,updatedNotification:i},!1):chrome.runtime.sendMessage({action:"Update_Notificação",dados:{notificationId:t,updatedNotification:i}}),{notifications:n}})})),l=async a=>{s.setState({notifications:a}),await c("notifications",a),chrome.runtime.sendMessage({action:"notifications-backup-update"})},z=a=>{const o=[...s.getState().notifications];a.forEach(t=>{const i=o.findIndex(e=>e.id===t.id);i===-1?o.push(t):o[i]=t}),l(o)},p=async()=>{const a=await g("notifications")||[];s.setState({notifications:a})},{setNotifications:m,setNaoVisualizadaTam:N}=s.getState();chrome.runtime.onMessage.addListener(a=>{switch(a.action){case"Update_Notificação":m(a.dados.update),N(a.dados.tam);break;case"setNotifications":chrome.storage.local.get("notifications",t=>{JSON.stringify(t.notifications)!==JSON.stringify(s.getState().notifications)&&m(t.notifications)});break;case"notifications-backup-update":p();break;case"removeNotification":const{updatedNotifications:o}=a.dados;s.setState({notifications:o});break}});export{z as M,l as R,p as i,s as u};
