1import{r as x,j as e,L as g}from"./react-vendor-Cvme-g6x.js";import{t as c,m as s,o as w,B as C,q as D}from"./index-BJjQW3BE.js";import{E as Q}from"./external-link-hulnOIDb.js";function _({className:I,compact:d=!1,onDark:a=!1}){const u=c.useUtils(),[E,o]=x.useState(!1),i=x.useRef(!1),n=c.whatsappApi.getStatus.useQuery(void 0,{refetchInterval:8e3}),p=c.whatsappApi.startSession.useMutation({onSuccess(){u.whatsappApi.getStatus.invalidate(),i.current=!0}}),h=c.whatsappApi.reconnectSession.useMutation({onSuccess(){u.whatsappApi.getStatus.invalidate(),i.current=!0}}),b=n.data?.localAuthSnapshotOnDisk===!0,m=p.isPending||h.isPending,t=n.data?.status||(m?"INITIALIZING":"DISCONNECTED"),r=String(n.data?.qrCode||"").trim(),f=String(n.data?.pairingCode||"").trim(),l=n.data?.lastDisconnect??null,A=!!l&&(t==="DISCONNECTED"||t==="INITIALIZING"),v=t==="CONNECTED"?"Conectado":t==="INITIALIZING"?"Conectandoâ¦":t==="PAIRING_CODE_READY"?"Código de pareamento":t==="QR_READY"?"Aguardando QR":"Desconectado",j=a?t==="CONNECTED"?"border-emerald-400/40 bg-emerald-500/15 text-emerald-100":t==="INITIALIZING"||t==="QR_READY"||t==="PAIRING_CODE_READY"?"border-amber-400/35 bg-amber-500/15 text-amber-100":"border-white/15 bg-white/10 text-violet-200":t==="CONNECTED"?"border-emerald-200 bg-emerald-50 text-emerald-700":t==="INITIALIZING"||t==="QR_READY"||t==="PAIRING_CODE_READY"?"border-amber-200 bg-amber-50 text-amber-800":"border-slate-200 bg-slate-100 text-slate-600";x.useEffect(()=>{i.current&&(t!=="QR_READY"||!r||(o(!0),i.current=!1))},[t,r]);function R(){if(t!=="CONNECTED"){if(t==="QR_READY"&&r){o(!0);return}b?h.mutate():p.mutate()}}const N=t!=="CONNECTED";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:s("flex flex-wrap items-center gap-2",d?"text-xs":"text-sm",I),children:[e.jsx(w,{className:s("shrink-0",a?"text-emerald-300":"text-emerald-600",d?"h-3.5 w-3.5":"h-4 w-4")}),e.jsx("span",{className:s("rounded-full border px-2 py-0.5 text-[10px] font-semibold",j),children:v}),N?e.jsxs(C,{type:"button",size:"sm",disabled:m,onClick:()=>R(),className:"h-8 gap-1.5 rounded-full bg-emerald-600 px-3 text-xs font-semibold text-white hover:bg-emerald-700",children:[m?e.jsx(D,{className:"h-3.5 w-3.5 animate-spin"}):null,b?"Reconectar":"Conectar"]}):null,t==="QR_READY"&&r&&N?e.jsx("button",{type:"button",onClick:()=>o(!0),className:s("text-xs font-semibold underline-offset-2 hover:underline",a?"text-amber-200 hover:text-amber-50":"text-amber-800"),children:"Ver QR"}):null,e.jsxs(g,{to:"/affiliate-config",className:s("inline-flex items-center gap-1 text-xs font-semibold underline-offset-2 hover:underline",a?"text-violet-200 hover:text-white":"text-violet-600"),children:[d?"Pareamento":"Pareamento e grupos (Central do Afiliado)",e.jsx(Q,{className:s("h-3 w-3",a?"opacity-80":"opacity-70")})]})]}),A&&l?e.jsxs("div",{className:s("mt-2 rounded-xl border px-3 py-2 text-[11px] leading-snug",l.suspectedBlock?"border-rose-300 bg-rose-50 text-rose-800":"border-amber-300 bg-amber-50 text-amber-900"),children:[e.jsx("p",{className:"font-bold",children:l.suspectedBlock?"Número possivelmente bloqueado pelo WhatsApp":"Conexão do WhatsApp caiu"}),e.jsx("p",{className:"mt-0.5",children:l.suspectedBlock?"O envio de ofertas está parado. Tente reconectar; se não voltar, conecte outro número.":"O envio de ofertas está parado até reconectar. Toque em âReconectarâ acima."})]}):null,t==="PAIRING_CODE_READY"&&f?e.jsxs("p",{className:s("mt-1.5 text-[11px]",a?"text-amber-100/95":"text-amber-900"),children:["Código:"," ",e.jsx("span",{className:"font-mono font-bold tracking-widest",children:f})," â ","No app: aparelhos conectados â conectar com número."]}):null,E&&r?e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-slate-950/70 p-4",children:e.jsxs("div",{className:"w-full max-w-md rounded-[24px] border border-violet-200 bg-white p-5 shadow-2xl",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] text-violet-500",children:"WhatsApp"}),e.jsx("h4",{className:"text-lg font-black text-slate-900",children:"Escaneie o QR para conectar"})]}),e.jsx(C,{type:"button",variant:"outline",onClick:()=>o(!1),className:"h-9 shrink-0 rounded-xl",children:"Fechar"})]}),e.jsx("div",{className:"rounded-[18px] border border-violet-100 bg-violet-50/50 p-3",children:e.jsx("img",{src:r,alt:"QR Code do WhatsApp",className:"mx-auto h-72 w-72 max-w-full rounded-xl bg-white p-2"})}),e.jsxs("p",{className:"mt-3 text-center text-xs text-slate-500",children:["Problemas? Use"," ",e.jsx(g,{to:"/affiliate-config",className:"font-semibold text-violet-600 hover:underline",onClick:()=>o(!1),children:"a Central do Afiliado"})," ","para pareamento por número."]})]})}):null]})}export{_ as W};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.