import{c as g}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e19.js";import{R as l,a as n,U as m}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e10.js";import{W as o}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e18.js";import{c as y}from"./v_7_4_0_1_4b8cc392-a410-45f6-b662-85abdad9c03e7.js";const u=y(i=>({status:[],createStatus:e=>i(s=>{const a=[e,...s.status];return n("status",a),{status:a}}),editStatus:e=>i(s=>{const a=s.status.map(r=>r.id===e.id?e:r);return n("status",a),{status:a}}),deleteStatus:e=>i(s=>{const a=s.status.filter(r=>r.id!==e);return n("status",a),{status:a}}),iniciarEnvioStatus:()=>{const{status:e}=u.getState(),s=e.filter(t=>{if(m.Dois_min_differ(`${t.data}T${t.hora}`))return t});if(s.length===0)return;const a=[],r=[];for(const t of s)t.type==="texto"?(o.Status("sendTextStatus",t),r.push(t.id)):t.type==="video"?(o.Status("sendVideoStatus",t),r.push(t.id)):t.type==="audio"?(o.Status("sendVideoStatus",t),r.push(t.id)):t.type==="image"&&(o.Status("sendImageStatus",t),r.push(t.id)),t.repostar&&(t.data=m.CalcularProximaData(t.data,"diario"),a.push(t));const d=[...e.filter(t=>!r.includes(t.id)),...a],p=s.map(t=>({id:t.id,data:t.data,repostar:t.repostar}));chrome.runtime.sendMessage({action:"status-dispart",dados:p}),n("status",d),u.setState({status:d})}})),R=async()=>{const i=await l("status")||[];u.setState({status:i})},h=async i=>{u.setState({status:i}),await n("status",i)},b=i=>{const e=[...u.getState().status],a=((r,c)=>r.concat(c).reduce((t,S)=>(t.find(f=>f.id===S.id)||t.push(S),t),[]))(e,i);h(a)};chrome.runtime.onMessage.addListener(async i=>{switch(i.action){case"Update_Status":g.getState().plugin_page||u.getState().iniciarEnvioStatus();break;case"status-dispart":let e=u.getState().status;i.dados.map(s=>{s.recorrencia.length==0?e=e.filter(a=>a.id!==s.id):e=e.map(a=>(a.id===s.id&&(a.data=s.data,a.repostar=s.repostar),a))}),u.setState({status:e});break}});export{b as M,h as R,R as i,u};
