1import{r as a,j as e}from"./react-vendor-pafHdoJx.js";import{u as T,d as y}from"./index-Db0fDLGN.js";import{S as I}from"./SendWhatsAppButton-DIwBEhQG.js";import{E as M}from"./ErrorState-B9i6eo2M.js";import{i as A,W as B}from"./whatsapp-shared-BYiuVwmW.js";import{M as D,as as $,o as F,L,a as W,aq as q,b as K,D as _}from"./ui-vendor-DLXJn6s3.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";function ee(){const{toast:r}=T(),[l,o]=a.useState([]),[t,x]=a.useState(null),[i,u]=a.useState([]),[c,b]=a.useState(!1),[j,N]=a.useState(!1),[m,w]=a.useState(""),[h,S]=a.useState(!1),[g,k]=a.useState(null),[C,E]=a.useState(null),[v,R]=a.useState(!1),p=a.useRef(null),n=a.useCallback(async()=>{b(!0);try{const s=await y.waInboxList(100);o(s.conversations||[]),k(null),R(!1)}catch(s){A(s)?R(!0):k(s)}finally{b(!1)}},[]),f=a.useCallback(async s=>{N(!0),E(null);try{const d=await y.waInboxGet(s);u(d.history||[]),n()}catch(d){E(d)}finally{N(!1)}},[n]);a.useEffect(()=>{if(n(),v)return;const s=setInterval(n,3e4);return()=>clearInterval(s)},[n,v]),a.useEffect(()=>{t&&f(t)},[t,f]),a.useEffect(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight)},[i]);const H=async()=>{if(!(!t||!m.trim())){S(!0);try{await y.waInboxReply(t,m.trim()),w(""),await f(t),r({title:"Mensagem enviada",kind:"success"})}catch(s){r({title:"Falha ao enviar",description:(s==null?void 0:s.message)||"erro desconhecido",kind:"error"})}finally{S(!1)}}};return v?e.jsx(B,{}):e.jsxs("div",{className:"flex h-[calc(100vh-200px)] gap-3 rounded-xl overflow-hidden border",style:{borderColor:"var(--page-border)"},children:[e.jsxs("div",{className:"w-72 flex-shrink-0 flex flex-col",style:{background:"var(--page-surface)"},children:[e.jsxs("div",{className:"px-3 py-2 border-b flex items-center justify-between gap-2",style:{borderColor:"var(--page-border)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(D,{className:"w-4 h-4 flex-shrink-0",style:{color:"var(--page-text-secondary)"}}),e.jsxs("span",{className:"text-sm font-medium truncate",style:{color:"var(--page-text)"},children:["Conversas (",l.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx(I,{variant:"new",refType:"inbox_new",onSent:()=>n()}),e.jsx("button",{onClick:n,disabled:c,className:"p-1 rounded hover-surface",children:e.jsx($,{className:`w-3.5 h-3.5 ${c?"animate-spin":""}`,style:{color:"var(--page-text-muted)"}})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[g&&e.jsx("div",{className:"p-2",children:e.jsx(M,{inline:!0,error:g,onRetry:n,title:"Falha ao carregar conversas"})}),l.length===0&&!c&&!g&&e.jsx("div",{className:"p-4 text-center text-xs",style:{color:"var(--page-text-muted)"},children:"Nenhuma conversa ainda. Quando motoristas/embarcadores enviarem mensagem, aparecem aqui."}),l.map(s=>e.jsxs("button",{onClick:()=>x(s.phoneHashed),className:`w-full text-left px-3 py-2.5 border-b transition-colors ${t===s.phoneHashed?"bg-blue-500/10":"hover-surface"}`,style:{borderColor:"var(--page-border)"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[e.jsxs("span",{className:"text-xs font-mono font-medium truncate",style:{color:"var(--page-text)"},children:[s.phoneHashed.slice(0,12),"â¦"]}),s.unread>0&&e.jsx("span",{className:"text-[10px] font-bold px-1.5 py-0.5 rounded-full",style:{background:"#EF4444",color:"#fff"},children:s.unread})]}),s.lastMessage&&e.jsxs("div",{className:"text-xs truncate",style:{color:"var(--page-text-secondary)"},children:[e.jsx("span",{className:"opacity-60",children:s.lastMessage.role==="driver"?"â ":s.lastMessage.role==="bot"?"ð¤ ":"â "}),s.lastMessage.text]}),e.jsxs("div",{className:"text-[10px] mt-0.5 flex items-center gap-1",style:{color:"var(--page-text-muted)"},children:[e.jsx(F,{className:"w-2.5 h-2.5"}),Q(s.lastTurnAt)]})]},s.phoneHashed))]})]}),e.jsx("div",{className:"flex-1 flex flex-col",style:{background:"var(--page-surface)"},children:t?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-4 py-2.5 border-b flex items-center justify-between",style:{borderColor:"var(--page-border)"},children:e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-medium font-mono",style:{color:"var(--page-text)"},children:[t.slice(0,16),"â¦"]}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:[i.length," mensagens · phone hash SHA-256"]})]})}),e.jsxs("div",{ref:p,className:"flex-1 overflow-y-auto p-4 space-y-2",children:[j&&e.jsx("div",{className:"text-center py-4",children:e.jsx(L,{className:"w-4 h-4 animate-spin inline",style:{color:"var(--page-text-muted)"}})}
1),C&&!j&&e.jsx(M,{inline:!0,error:C,onRetry:()=>f(t),title:"Falha ao carregar o histórico"}),i.map((s,d)=>e.jsx(G,{turn:s},d))]}),e.jsxs("div",{className:"border-t p-3 flex gap-2",style:{borderColor:"var(--page-border)"},children:[e.jsx("input",{type:"text",value:m,onChange:s=>w(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),H())},placeholder:"Responder manualmente...",disabled:h,className:"flex-1 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("button",{onClick:H,disabled:h||!m.trim(),className:"px-4 py-2 rounded-md text-sm font-medium flex items-center gap-2 disabled:opacity-50",style:{background:"#10B981",color:"#fff"},children:[h?e.jsx(L,{className:"w-4 h-4 animate-spin"}):e.jsx(W,{className:"w-4 h-4"}),"Enviar"]})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-sm",style:{color:"var(--page-text-muted)"},children:"Selecione uma conversa pra ver o histórico."})})]})}function G({turn:r}){const l=r.role==="driver",o=r.role==="bot",t=r.role==="human_admin",x=l?"rgba(148,163,184,0.15)":o?"rgba(59,130,246,0.15)":"rgba(16,185,129,0.15)",i=l?"self-start":"self-end",u=l?e.jsx(q,{className:"w-3 h-3"}):o?e.jsx(K,{className:"w-3 h-3"}):e.jsx(_,{className:"w-3 h-3"}),c=l?"Motorista":o?"Bot Sentinel":t?"Você (manual)":r.role;return e.jsxs("div",{className:`max-w-[80%] ${i} flex flex-col`,children:[e.jsxs("div",{className:"flex items-center gap-1 text-[10px] mb-0.5 px-1",style:{color:"var(--page-text-muted)"},children:[u,e.jsx("span",{children:c}),e.jsxs("span",{className:"opacity-60",children:["· ",U(r.at)]})]}),e.jsx("div",{className:"px-3 py-2 rounded-lg text-sm whitespace-pre-wrap break-words",style:{background:x,color:"var(--page-text)"},children:r.text})]})}function Q(r){if(!r)return"â";const l=Date.now()-r,o=Math.floor(l/6e4);if(o<1)return"agora";if(o<60)return`${o}m`;const t=Math.floor(o/60);return t<24?`${t}h`:`${Math.floor(t/24)}d`}function U(r){return new Date(r).toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}export{ee 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.