1import{j as e,r}from"./react-vendor-pafHdoJx.js";import{u as $,d as g,M as _,C as H}from"./index-Db0fDLGN.js";import{E as W}from"./ErrorState-B9i6eo2M.js";import{i as q,W as M}from"./whatsapp-shared-BYiuVwmW.js";import{b4 as V,as as J,x as K,l as X,L as S,j as Y,b9 as Z,a7 as ee,k as se,a_ as ae,Q as te,bf as re,c as ne}from"./ui-vendor-DLXJn6s3.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";const I=[{key:"brandName",label:"Nome comercial",description:'Aparece em todas as mensagens. Ex: "Transportes ACME".',placeholder:"Sua transportadora"},{key:"signature",label:"Assinatura",description:'Footer das mensagens. Ex: "Atenciosamente, Equipe ACME".',placeholder:"Equipe da sua transportadora"},{key:"trackingBaseUrl",label:"URL de tracking",description:"Base do link enviado pro embarcador. Use domÃnio próprio (CNAME) se quiser white-label total.",placeholder:"https://www.sentinel365.ai/track"},{key:"optoutBaseUrl",label:"URL de opt-out (LGPD)",description:"Link no footer pra descadastrar. Pode ser domÃnio próprio.",placeholder:"https://www.sentinel365.ai/whatsapp/optout"},{key:"adminBaseUrl",label:"URL de admin",description:"Aparece em mensagens internas (CIOT vencido, etc).",placeholder:"https://www.sentinel365.ai/v2/admin"},{key:"supportPhone",label:"Telefone de suporte (opcional)",description:"Aparece em mensagens de problema/emergência. Formato E.164: +5511...",placeholder:"+5511999999999"}];function he(){return e.jsxs("div",{className:"space-y-6 max-w-3xl",children:[e.jsx(le,{}),e.jsx("div",{className:"h-px",style:{background:"var(--page-border)"}}),e.jsx(ce,{})]})}function le(){const{toast:t}=$(),[y,E]=r.useState([]),[h,o]=r.useState(!0),[m,p]=r.useState(!1),[x,v]=r.useState(!1),[f,j]=r.useState(""),[N,w]=r.useState(""),[k,C]=r.useState(null),[R,d]=r.useState(null),[L,a]=r.useState(!1),[n,c]=r.useState(null),[i,A]=r.useState(null),[D,B]=r.useState(!1),[l,Q]=r.useState(null),b=r.useCallback(async()=>{o(!0),A(null);try{const s=await g.waInstances();E(s||[]),B(!1)}catch(s){q(s)?B(!0):A(s)}finally{o(!1)}},[]);r.useEffect(()=>{b()},[b]);const P=async()=>{p(!0),c(null);try{const s=await g.waProvisionInstance({number:f,label:N||void 0});v(!1),j(""),w(""),C({id:s.id,name:s.instanceName}),d(s.qrcode||null),await b()}catch(s){c((s==null?void 0:s.message)||"Falha ao conectar.")}finally{p(!1)}},U=async s=>{C({id:s.id,name:s.instanceName}),d(null),a(!0);try{const u=await g.waInstanceQR(s.id);d(u.base64)}catch(u){c((u==null?void 0:u.message)||"Falha ao gerar QR.")}finally{a(!1)}},O=async()=>{if(k){a(!0);try{const s=await g.waInstanceQR(k.id);d(s.base64)}catch{}finally{a(!1)}}},T=s=>Q({kind:"logout",inst:s}),z=s=>Q({kind:"delete",inst:s}),G=async()=>{if(!l)return;const{kind:s,inst:u}=l;try{s==="logout"?(await g.waInstanceLogout(u.id),t({title:"Instância desconectada",kind:"success"})):(await g.waInstanceDelete(u.id),t({title:"Instância removida",kind:"success"})),await b()}catch(F){t({title:s==="logout"?"Falha ao desconectar":"Falha ao remover",description:F==null?void 0:F.message,kind:"error"})}};return e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(V,{className:"w-5 h-5",style:{color:"var(--page-text-secondary)"}}),e.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--page-text)"},children:"Conexão WhatsApp"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:b,disabled:h,className:"p-2 rounded hover-surface",children:e.jsx(J,{className:`w-4 h-4 ${h?"animate-spin":""}`,style:{color:"var(--page-text-muted)"}})}),!x&&e.jsxs("button",{onClick:()=>v(!0),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium",style:{background:"#10B981",color:"#fff"},children:[e.jsx(K,{className:"w-3.5 h-3.5"}),"Conectar número"]})]})]}),n&&e.jsxs("div",{className:"mb-3 p-3 rounded-lg text-xs flex items-start gap-2",style:{background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.25)",color:"#EF4444"},children:[e.jsx(X,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:n})]}),x&&e.jsxs("div",{className:"p-4 rounded-lg mb-3 space-y-3",style:{background:"var(--page-surface)",border:"1px solid var(--page-border)"},children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--page-text)"},children:"Número (com DDI)"}),e.jsx("input",{type:"text",value:f,onChange:s=>j(s.target.value),placeholder:"5511999999999",className:"w-full px-3 py-2 rounded-md text-sm",style:{background:"var(--page-bg)",border:"1px solid var(--page-border)",color:"var(--page-text)"}}),e.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--page-text-muted)"},children:"Use o número WhatsApp da sua transportadora (não pessoal). Após criar, abre QR pra escanear."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium block mb-1",style:{color:"var(--page-text)"},children:"Rótulo (opcional)"}),e.jsx("input",{type:"text",value:N,onChange:s=>w(s.target.value),placeholder:"Comercial / Suporte / etc.",className:"w-full px-3 py-2 rounded-md text-sm",style:{background:"var(--page-bg)",border:"1px solid var(--page-border)",color:"var(--page-text)"}})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:P,disabled:m||!f,className:"px-4 py-2 rounded-lg text-sm font-medium text-white disabled:opacity-50",style:{background:"#10B981"},children:m?e.jsx(S,{className:"w-4 h-4 animate-spin inline"}):"Conectar"}),e.jsx("button",{onClick:()=>{v(!1),j(""),w(""),c(null)},className:"px-4 py-2 rounded-lg text-sm font-medium",style:{color:"var(--page-text-muted)"},children:"Cancelar"})]})]}),D?e.jsx(M,{compact:!0}):h?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(S,{className:"w-5 h-5 animate-spin",style:{color:"var(--page-text-muted)"}})}):i?e.jsx(W,{error:i,onRetry:b,title:"Não foi possÃvel carregar as instâncias"}):y.length===0&&!x?e.jsxs("div",{className:"text-center py-8 text-sm",style:{color:"var(--page-text-muted)"},children:["Nenhum número conectado ainda. Clique ",e.jsx("strong",{children:"Conectar número"})," pra começar."]}):e.jsx("div",{className:"space-y-2",children:y.map(s=>e.jsx(oe,{inst:s,onOpenQr:U,onLogout:T,onDelete:z},s.id))}),k&&e.jsx(_,{open:!0,onClose:()=>{C(null),d(null)},title:"Escaneie no WhatsApp",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"No celular: WhatsApp â âï¸ â Aparelhos conectados â Conectar aparelho."}),e.jsx("div",{className:"flex items-center justify-center",style:{minHeight:280},children:L?e.jsx(S,{className:"w-8 h-8 animate-spin",style:{color:"var(--page-text-muted)"}}
1):R?e.jsx("img",{src:R,alt:"QR Code",className:"w-64 h-64 rounded-lg"}):e.jsx("div",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:'QR não disponÃvel. Aguarde alguns segundos e clique em "Atualizar QR".'})}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("button",{onClick:O,disabled:L,className:"px-3 py-1.5 rounded-md text-xs font-medium",style:{background:"var(--page-surface)",color:"var(--page-text)",border:"1px solid var(--page-border)"},children:L?e.jsx(S,{className:"w-3 h-3 animate-spin inline"}):"Atualizar QR"}),e.jsx("button",{onClick:()=>{C(null),d(null),b()},className:"px-3 py-1.5 rounded-md text-xs font-medium text-white",style:{background:"#10B981"},children:"Fechar"})]})]})}),e.jsx(H,{open:!!l,onClose:()=>Q(null),title:(l==null?void 0:l.kind)==="delete"?`Remover a instância ${l.inst.number||l.inst.instanceName}?`:"Desconectar essa instância?",description:(l==null?void 0:l.kind)==="delete"?"Ela some completamente â pra ter WhatsApp de novo precisa conectar um número novo.":"O responsável pelo número precisará escanear o QR de novo pra reconectar.",confirmLabel:(l==null?void 0:l.kind)==="delete"?"Remover instância":"Desconectar",onConfirm:G})]})}function oe({inst:t,onOpenQr:y,onLogout:E,onDelete:h}){const o=t.state==="open",m=t.state==="connecting"||t.state==="close",p=o?"#10B981":m?"#F59E0B":"#94A3B8",x=o?"Conectado":t.state==="connecting"?"Conectando":t.state==="close"?"Desconectado":t.state;return e.jsxs("div",{className:"p-3 rounded-lg flex items-center gap-3 flex-wrap",style:{background:"var(--page-surface)",border:"1px solid var(--page-border)"},children:[e.jsx("div",{className:"flex-shrink-0 w-10 h-10 rounded-full flex items-center justify-center",style:{background:`${p}20`},children:o?e.jsx(se,{className:"w-5 h-5",style:{color:p}}):e.jsx(ae,{className:"w-5 h-5",style:{color:p}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:t.number||t.instanceName}),t.label&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full",style:{background:"var(--page-bg)",color:"var(--page-text-muted)"},children:t.label}),t.quarantined&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full",style:{background:"rgba(239,68,68,0.15)",color:"#EF4444"},children:"quarentena"})]}),e.jsxs("div",{className:"text-xs mt-0.5 flex items-center gap-2",style:{color:"var(--page-text-muted)"},children:[e.jsxs("span",{style:{color:p},children:["â ",x]}),o&&typeof t.warmupDay=="number"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Warm-up dia ",t.warmupDay]}),typeof t.dailyCap=="number"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:[t.sentToday||0,"/",t.dailyCap," hoje"]})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[m&&e.jsxs("button",{onClick:()=>y(t),className:"flex items-center gap-1 px-2.5 py-1 rounded-md text-xs font-medium text-white",style:{background:"#10B981"},children:[e.jsx(te,{className:"w-3.5 h-3.5"}),"QR"]}),o&&e.jsxs("button",{onClick:()=>E(t),className:"flex items-center gap-1 px-2.5 py-1 rounded-md text-xs font-medium",style:{background:"var(--page-bg)",color:"var(--page-text-secondary)",border:"1px solid var(--page-border)"},children:[e.jsx(re,{className:"w-3.5 h-3.5"}),"Desconectar"]}),e.jsx("button",{onClick:()=>h(t),className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium",style:{color:"#EF4444",background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.25)"},title:"Remover instância",children:e.jsx(ne,{className:"w-3.5 h-3.5"})})]})]})}function ce(){const[t,y]=r.useState({}),[E,h]=r.useState({}),[o,m]=r.useState({}),[p,x]=r.useState(!0),[v,f]=r.useState(!1),[j,N]=r.useState(null),[w,k]=r.useState(null),[C,R]=r.useState(!1),d=r.useCallback(async()=>{x(!0),k(null);try{const a=await g.waGetBranding();y((a==null?void 0:a.resolved)||{});const n=(a==null?void 0:a.overrides)||{};h(n);const c={};for(const i of I)c[i.key]=n[i.key]||"";m(c),R(!1)}catch(a){q(a)?R(!0):k(a)}finally{x(!1)}},[]);r.useEffect(()=>{d()},[d]);const L=async()=>{var a;f(!0),N(null);try{const n={};for(const c of I){const i=((a=o[c.key])==null?void 0:a.trim())||"";n[c.key]=i===""?null:i}await g.waSaveBranding(n),N("Salvo. Mudanças entram em vigor em até 60s."),await d()}catch(n){N("Erro: "+((n==null?void 0:n.message)||"desconhecido"))}finally{f(!1)}};return C?e.jsx(M,{compact:!0}):p?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(S,{className:"w-5 h-5 animate-spin",style:{color:"var(--page-text-muted)"}})}):w?e.jsx(W,{error:w,onRetry:d,title:"Não foi possÃvel carregar o branding do WhatsApp"}):e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"w-5 h-5",style:{color:"var(--page-text-secondary)"}}),e.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--page-text)"},children:"Marca nas mensagens"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[j&&e.jsx("span",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:j}),e.jsxs("button",{onClick:L,disabled:v,className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-semibold text-white disabled:opacity-50",style:{background:"#3B82F6"},children:[v?e.jsx(S,{className:"w-4 h-4 animate-spin"}):e.jsx(Z,{className:"w-4 h-4"}),"Salvar"]})]})]}),e.jsxs("div",{className:"p-3 rounded-lg mb-4 text-xs",style:{background:"rgba(59,130,246,0.08)",border:"1px solid rgba(59,130,246,0.25)",color:"var(--page-text)"},children:[e.jsx("strong",{children:"White-label:"})," motoristas e embarcadores recebem mensagens em nome da ",e.jsx("strong",{children:"sua"})," transportadora â Sentinel 365 nunca aparece pra eles. Campos vazios usam o default."]}),e.jsx("div",{className:"space-y-3",children:I.map(a=>{const n=E[a.key]||"",c=t[a.key]||"",i=o[a.key]??"",A=!!n,D=i!==n;return e.jsxs("div",{className:"p-3 rounded-lg",style:{background:"var(--page-surface)",border:"1px solid var(--page-border)"},children:[e.jsx("div",{className:"flex items-start justify-between mb-1",children:e.jsxs("label",{className:"text-sm font-medium",style:{color:"var(--page-text)"},children:[a.label,A&&e.jsx("span",{className:"ml-2 text-[10px] px-2 py-0.5 rounded-full",style:{background:"rgba(245,158,11,0.15)",color:"#F59E0B"},children:"custom"}),D&&e.jsx("span",{className:"ml-1 text-[10px] px-2 py-0.5 rounded-full",style:{background:"rgba(59,130,246,0.15)",color:"#3B82F6"},children:"editado"})]})}),e.jsx("div",{className:"text-xs mb-2",style:{color:"var(--page-text-muted)"},children:a.description}),e.jsx("input",{type:"text",value:i,onChange:B=>m({...o,[a.key]:B.target.value}),placeholder:a.placeholder,className:"w-full px-3 py-2 rounded-md text-sm",style:{background:"var(--page-bg)",border:"1px solid var(--page-border)",color:"var(--page-text)"}}),e.jsxs("div",{className:"flex items-center justify-between mt-1.5 text-[11px]",children:[e.jsxs("span",{style:{color:"var(--page-text-muted)"},children:["Valor atual em uso: ",e.jsx("span",{className:"font-mono",style:{color:"var(--page-text)"},children:c||"â"})]}),i&&e.jsxs("button",{onClick:()=>m({...o,[a.key]:""}),className:"flex items-center gap-1 hover:underline",style:{color:"var(--page-text-secondary)"},children:[e.jsx(ee,{className:"w-3 h-3"}),"Limpar"]})]})]},a.key)})})]})}export{he as default};
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.