import{l as d}from"./v_7_4_3_25_2ff64573-14a6-4762-a634-9cd350f14f778.js";import{a as w}from"./v_7_4_3_25_2ff64573-14a6-4762-a634-9cd350f14f7730.js";import{a as h,u as g,l as I,W as f}from"./v_7_4_3_25_2ff64573-14a6-4762-a634-9cd350f14f774.js";import{ah as i}from"./v_7_4_3_25_2ff64573-14a6-4762-a634-9cd350f14f7723.js";import{W as m,V as b}from"./v_7_4_3_25_2ff64573-14a6-4762-a634-9cd350f14f772.js";import"./v_7_4_3_25_2ff64573-14a6-4762-a634-9cd350f14f775.js";import{N as r,C as v,I as A}from"./v_7_4_3_25_2ff64573-14a6-4762-a634-9cd350f14f777.js";import{b as k}from"./v_7_4_3_25_2ff64573-14a6-4762-a634-9cd350f14f77.js";const p=k((o,c)=>({active:!1,socket:null,token:"",userID:"",connect:async()=>{const{token:t,userID:a,ouvintes:n}=c(),s=d(b.webSocket["api-whatsapp"],{path:"/ws/socket.io",transports:["websocket"]});s.open(),n(s),o({active:!0,socket:s}),await f("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}=c();t?.close(),t?.disconnect(),o({active:!1,socket:null}),await f("whatsApi",{active:!1,token:a,userID:n})},toggleSwitch:async()=>{const t=g.getState().language,{active:a,connect:n,disconnect:s,token:e}=c();if(!e){A({type:"Info",message:t.youNeedGenerateToken,position:"top-right"});return}a?s():await i("API",!0)?r("API",t.btnPremium,I()):n()},getToken:async()=>{const t=g.getState().language,{active:a,token:n,connect:s}=c();if(n&&!await new Promise(P=>{v({content:`${t.prestesASobrescreverTokenAtual} ${t.desejaContinuar}`,confirmText:t.confirm,submit:()=>P(!0)})}))return;a||await s();const{socket:e}=c();e.removeAllListeners("capture-token");const u=await m.Conn("getMyUserId");e.emit("set-user",u,n),e.on("capture-token",async l=>{A({type:"Success",message:t.tokenGenerateSucess,position:"top-right"}),await f("whatsApi",{active:!0,token:l,userID:u}),o({token:l,active:!0,userID:u})})},ouvintes:t=>{const a=g.getState().language,n=I(),{disconnect:s}=p.getState();t.on("sendText",async e=>{await i("API",!0)?(r("API",a.btnPremium,n),s()):m.Chat("sendTxt",{id:e.phone,msg:e.message})}),t.on("sendImage",async e=>{await i("API",!0)?(r("API",a.btnPremium,n),s()):m.Chat("sendImage",{id:e.phone,base64:e.base64,msg:e.message})}),t.on("sendVideo",async e=>{await i("API",!0)?(r("API",a.btnPremium,n),s()):m.Chat("sendVideo",{id:e.phone,base64:e.base64,msg:e.message})}),t.on("sendDoc",async e=>{await i("API",!0)?(r("API",a.btnPremium,n),s()):m.Chat("sendDoc",{id:e.phone,base64:e.base64,name:e.name})}),t.on("sendAudio",async e=>{await i("API",!0)?(r("API",a.btnPremium,n),s()):m.Chat("sendAudio",{id:e.phone,base64:e.base64})}),t.on("get-etiquetas",async e=>{if(await i("API",!0))r("API",a.btnPremium,n),s(),e([]);else{const u=await m.Labels("getAllLabels");e(u)}}),t.on("addOrRemoveLabels",async(e,u)=>{if(await i("API",!0))r("API",a.btnPremium,n),s(),u([]);else{const l=await m.Labels("addOrRemoveLabels",e);u(l)}}),t.on("createNote",async e=>{await i("API",!0)?(r("API",a.btnPremium,n),s()):w.getState().createNoteSocket(e.userID,e.text,e.base64)})}})),x=async()=>{const{connect:o}=p.getState(),{token:c,active:t,userID:a}=await h("whatsApi")||{},s=await i("API",!0)?!1:t;p.setState({token:c,active:s,userID:a}),s&&o()},R=async o=>{const{active:c,socket:t,connect:a}=p.getState();c&&(t?.close(),t?.disconnect()),p.setState({token:o.token,active:o.active}),o.active&&a()};export{p as a,x as i,R as r};
