import{l as P}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b10.js";import{a as d}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b33.js";import{R as k,N as u,h as w,I as A,g as p}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b11.js";import{u as f}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b20.js";import{aA as c,s as I}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b24.js";import{W as m,V as b}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b19.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b.js";import{c as v}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b8.js";const g=v((o,r)=>({active:!1,socket:null,token:"",userID:"",connect:async()=>{const{token:t,userID:a,ouvintes:n}=r(),s=P(b.webSocket["api-whatsapp"],{path:"/ws/socket.io",transports:["websocket"]});s.open(),n(s),o({active:!0,socket:s}),await p("whatsApi",{active:!0,token:t,userID:a}),s.on("connect",()=>{o({active:!0}),s.emit("update-user-socket",a,t)}),s.on("disconnect",()=>{o({active:!1})})},disconnect:async()=>{const{socket:t,token:a,userID:n}=r();t?.close(),t?.disconnect(),o({active:!1,socket:null}),await p("whatsApi",{active:!1,token:a,userID:n})},toggleSwitch:async()=>{const t=f.getState().language,{label:a}=I.getState(),{active:n,connect:s,disconnect:e,token:i}=r();if(!i){A({type:"Info",message:t.youNeedGenerateToken,position:"top-right"});return}n?e():await c("API",!0)?u("API",t.btnPremium,a.checkout):s()},getToken:async()=>{const t=f.getState().language,{active:a,token:n,connect:s}=r();if(n&&!await new Promise(h=>{w({content:`${t.prestesASobrescreverTokenAtual} ${t.desejaContinuar}`,confirmText:t.confirm,submit:()=>h(!0)})}))return;a||await s();const{socket:e}=r();e.removeAllListeners("capture-token");const i=await m.Conn("getMyUserId");e.emit("set-user",i,n),e.on("capture-token",async l=>{A({type:"Success",message:t.tokenGenerateSucess,position:"top-right"}),await p("whatsApi",{active:!0,token:l,userID:i}),o({token:l,active:!0,userID:i})})},ouvintes:t=>{const a=f.getState().language,{label:n}=I.getState(),{disconnect:s}=g.getState();t.on("sendText",async e=>{await c("API",!0)?(u("API",a.btnPremium,n.checkout),s()):m.Chat("sendTxt",{id:e.phone,msg:e.message})}),t.on("sendImage",async e=>{await c("API",!0)?(u("API",a.btnPremium,n.checkout),s()):m.Chat("sendImage",{id:e.phone,base64:e.base64,msg:e.message})}),t.on("sendVideo",async e=>{await c("API",!0)?(u("API",a.btnPremium,n.checkout),s()):m.Chat("sendVideo",{id:e.phone,base64:e.base64,msg:e.message})}),t.on("sendDoc",async e=>{await c("API",!0)?(u("API",a.btnPremium,n.checkout),s()):m.Chat("sendDoc",{id:e.phone,base64:e.base64,name:e.name})}),t.on("sendAudio",async e=>{await c("API",!0)?(u("API",a.btnPremium,n.checkout),s()):m.Chat("sendAudio",{id:e.phone,base64:e.base64})}),t.on("get-etiquetas",async e=>{if(await c("API",!0))u("API",a.btnPremium,n.checkout),s(),e([]);else{const i=await m.Labels("getAllLabels");e(i)}}),t.on("addOrRemoveLabels",async(e,i)=>{if(await c("API",!0))u("API",a.btnPremium,n.checkout),s(),i([]);else{const l=await m.Labels("addOrRemoveLabels",e);i(l)}}),t.on("createNote",async e=>{await c("API",!0)?(u("API",a.btnPremium,n.checkout),s()):d.getState().createNoteSocket(e.userID,e.text,e.base64)})}})),x=async()=>{const{connect:o}=g.getState(),{token:r,active:t,userID:a}=await k("whatsApi")||{},s=await c("API",!0)?!1:t;g.setState({token:r,active:s,userID:a}),s&&o()},R=async o=>{const{active:r,socket:t,connect:a}=g.getState();r&&(t?.close(),t?.disconnect()),g.setState({token:o.token,active:o.active}),o.active&&a()};export{g as a,x as i,R as r};
