import{R as g,g as c,W as r}from"./v_7_4_2_19_142f09de-58e9-4005-bc9b-6e38dd94578110.js";import{b as f}from"./v_7_4_2_19_142f09de-58e9-4005-bc9b-6e38dd94578119.js";import{c as u}from"./v_7_4_2_19_142f09de-58e9-4005-bc9b-6e38dd9457817.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"})},b=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{b as M,l as R,p as i,s as u};
