import{g as f,a as l,W as n,U as m}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1164.js";import{W as o}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb1162.js";import{b as y}from"./v_7_4_3_28_345c6a4a-aab6-4ec9-a0c6-3718e7fdb116.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],S=s.map(t=>({id:t.id,data:t.data,repostar:t.repostar}));chrome.runtime.sendMessage({action:"status-dispart",dados:S}),n("status",d),u.setState({status:d})}})),P=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,p)=>(t.find(g=>g.id===p.id)||t.push(p),t),[]))(e,i);h(a)};chrome.runtime.onMessage.addListener(async i=>{switch(i.action){case"Update_Status":f.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,P as i,u};
