PageSourceSearch

https://chatmerge.ai/assets/NeedsReply-BJMEPLP_.js

js chatmerge.ai collected 2026-10-05 13:03:18 UTC 49,025 bytes, 1 lines download raw bytes

1import{r as l,p as Ye,j as e,Q as Ce,_ as Xe,I as $e,b as Ie,u as L,c as v,m as Je,t as Q,A as oe,z as Me,T as et,h as Ae,k as F,i as C,d as Re,C as Le,g as Fe,$ as tt,P as qe,a as nt,n as ie,a0 as st}from"./index-aQ_xt8mz.js";import{w as X}from"./constants-CgJ2iP0H.js";import{p as at}from"./ArrowBendUpLeft.es-DdqutsbZ.js";import{a as de}from"./ChannelIcon-CKODN6Qv.js";import{E as ze}from"./EmptyState-Cnrkqejs.js";import{n as rt}from"./ArrowSquareOut.es-B5bi_1bu.js";import{c as le}from"./Info.es-CI0jadjD.js";import{a as ot,u as it,e as lt,S as dt}from"./useComposerBox-BcsOeusB.js";import{t as ct,T as se}from"./TagLabels-CsrUDShG.js";import{s as mt}from"./CaretRight.es-CM0hqBPF.js";import"./ArrowDown.es-CAKXuIql.js";import"./ArrowUp.es-Dcd21_4R.js";import"./Circle.es-_CWj2UqI.js";import"./Minus.es-CHwQzEn_.js";import"./PauseCircle.es-CXWCzZyN.js";const ut=new Map([["bold",l.createElement(l.Fragment,null,l.createElement("path",{d:"M128,20a108,108,0,0,0,0,216c22.27,0,45.69-6.73,62.64-18a12,12,0,1,0-13.29-20c-13,8.63-31.89,14-49.35,14a84,84,0,1,1,84-84c0,9.29-1.67,17.08-4.69,21.95-2.64,4.24-6,6.05-11.31,6.05s-8.67-1.81-11.31-6.05c-3-4.87-4.69-12.66-4.69-21.95V88a12,12,0,0,0-23.49-3.46,52,52,0,1,0,8.86,79.57C172.3,174.3,182.81,180,196,180c24.67,0,40-19.92,40-52A108.12,108.12,0,0,0,128,20Zm0,136a28,28,0,1,1,28-28A28,28,0,0,1,128,156Z"}))],["duotone",l.createElement(l.Fragment,null,l.createElement("path",{d:"M224,128a96,96,0,1,1-96-96A96,96,0,0,1,224,128Z",opacity:"0.2"}),l.createElement("path",{d:"M128,24a104,104,0,0,0,0,208c21.51,0,44.1-6.48,60.43-17.33a8,8,0,0,0-8.86-13.33C166,210.38,146.21,216,128,216a88,88,0,1,1,88-88c0,26.45-10.88,32-20,32s-20-5.55-20-32V88a8,8,0,0,0-16,0v4.26a48,48,0,1,0,5.93,65.1c6,12,16.35,18.64,30.07,18.64,22.54,0,36-17.94,36-48A104.11,104.11,0,0,0,128,24Zm0,136a32,32,0,1,1,32-32A32,32,0,0,1,128,160Z"}))],["fill",l.createElement(l.Fragment,null,l.createElement("path",{d:"M232,128c0,.51,0,1,0,1.52-.34,14.26-5.63,30.48-28,30.48-23.14,0-28-17.4-28-32V88a8,8,0,0,0-8.53-8A8.17,8.17,0,0,0,160,88.27v4a48,48,0,1,0,6.73,64.05,40.19,40.19,0,0,0,3.38,5C175.48,168,185.71,176,204,176a54.81,54.81,0,0,0,9.22-.75,4,4,0,0,1,4.09,6A104.05,104.05,0,0,1,125.91,232C71.13,230.9,26.2,186.86,24.08,132.11A104,104,0,1,1,232,128ZM96,128a32,32,0,1,0,32-32A32,32,0,0,0,96,128Z"}))],["light",l.createElement(l.Fragment,null,l.createElement("path",{d:"M128,26a102,102,0,0,0,0,204c21.13,0,43.31-6.35,59.32-17a6,6,0,0,0-6.65-10c-13.9,9.25-34.09,15-52.67,15a90,90,0,1,1,90-90c0,29.58-13.78,34-22,34s-22-4.42-22-34V88a6,6,0,0,0-12,0v9a46,46,0,1,0,4.34,56.32C171.76,166.6,182,174,196,174c21.29,0,34-17.2,34-46A102.12,102.12,0,0,0,128,26Zm0,136a34,34,0,1,1,34-34A34,34,0,0,1,128,162Z"}))],["regular",l.createElement(l.Fragment,null,l.createElement("path",{d:"M128,24a104,104,0,0,0,0,208c21.51,0,44.1-6.48,60.43-17.33a8,8,0,0,0-8.86-13.33C166,210.38,146.21,216,128,216a88,88,0,1,1,88-88c0,26.45-10.88,32-20,32s-20-5.55-20-32V88a8,8,0,0,0-16,0v4.26a48,48,0,1,0,5.93,65.1c6,12,16.35,18.64,30.07,18.64,22.54,0,36-17.94,36-48A104.11,104.11,0,0,0,128,24Zm0,136a32,32,0,1,1,32-32A32,32,0,0,1,128,160Z"}))],["thin",l.createElement(l.Fragment,null,l.createElement("path",{d:"M128,28a100,100,0,0,0,0,200c20.76,0,42.52-6.23,58.21-16.66a4,4,0,1,0-4.43-6.67C167.35,214.27,147.24,220,128,220a92,92,0,1,1,92-92c0,31.32-15,36-24,36s-24-4.68-24-36V88a4,4,0,0,0-8,0v14.75a44,44,0,1,0,2.82,45.94C171.46,163.58,181.66,172,196,172c20,0,32-16.45,32-44A100.11,100.11,0,0,0,128,28Zm0,136a36,36,0,1,1,36-36A36,36,0,0,1,128,164Z"}))]]),Pe=l.forwardRef((t,s)=>l.createElement(Ye,{ref:s,...t,weights:ut}));Pe.displayName="AtIcon";const xt=Pe,pt=10;function De(t,s=Date.now()){return t.target.lens!=="bot"?null:t.botOutcome==="FAILED"?"failed":t.botOutcome==="ANSWERED"||t.doneVia==="BOT_ANSWERED"?"answered":t.status!=="OPEN"?null:J(t,s)>pt?"silent":"waiting"}function ke(t){if(t.status==="DISMISSED")return t.doneVia==="CUSTOMER"?"Marked as a customer":"Marked not for you";switch(t.doneVia){case"REPLY":return"Answered in the group";case"QUOTE":return"Quoted in a reply";case"BOT_ANSWERED":return"The bot answered";case"TICKET":return"Ticket raised";case"MANUAL":return"Marked done";default:return"Done"}}const ht=240,J=(t,s=Date.now())=>Math.max(0,Math.round((s-Date.parse(t.mentionedAt))/6e4)),gt=(t,s=Date.now())=>t.status==="OPEN"&&J(t,s)>=ht;function bt(t){switch(t.target.lens){case"me":return"Me";case"bot":return"Bot";case"team":return(t.target.name||t.target.handle||"Teammate").split(" ")[0];default:return t.target.label||t.target.handle}}function ae(t,s){const r=t.findIndex(n=>n.id===s);return r<0?null:(t[r+1]||t[r-1]||{id:null}).id}function ft(t,s,r=3,n=3){const u=t.findIndex(c=>c.id===s);if(u<0)return{lines:[],at:-1,found:!1};const g=Math.max(0,u-r);return{lines:t.slice(g,u+1+n),at:u-g,found:!0}}const Se=["#c0391b","#6d4bc0","#0f7a6e","#2657c9","#b25b07","#a3336f","#3d6b1f"];function yt(t){let s=2166136261;for(const r of String(t||"?"))s^=r.charCodeAt(0),s=Math.imul(s,16777619);return Se[(s>>>0)%Se.length]}const jt=t=>t?t.me+t.bot:0;function Oe({text:t,labels:s}){return e.jsx(e.Fragment,{children:ct(t,s).map((r,n)=>r.tag?e.jsx("mark",{className:"rounded bg-amber-200/70 px-0.5 font-medium text-amber-950 dar
1k:bg-amber-400/25 dark:text-amber-100",children:r.text},n):e.jsx("span",{children:r.text},n))})}function Nt({m:t}){const s=t.target.lens,r=s==="me"?"bg-primary/10 text-primary":s==="bot"?"bg-violet-100 text-violet-700 dark:bg-violet-950/50 dark:text-violet-300":s==="team"?"bg-blue-100 text-blue-700 dark:bg-blue-950/50 dark:text-blue-300":"border border-dashed border-muted-foreground/60 font-mono text-[11px] font-medium text-muted-foreground";return e.jsxs("span",{className:`inline-flex h-5 shrink-0 items-center gap-1 rounded-full px-2 text-[11.5px] font-semibold ${r}`,children:[s==="bot"&&e.jsx(Xe,{size:11}),bt(t)]})}function wt({m:t,now:s}){const r=De(t,s);if(!r)return null;const n="inline-flex h-5 shrink-0 items-center gap-1 rounded-full px-2 text-[11.5px] font-semibold";return r==="failed"?t.status==="OPEN"?e.jsxs("span",{className:`${n} bg-red-100 text-red-700 dark:bg-red-950/50 dark:text-red-300`,children:[e.jsx($e,{size:11})," Couldn’t answer"]}):e.jsx("span",{className:`${n} bg-muted text-muted-foreground`,children:"Handed to a person"}):r==="answered"?e.jsxs("span",{className:`${n} bg-emerald-100 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300`,children:[e.jsx(Ie,{size:11})," Answered"]}):r==="silent"?e.jsx("span",{className:`${n} border border-dashed border-muted-foreground/60 font-medium text-muted-foreground`,children:"No bot reply"}):e.jsx("span",{className:`${n} bg-amber-100 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300`,children:"Waiting"})}function Ke({name:t,team:s}){return e.jsx("span",{className:`grid h-8 w-8 shrink-0 place-items-center rounded-full text-[13px] font-semibold text-white ${s?"":"bg-muted-foreground/70"}`,style:s?{background:yt(t)}:void 0,"aria-hidden":"true",children:(t||"?").trim().charAt(0).toUpperCase()})}function vt({m:t,selected:s,now:r,onOpen:n}){const u=t.status==="OPEN",g=gt(t,r);return e.jsxs("li",{role:"option","aria-selected":s,tabIndex:0,"data-mention":t.id,onClick:n,onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&c.target===c.currentTarget&&(c.preventDefault(),n())},className:`relative grid cursor-pointer grid-cols-[2rem_minmax(0,1fr)_auto] gap-x-3 gap-y-1 border-b border-border px-4 py-3 hover:bg-accent/40 sm:px-5 ${s?"bg-accent/60":""} ${u?"":"opacity-65"}`,children:[s&&e.jsx("span",{className:"absolute inset-y-0 left-0 w-[3px] bg-primary","aria-hidden":"true"}),e.jsx(Ke,{name:t.from.name,team:t.from.isTeam}),e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-[13px]",children:[e.jsx("b",{className:"truncate font-semibold",children:t.from.name||"Someone"}),e.jsxs("span",{className:"truncate text-muted-foreground",children:["· ",t.groupName||(t.private?"Private chat":"Group")]}),e.jsx(de,{channel:t.channel,size:12}),t.private&&e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(Ce,{size:11})," private"]})]}),e.jsx("span",{className:`font-mono text-xs tabular-nums ${g?"font-semibold text-amber-600 dark:text-amber-400":"text-muted-foreground"}`,title:`Tagged ${new Date(t.mentionedAt).toLocaleString()}`,children:u?X(J(t,r)):"done"}),e.jsxs("div",{className:"col-span-2 col-start-2 flex min-w-0 items-start gap-2",children:[e.jsx(Nt,{m:t}),e.jsx("p",{className:"line-clamp-2 min-w-0 flex-1 text-[13px] text-muted-foreground",children:e.jsx(Oe,{text:t.snippet,labels:t.tags})}),e.jsx(wt,{m:t,now:r})]})]})}const We=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),kt=l.forwardRef(function(s,r){const{m:n}=s,[u,g]=l.useState(""),c=l.useRef(null),p=ot();it(c,u),l.useImperativeHandle(r,()=>({focusReply:()=>{var d;return(d=c.current)==null?void 0:d.focus()}}),[]),l.useEffect(()=>{g("")},[n.id]);const{data:m,isLoading:j}=L({queryKey:["mention-context",n.groupId,n.messageId],queryFn:()=>v.get(`/groups/${n.groupId}/activity`,{params:{limit:200}}).then(d=>ft(d.data.data||[],n.messageId)).catch(()=>({lines:[],at:-1,found:!1})),enabled:!!n.groupId&&!!n.messageId,staleTime:3e4}),x=((m==null?void 0:m.lines)||[]).map(d=>d.content||"").filter(d=>/@\d|tg:\/\/user/.test(d)),{data:i}=L({queryKey:["mention-context-labels",n.groupId,n.messageId,x.length],queryFn:()=>v.post("/mentions/labels",{groupId:n.groupId,texts:x}).then(d=>d.data.data||{}).catch(()=>({})),enabled:!!n.groupId&&x.length>0,staleTime:6e4}),b={...n.tags||{},...i||{}},N=De(n,s.now),k=n.status==="OPEN",w=n.target.lens==="bot"?"the assistant bot":n.target.lens==="unknown"?n.target.handle:n.target.name||n.target.handle,S=s.canWrite&&k&&!!n.groupId&&n.target.lens!=="unknown",I=()=>{const d=u.trim();d&&!s.busy.reply&&s.onReply(d)};return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-3 border-b border-border bg-background px-4 py-3 sm:px-5",children:[e.jsx("button",{onClick:s.onBack,className:"rounded-md p-1.5 hover:bg-accent lg:hidden","aria-label":"Back to the list",children:e.jsx(Je,{size:16})}),e.jsxs("div",{className:"min-w-[12rem] flex-1",children:[e.jsxs("h2",{className:"text-[15px] font-semibold",children:[n.from.name||"Someone"," tagged ",e.jsx("span",{className:"font-semibold",children:w})]}),e.jsxs("p",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground",children:[e.jsx(de,{channel:n.channel,size:12}),e.jsx("span",{children:n.groupName||(n.private?"A private chat":"A group")}),e.jsxs("span",{children:["· ",k?`waiting ${X(J(n,s.now))}`:ke(n)]})]})]}),e.jsx("span",{className:`rounded-full px-2.5 py-0.5 text-[11.5px] font-semibold ${k?"bg-amber-100 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300":"bg-emerald-100 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300"}`,children:k?"Open":"Done"})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[n.private&&e.jsxs(re,{tone:"violet",icon:e.jsx(Ce,{size:14}),children:[e.jsx("b",{children:"Private."})," This was said in a chat with you. Only you see it here."]}),N==="failed"&&k&&e.jsxs(re,{tone:"red",icon:e.jsx($e,{size:14}),children:[e.jsx("b",{children:"The bot couldn’t answer."})," A customer is waiting for a person. Answer below, or open the group."]}),n.target.lens==="unknown"&&e.jsxs(re,{tone:"amber",icon:e.jsx(le,{size:14}),children:[e.jsxs("b",{children:["We don’t know who ",n.target.handle," is."]})," ",s.canResolve?e.jsxs(e.Fragment,{children:["Say who it is and every tag of them is placed at once."," ",e.jsx("button",{onClick:d=>s.onResolve(d.currentTarget),className:"font-medium underline",children:"Who is this?"})]}):"Ask a team manager to say who it is."]}),e.jsxs("div",{className:"flex flex-col gap-2 px-4 py-4 sm:px-5","aria-label":"The conversation around it",children:[j&&e.jsxs("p",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(Q,{size:12,className:"animate-spin"})," Reading the conversation…"]}),m!=null&&m.found?m.lines.map((d,$)=>e.jsx(Te,{line:d,hit:$===m.at,lens:n.target.lens,labels:b},d.id)):!j&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{line:{id:n.id,senderName:n.from.name,content:n.snippet,timestamp:n.mentionedAt,isTeamMember:n.from.isTeam},hit:!0,lens:n.target.lens,labels:b}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The lines around it are too far back to show here. Open the group to read them."})]})]}),n.questionId&&k&&e.jsxs("p",{className:"flex items-center gap-1.5 px-4 pb-2 text-xs text-muted-foreground sm:px-5",children:[e.jsx(le,{size:12})," Also raised as a question in ",e.jsx("b",{children:"Questions"})," — answering in the group closes both."]}),e.jsxs("ul",{className:"space-y-1 px-4 pb-3 text-[12.5px] text-muted-foreground sm:px-5",children:[e.jsxs(V,{tone:"plain",at:n.mentionedAt,children:[n.from.name||"Someone"," tagged ",n.target.lens==="bot"?"the bot":w]}),n.target.lens==="bot"&&N==="answered"&&e.jsx(V,{tone:"ok",children:"The bot answered"}),n.target.lens==="bot"&&N==="failed"&&e.jsx(V,{tone:"bad",children:"The bot could not answer from the knowledge base"}),n.target.lens==="bot"&&N==="silent"&&e.jsx(V,{tone:"plain",children:"The bot has not replied"}),!k&&e.jsx(V,{tone:"ok",at:n.doneAt,children:ke(n)})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-4 pb-4 sm:px-5",children:[k&&s.canWrite&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:s.onDone,disabled:s.busy.done,className:"inline-flex h-8 items-center gap-1.5 rounded-lg bg-primary px-3 text-[13px] font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[e.jsx(Ie,{size:13})," Done ",e.jsx(Ee,{children:"e"})]}),e.jsxs("button",{onClick:s.onDismiss,disabled:s.busy.dismiss,className:"inline-flex h-8 items-center gap-1.5 rounded-lg border border-input px-3 text-[13px] hover:bg-accent disabled:opacity-50",children:["Not for me ",e.jsx(Ee,{children:"x"})]}),n.source==="GROUP"&&e.jsxs("button",{onClick:s.onTicket,disabled:s.busy.ticket,className:"inline-flex h-8 items-center gap-1.5 rounded-lg border border-input px-3 text-[13px] hover:bg-accent disabled:opacity-50",children:[e.jsx(oe,{size:13})," Create ticket"]})]}),!k&&s.canWrite&&e.jsx("button",{onClick:s.onUndo,className:"inline-flex h-8 items-center rounded-lg border border-input px-3 text-[13px] hover:bg-accent",children:"Reo
1pen"}),n.groupId&&e.jsxs("button",{onClick:s.onOpenGroup,className:"inline-flex h-8 items-center gap-1.5 rounded-lg px-2 text-[13px] text-muted-foreground hover:bg-accent hover:text-foreground",children:[e.jsx(rt,{size:13})," Open in Group Monitor"]})]})]}),S&&e.jsxs("div",{className:"border-t border-border bg-background px-4 pb-3 pt-2.5 sm:px-5",children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx("textarea",{ref:c,value:u,onChange:d=>g(d.target.value),onKeyDown:d=>{lt(d,p)==="send"&&(d.preventDefault(),I())},rows:1,placeholder:n.target.lens==="bot"?"Answer as a person, in the group…":"Reply in the group, quoting this message…","aria-label":"Reply in the group",className:"min-h-[2.4rem] flex-1 resize-none rounded-xl border border-input bg-muted/30 px-3 py-2 text-sm leading-5 focus:border-primary"}),e.jsxs("button",{onClick:I,disabled:!u.trim()||s.busy.reply,className:"inline-flex h-[2.4rem] items-center gap-1.5 rounded-lg bg-primary px-3.5 text-sm font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[s.busy.reply?e.jsx(Q,{size:13,className:"animate-spin"}):e.jsx(Me,{size:13}),s.busy.reply?"Sending…":"Send"]})]}),e.jsxs("p",{className:"mt-1.5 flex flex-wrap gap-x-4 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:p?dt:"Enter for a new line"}),e.jsx("span",{children:"Sending closes this mention"})]})]})]})});function Ee({children:t}){return e.jsx("kbd",{className:"ml-0.5 hidden rounded border border-b-2 border-current/30 px-1 font-mono text-[10px] opacity-70 sm:inline",children:t})}function re({tone:t,icon:s,children:r}){const n=t==="violet"?"bg-violet-100/70 dark:bg-violet-950/40":t==="red"?"bg-red-100/70 dark:bg-red-950/40":"bg-amber-100/70 dark:bg-amber-950/40";return e.jsxs("div",{className:`mx-4 mt-3 flex gap-2.5 rounded-xl px-3 py-2.5 text-[13px] sm:mx-5 ${n}`,role:"note",children:[e.jsx("span",{className:"mt-0.5 shrink-0",children:s}),e.jsx("div",{children:r})]})}function V({tone:t,at:s,children:r}){const n=t==="ok"?"bg-emerald-500":t==="bad"?"bg-red-500":"bg-muted-foreground/60";return e.jsxs("li",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`h-2 w-2 shrink-0 rounded-full ${n}`,"aria-hidden":"true"}),e.jsx("span",{children:r}),s&&e.jsx("time",{className:"ml-auto font-mono text-[11px]",dateTime:s,children:We(s)})]})}function Te({line:t,hit:s,lens:r,labels:n}){const u=!!t.fromMe||!!t.isTeamMember,g=s?r==="me"?"ring-2 ring-primary":r==="team"?"ring-2 ring-blue-500":r==="bot"?"ring-2 ring-violet-500":"ring-2 ring-amber-500":"";return e.jsxs("div",{className:`flex max-w-[86%] items-start gap-2 ${u?"self-end":""}`,children:[!u&&e.jsx(Ke,{name:t.senderName,team:!1}),e.jsxs("div",{className:`rounded-2xl border px-3 py-2 text-sm ${u?"border-transparent bg-primary/10":"border-border bg-card"} ${g}`,children:[e.jsxs("p",{className:"mb-0.5 flex items-baseline justify-between gap-3 text-[11.5px] font-semibold text-muted-foreground",children:[e.jsx("span",{children:t.fromMe?"Us":t.senderName||"Someone"}),e.jsx("time",{className:"font-mono text-[10.5px] font-medium",dateTime:t.timestamp,children:We(t.timestamp)})]}),e.jsx("p",{className:"whitespace-pre-wrap break-words",children:e.jsx(Oe,{text:t.content||"(a file)",labels:n})})]})]})}function St({setup:t,needed:s,busy:r,onSave:n,onClose:u}){const[g,c]=l.useState((t==null?void 0:t.telegram)||""),[p,m]=l.useState((t==null?void 0:t.whatsapp)||"");l.useEffect(()=>{c((t==null?void 0:t.telegram)||""),m((t==null?void 0:t.whatsapp)||"")},[t==null?void 0:t.telegram,t==null?void 0:t.whatsapp]);const j=g.trim()!==((t==null?void 0:t.telegram)||"")||p.trim()!==((t==null?void 0:t.whatsapp)||"");return e.jsxs("form",{className:"m-3 rounded-xl border border-border bg-card p-4",onSubmit:x=>{x.preventDefault(),!(!j||r)&&n({...g.trim()!==((t==null?void 0:t.telegram)||"")?{telegram:g.trim()}:{},...p.trim()!==((t==null?void 0:t.whatsapp)||"")?{whatsapp:p.trim()}:{}})},children:[e.jsx("h3",{className:"text-sm font-semibold",children:"How do people tag you?"}),e.jsx("p",{className:"mb-3 mt-1 text-[13px] text-muted-foreground",children:s?"We can only tell a tag is for you once we know your Telegram username or WhatsApp number. Add it once and tags — including the ones already here — appear."
1:t!=null&&t.suggest?"We know your Telegram account, but not yet the @username people tag you by. It usually fills in by itself the next time you write in one of your groups — or add it here now.":"The username or number people type when they tag you. Change it here, or clear a field to stop matching it."}),(t==null?void 0:t.telegramLearned)&&e.jsxs("p",{className:"-mt-1.5 mb-3 text-[13px] text-muted-foreground",children:["Telegram says your username is ",e.jsx("span",{className:"font-medium text-foreground",children:t.telegramLearned}),", so tags of it already reach you. Add another here only if people tag you by a different one."]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{value:g,onChange:x=>c(x.target.value),placeholder:"Telegram @username","aria-label":"Telegram username",autoComplete:"off",className:"h-8 min-w-[11rem] flex-1 rounded-lg border border-input bg-background px-2.5 text-sm"}),e.jsx("input",{value:p,onChange:x=>m(x.target.value),placeholder:"WhatsApp number","aria-label":"WhatsApp number",inputMode:"tel",autoComplete:"off",className:"h-8 min-w-[11rem] flex-1 rounded-lg border border-input bg-background px-2.5 text-sm"}),e.jsxs("button",{type:"submit",disabled:!j||r,className:"inline-flex h-8 items-center gap-1.5 rounded-lg bg-primary px-3.5 text-[13px] font-semibold text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[r&&e.jsx(Q,{size:12,className:"animate-spin"})," Save"]}),u&&!s&&e.jsx("button",{type:"button",onClick:u,className:"h-8 rounded-lg px-2.5 text-[13px] text-muted-foreground hover:bg-accent",children:"Close"})]})]})}function Et({handles:t,total:s,onPick:r}){const[n,u]=l.useState(!1),[g,c]=l.useState(null);if(!s||!t.length)return null;const p=t.slice(0,2).map(m=>m.label||m.handle).join(", ");return e.jsxs("div",{className:"relative mx-3 mt-2.5 rounded-xl border border-dashed border-border bg-card",children:[e.jsxs("button",{onClick:()=>u(m=>!m),"aria-expanded":n,className:"flex w-full items-center gap-2 px-3 py-2 text-left text-[12.5px] text-muted-foreground",children:[e.jsx(le,{size:14,className:"shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[e.jsxs("b",{className:"text-foreground",children:[s," tag",s===1?"":"s"," of people we can’t place"]})," — ",p,t.length>2?"…":""]}),n?e.jsx(et,{size:14}):e.jsx(mt,{size:14})]}),n&&e.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 pb-2.5",children:t.map(m=>e.jsxs("button",{onClick:()=>c(m),className:"inline-flex h-[26px] items-center gap-1.5 rounded-full border border-dashed border-muted-foreground/60 px-2.5 font-mono text-xs text-muted-foreground hover:border-solid hover:bg-accent","aria-haspopup":"dialog",children:[m.label||m.handle," ",e.jsxs("small",{className:"font-sans text-[11px]",children:[m.count,"× · who is this?"]})]},`${m.channel}:${m.handle}`))}),g&&e.jsx(_e,{handle:g,onClose:()=>c(null),onPick:m=>{c(null),r(g,m)}})]})}function _e({handle:t,onPick:s,onClose:r,anchor:n}){const u=l.useRef(null),[g,c]=l.useState(""),{data:p=[],isLoading:m}=L({queryKey:["team-members"],queryFn:()=>v.get("/teams/members").then(x=>x.data).catch(()=>({data:[]})),select:x=>Array.isArray(x==null?void 0:x.data)?x.data:[],staleTime:6e4}),j=l.useMemo(()=>{const x=g.trim().toLowerCase();return p.filter(i=>!x||(i.name||"").toLowerCase().includes(x)||(i.email||"").toLowerCase().includes(x))},[p,g]);return l.useEffect(()=>{const x=b=>{var N;(N=u.current)!=null&&N.contains(b.target)||r()},i=b=>{b.key==="Escape"&&r()};return document.addEventListener("mousedown",x),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",i)}},[r]),e.jsxs("div",{ref:u,role:"dialog","aria-label":`Who is ${t.label||t.handle}?`,className:`z-40 w-72 rounded-xl border border-border bg-background p-2 shadow-lg ${n?"fixed":"absolute left-3 top-full mt-1"}`,style:n?{top:n.top,left:n.left}:void 0,children:[e.jsxs("p",{className:"px-2 pb-1 pt-0.5 text-[13px] font-semibold",children:["Who is ",t.label||t.handle,"?"]}),p.length>8&&e.jsx("input",{autoFocus:!0,value:g,onChange:x=>c(x.target.value),placeholder:"Find a teammate","aria-label":"Find a teammate",className:"mb-1 h-8 w-full rounded-lg border border-input bg-background px-2 text-sm"}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[m&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:"Loading the team…"}),j.map(x=>e.jsx("button",{onClick:()=>s({userId:x.id,name:x.name||"this person"}),className:"block w-full rounded-lg px-2 py-1.5 text-left text-sm hover:bg-accent",children:x.name||x.email},x.id)),!m&&!j.length&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:"Nobody by that name."})]}),e.jsx("div",{className:"my-1 h-px bg-border"}),e.jsx("button",{onClick:()=>s("customer"),className:"block w-full rounded-lg px-2 py-1.5 text-left text-sm hover:bg-accent",children:"It’s a customer — stop asking"})]})}const U={list:"mentions",counts:"mention-counts",unknown:"mention-unknown"},ce=3e4;function Ue(){return L({queryKey:[U.counts],queryFn:()=>v.get("/mentions/counts").then(t=>t.data.data),refetchInterval:ce})}function Tt(t){return L({queryKey:[U.list,t.lens,t.status,t.channel],queryFn:()=>v.get("/mentions",{params:{lens:t.lens,status:t.status==="done"?"done":"open",...t.status==="older"?{age:"older"}:{},...t.channel?{channel:t.channel}:{},limit:100}}).then(s=>s.data.data||[]),refetchInterval:ce})}function Ct(t){return L({queryKey:[U.unknown],queryFn:()=>v.get("/mentions/unknown").then(s=>s.data.data||[]),enabled:t,refetchInterval:ce})}const _=(t,s)=>{var r,n;return((n=(r=t==null?void 0:t.response)==null?void 0:r.data)==null?void 0:n.error)||s};function $t(t={}){const s=Ae(),r=()=>{s.invalidateQueries({queryKey:[U.list]}),s.invalidateQueries({queryKey:[U.counts]}),s.invalidateQueries({queryKey:[U.unknown]}),s.invalidateQueries({queryKey:["questions"]}),s.invalidateQueries({queryKey:["question-counts"]}),s.invalidateQueries({queryKey:["home-queue"]})},n=F({mutationFn:i=>v.post(`/mentions/${i}/undo`),onSuccess:r,onError:i=>C.error(_(i,"Could not put it back"))}),u=i=>F({mutationFn:b=>v.post(`/mentions/${b}/${i}`,{}),onSuccess:(b,N)=>{var k;r(),(k=t.onFinished)==null||k.call(t,N),C.success(i==="done"?"Marked done":"Marked not for you",{action:{label:"Undo",onClick:()=>n.mutate(N)}})},onError:b=>{var N;((N=b==null?void 0:b.response)==null?void 0:N.status)===409&&r(),C.error(_(b,"Could not update that mention"))}}),g=u("done"),c=u("dismiss"),p=F({mutationFn:i=>v.post(`/mentions/${i}/ticket`,{}).then(b=>{var N;return{id:i,...((N=b.data)==null?void 0:N.data)||{}}}),onSuccess:i=>{var b;r(),(b=t.onFinished)==null||b.call(t,i.id),C.success(i.alreadyTicketed?"That already has a ticket":`${i.ticketNumber||"Ticket"} raised`)},onError:i=>C.error(_(i,"The ticket could not be raised"))}),m=F({mutationFn:async({mention:i,text:b})=>{var k,w,S;const N=`/groups/${i.groupId}/send`;try{await v.post(N,{text:b,quoteMessageId:i.messageId})}
1catch(I){if(!(((k=I==null?void 0:I.response)==null?void 0:k.status)===400&&/quot/i.test(String(((S=(w=I==null?void 0:I.response)==null?void 0:w.data)==null?void 0:S.error)||""))))throw I;await v.post(N,{text:b})}return await v.post(`/mentions/${i.id}/done`,{via:"REPLY"}).catch(()=>{}),i.id},onSuccess:i=>{var b;r(),setTimeout(r,1500),(b=t.onFinished)==null||b.call(t,i),C.success("Sent to the group")},onError:i=>C.error(_(i,"The reply was not sent"))}),j=F({mutationFn:i=>v.post("/mentions/handles",{channel:i.channel,handle:i.handle,...i.customer?{customer:!0}:{userId:i.userId}}).then(b=>{var N;return{...((N=b.data)==null?void 0:N.data)||{},customer:!!i.customer,name:i.name}}),onSuccess:i=>{r(),C.success(i.customer?`${i.handle} is a customer — its tags are set aside`:`Linked ${i.handle}${i.name?` to ${i.name}`:""} — ${i.updated} tag${i.updated===1?"":"s"} placed`)},onError:i=>C.error(_(i,"Could not save that"))}),x=F({mutationFn:i=>v.put("/mentions/me/handles",i).then(b=>{var N;return((N=b.data)==null?void 0:N.data)||{}}),onSuccess:i=>{r();const b=[i.telegram,i.whatsapp].filter(Boolean).join(" and ");C.success(b?`Saved ${b} — tags of it will show here`:"Removed")},onError:i=>C.error(_(i,"Could not save that"))});return{done:g,dismiss:c,undo:n,ticket:p,reply:m,resolve:j,saveMine:x,refresh:r}}const It=[{key:"me",label:"Me"},{key:"bot",label:"Bot"},{key:"team",label:"Team"},{key:"all",label:"All"}],Mt=[{key:"TELEGRAM",label:"Telegram"},{key:"WHATSAPP",label:"WhatsApp"}],At={me:{open:["Nobody needs you right now","Nothing open is tagged to you."],done:["Nothing done yet","Tags you have handled show here."]},bot:{open:["The bot has nothing waiting","Every tag of the assistant has been answered or handled."],done:["Nothing done yet","Tags of the assistant that were handled show here."]},team:{open:["No open tags on your team","Every tag of a teammate has been answered."],done:["Nothing done yet","Tags of teammates that were handled show here."]},all:{open:["All clear","Nothing open is tagged to you, the bot or your team."],done:["Nothing done yet","Handled tags show here."]}},Rt="chatmerge_mentions_tag_hint_closed",Lt=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(min-width: 1024px)").matches;function Ft({tabs:t,active:s}){var ye;const r=Re(),[n]=Le(),{can:u}=Fe(),g=u("chats:write"),c=u("team:manage"),[p,m]=l.useState("me"),[j,x]=l.useState("open"),[i,b]=l.useState(""),[N,k]=l.useState(""),[w,S]=l.useState(null),[I,d]=l.useState(!1),$=(ye=tt())==null?void 0:ye.user,P=`${Rt}:${($==null?void 0:$.orgId)||""}:${($==null?void 0:$.id)||""}`,[O,B]=l.useState(null),H=O===P||(()=>{try{return window.localStorage.getItem(P)==="1"}catch{return!1}})(),D=()=>{B(P);try{window.localStorage.setItem(P,"1")}catch{}},[q,a]=l.useState(null),[f,T]=l.useState(()=>Date.now());l.useEffect(()=>{if(!s)return;T(Date.now());const o=setInterval(()=>T(Date.now()),3e4);return()=>clearInterval(o)},[s]);const ee=Ue(),K=Tt({lens:p,status:j,channel:i}),y=ee.data,Qe=Ct(c&&((y==null?void 0:y.unknown)??0)>0),G=l.useRef(null),A=$t({onFinished:o=>S(h=>h===o?Lt()?G.current:null:h)}),te=l.useRef(null),z=K.data,me=l.useMemo(()=>{const o=new Map;for(const h of z||[])h.groupId&&o.set(h.groupId,h.groupName||"A group");return[...o.entries()].sort((h,R)=>h[1].localeCompare(R[1]))},[z]),Y=me.some(([o])=>o===N)?N:"",M=l.useMemo(()=>Y?(z||[]).filter(o=>o.groupId===Y):z||[],[z,Y]),E=M.find(o=>o.id===w)||null,W=n.get("mention"),ue=l.useRef(null);l.useEffect(()=>{W&&ue.current!==W&&M.some(o=>o.id===W)&&(ue.current=W,S(W))},[W,M]),l.useEffect(()=>{var o,h;w&&((h=(o=document.querySelector(`[data-mention="${w}"]`))==null?void 0:o.scrollIntoView)==null||h.call(o,{block:"nearest"}))},[w]);const xe=o=>h=>{G.current=ae(M,h.id),o(h.id)},pe=xe(o=>A.done.mutate(o)),he=xe(o=>A.dismiss.mutate(o));l.useEffect(()=>{if(!s)return;const o=h=>{var Ne,we,ve;const R=h.target;if(h.metaKey||h.ctrlKey||h.altKey||q||(Ne=R==null?void 0:R.closest)!=null&&Ne.call(R,'input, textarea, select, [contenteditable="true"], [role="dialog"]'))return;const je=M.findIndex(Ge=>Ge.id===w);h.key==="j"?S(((we=M[je+1]||M[0])==null?void 0:we.id)??null):h.key==="k"?S(((ve=M[je-1]||M[M.length-1])==null?void 0:ve.id)??null):h.key==="e"&&E&&g&&E.status==="OPEN"?pe(E):h.key==="x"&&E&&g&&E.status==="OPEN"?he(E):h.key==="r"&&te.current&&(h.preventDefault(),te.current.focusReply())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)});const ne=!!(y!=null&&y.canSeeTeam),He=It.filter(o=>o.key!=="team"||ne),Ve=o=>y?o==="all"?y.me+y.bot+(ne?y.team:0):y[o]:0,Ze=!!(y!=null&&y.setup.suggest)&&!H,ge=!!y&&(p==="me"&&j==="open"&&(y.setup.needed||Ze)||I),be=At[p][j==="done"?"done":"open"],Be={done:A.done.isPending,dismiss:A.dismiss.isPending,ticket:A.ticket.isPending,reply:A.reply.isPending},fe=(o,h)=>A.resolve.mutate({...o,...h==="customer"?{customer:!0}:{userId:h.userId,name:h.name}});return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("header",{className:"border-b border-border px-4 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Needs reply"}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:ne?"Showing tags for you, the bot and your team":"Showing what is tagged to you and the bot"})]}),e.jsx("button",{onClick:()=>A.refresh(),className:"rounded-lg border border-input px-3 py-1.5 text-sm hover:bg-accent",children:"Refresh"})]}),t]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-border px-4 py-2.5 sm:px-6",children:[He.map(o=>{const h=p===o.key,R=Ve(o.key);return e.jsxs("button",{"aria-pressed":h,onClick:()=>{m(o.key),S(null)},className:`inline-flex h-[30px] items-center gap-1.5 rounded-full border px-3 text-[13px] ${h?`${o.key==="bot"?"border-violet-600 bg-violet-600":"border-primary bg-primary"} font-semibold text-white`:"border-input hover:bg-accent"}`,children:[o.label,R>0&&e.jsx("span",{className:`font-mono text-[11px] font-semibold ${h?"opacity-85":"text-muted-foreground"}`,children:R})]},o.key)}),e.jsx("span",{className:"mx-1 hidden h-5 w-px bg-border sm:block","aria-hidden":"true"}),Mt.map(o=>e.jsx("button",{"aria-pressed":i===o.key,onClick:()=>{b(i===o.key?"":o.key),S(null)},className:`h-[30px] rounded-lg border px-2.5 text-[12.5px] ${i===o.key?"border-transparent bg-primary/10 font-semibold text-primary":"border-input text-muted-foreground hover:bg-accent"}`,children:o.label},o.key)),e.jsxs("select",{value:Y,onChange:o=>{k(o.target.value),S(null)},"aria-label":"Group",className:"h-[30px] max-w-[12rem] rounded-lg border border-input bg-background px-2 text-[12.5px]",children:[e.jsx("option",{value:"",children:"Every group"}),me.map(([o,h])=>e.jsx("option",{value:o,children:h},o))]}),e.jsxs("select",{value:j,onChange:o=>{x(o.target.value),S(null)},"aria-label":"Status",className:"h-[30px] rounded-lg border border-input bg-background px-2 text-[12.5px]",children:[e.jsx("option",{value:"open",children:"Open"}),(((y==null?void 0:y.older)??0)>0||j==="older")&&e.jsxs("option",{value:"older",children:["Older than 2 weeks",y!=null&&y.older?` (${y.older})`:""]}),e.jsx("option",{value:"done",children:"Done"})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsx("div",{className:`min-h-0 w-full flex-col border-border lg:flex lg:w-[26rem] lg:shrink-0 lg:border-r xl:w-[28rem] ${E?"hidden":"flex"}`,children:e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[c&&p!=="team"&&e.jsx(Et,{handles:Qe.data||[],total:(y==null?void 0:y.unknown)??0,onPick:fe}),ge&&e.jsx(St,{setup:y==null?void 0:y.setup,needed:!!(y!=null&&y.setup.needed),busy:A.saveMine.isPending,onSave:o=>A.saveMine.mutate(o,{onSuccess:()=>d(!1)}),onClose:()=>{d(!1),y!=null&&y.setup.suggest&&D()}}),K.isLoading&&e.jsxs("div",{className:"flex items-center gap-2 p-6 text-sm text-muted-foreground",children:[e.jsx(Q,{size:14,className:"animate-spin"})," Looking for tags…"]}),K.isError&&e.jsxs("div",{className:"p-6 text-sm text-muted-foreground",children:["The list could not be loaded."," ",e.jsx("button",{onClick:()=>K.refetch(),className:"underline",children:"Try again"})]}),!K.isLoading&&!K.isError&&!M.length&&!ge&&e.jsx(ze,{icon:e.jsx(qe,{size:40}),title:be[0],description:be[1]}),e.jsx("ul",{role:"listbox","aria-label":"Mentions",children:M.map(o=>e.jsx(vt,{m:o,now:f,selected:o.id===w,onOpen:()=>S(o.id)},o.id))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1 px-4 pb-4 pt-3 text-xs text-muted-foreground sm:px-5",children:[((z==null?void 0:z.length)??0)>=100&&e.jsx("span",{children:"Showing the first 100."}),e.jsxs("span",{className:"hidden lg:inline",children:[e.jsx(Z,{children:"j"})," ",e.jsx(Z,{children:"k"})," move · ",e.jsx(Z,{children:"r"})," reply · ",e.jsx(Z,{children:"e"})," done · ",e.jsx(Z,{children:"x"})," not for me"]}),e.jsxs("button",{onClick:()=>d(o=>!o),className:"ml-auto inline-flex items-center gap-1 hover:text-foreground",children:[e.jsx(xt,{size:12})," How am I tagged?"]})]})]})}),e.jsx("div",{className:`min-h-0 min-w-0 flex-1 flex-col bg-muted/20 lg:flex ${E?"flex":"hidden"}
1`,children:E?e.jsx(kt,{ref:te,m:E,now:f,canWrite:g,canResolve:c,busy:Be,onBack:()=>S(null),onDone:()=>pe(E),onDismiss:()=>he(E),onUndo:()=>A.undo.mutate(E.id),onTicket:()=>{G.current=ae(M,E.id),A.ticket.mutate(E.id)},onReply:o=>{G.current=ae(M,E.id),A.reply.mutate({mention:E,text:o})},onOpenGroup:()=>r(`/groups?group=${E.groupId}`),onResolve:o=>{const h=o.getBoundingClientRect();a({handle:E.target.handle,channel:E.channel,anchor:{top:Math.min(h.bottom+6,window.innerHeight-380),left:Math.min(Math.max(8,h.left),window.innerWidth-300)}})}}):e.jsx("div",{className:"grid flex-1 place-items-center p-8 text-center text-sm text-muted-foreground",children:e.jsxs("div",{children:[e.jsx("b",{className:"mb-1 block text-foreground",children:"Pick a mention"}),"The conversation around it opens here, with the tag marked."]})})})]}),q&&e.jsx(_e,{handle:q,anchor:q.anchor,onClose:()=>a(null),onPick:o=>{fe(q,o),a(null)}})]})}function Z({children:t}){return e.jsx("kbd",{className:"rounded border border-b-2 border-border bg-background px-1 font-mono text-[10.5px]",children:t})}function qt({tab:t,onChange:s}){const{data:r}=L({queryKey:["question-counts"],queryFn:()=>v.get("/questions/counts").then(p=>p.data.data),refetchInterval:3e4}),{data:n}=Ue(),u=(r==null?void 0:r.all)??0,g=jt(n),c=(p,m,j,x)=>e.jsxs("button",{role:"tab","aria-selected":t===p,onClick:()=>s(p),className:`inline-flex items-center gap-2 rounded-lg px-3 py-1 text-sm ${t===p?"bg-background font-semibold text-foreground shadow-sm ring-1 ring-border":"text-muted-foreground hover:text-foreground"}`,children:[m,j>0&&e.jsx("span",{className:`inline-grid h-[18px] min-w-[18px] place-items-center rounded-full px-1.5 font-mono text-[11px] font-semibold ${t===p&&x?"bg-violet-100 text-violet-700 dark:bg-violet-950/60 dark:text-violet-300":"bg-muted text-muted-foreground"}`,children:j})]});return e.jsxs("div",{role:"tablist","aria-label":"What is waiting",className:"mt-3 inline-flex gap-0.5 rounded-xl bg-muted p-[3px]",children:[c("questions","Questions",u,!1),c("mentions","Mentions",g,!0)]})}const zt=[{key:"all",label:"All"},{key:"mine",label:"My groups"},{key:"late",label:"Past target"},{key:"unowned",label:"Nobody’s groups"}];function tn(){const[t,s]=Le(),r=t.get("tab")==="mentions"?"mentions":"questions",[n,u]=l.useState(r==="mentions");l.useEffect(()=>{r==="mentions"&&u(!0)},[r]);const g=p=>{s(m=>{const j=new URLSearchParams(m);return p==="mentions"?j.set("tab","mentions"):(j.delete("tab"),j.delete("mention")),j},{replace:!0})},c=e.jsx(qt,{tab:r,onChange:g});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:r==="questions"?"h-full":"hidden",children:e.jsx(Pt,{tabs:c})}),n&&e.jsx("div",{className:r==="mentions"?"h-full":"hidden",children:e.jsx(Ft,{tabs:c,active:r==="mentions"})})]})}function Pt({tabs:t}){var q;const s=Ae(),r=Re(),{can:n}=Fe(),[u,g]=l.useState("all"),[c,p]=l.useState(null),[m,j]=l.useState(""),[,x]=l.useState(0);l.useEffect(()=>{const a=setInterval(()=>x(f=>f+1),3e4);return()=>clearInterval(a)},[]);const{data:i,isLoading:b,isError:N,refetch:k}=L({queryKey:["questions",u],queryFn:()=>v.get("/questions",{params:{view:u}}).then(a=>a.data),refetchInterval:3e4}),{data:w}=L({queryKey:["question-counts"],queryFn:()=>v.get("/questions/counts").then(a=>a.data.data),refetchInterval:3e4}),S=(i==null?void 0:i.data)||[],I=(w==null?void 0:w.replyTargetMinutes)??((q=i==null?void 0:i.meta)==null?void 0:q.replyTargetMinutes)??30,d=l.useMemo(()=>S.find(a=>a.id===c)||null,[S,c]);l.useEffect(()=>{j("")},[c]);const{data:$}=L({queryKey:["question-context",d==null?void 0:d.id],queryFn:()=>v.get(`/groups/${d.groupId}/activity`,{params:{limit:40}}).then(a=>{const f=a.data.data||[],T=f.findIndex(ee=>ee.id===d.messageId);return{lines:T>0?f.slice(Math.max(0,T-3),T):[],tags:a.data.tags||{}}}).catch(()=>({lines:[],tags:{}})),enabled:!!(d!=null&&d.groupId)&&!!(d!=null&&d.messageId),staleTime:3e4}),P=($==null?void 0:$.lines)??[],O=()=>{s.invalidateQueries({queryKey:["questions"]}),s.invalidateQueries({queryKey:["question-counts"]}),s.invalidateQueries({queryKey:["home-queue"]})},B=F({mutationFn:({id:a,reason:f})=>v.post(`/questions/${a}/dismiss`,{reason:f}),onSuccess:(a,{id:f})=>{O(),c===f&&p(null),C.success("Taken off the list",{action:{label:"Undo",onClick:()=>v.post(`/questions/${f}/undo`).then(O).catch(()=>C.error("Could not put it back"))}})},onError:a=>{var f,T;return C.error(((T=(f=a.response)==null?void 0:f.data)==null?void 0:T.error)||"Could not update that question")}}),H=F({mutationFn:a=>v.post(`/questions/${a}/ticket`,{}),onSuccess:a=>{var T;O();const f=(T=a.data)==null?void 0:T.data;C.success(`${(f==null?void 0:f.ticketNumber)||"Ticket"} raised`,{action:{label:"Open it",onClick:()=>r(`/tickets?ticket=${f==null?void 0:f.ticketId}`)}})},onError:a=>{var f,T;return C.error(((T=(f=a.response)==null?void 0:f.data)==null?void 0:T.error)||"The ticket could not be raised")}}),D=F({mutationFn:async({question:a,text:f})=>a.kind==="GROUP"&&a.groupId?v.post(`/groups/${a.groupId}/send`,{text:f}):v.post(`/messages/reply/${a.chatId}`,{text:f,type:"TEXT"}),onSuccess:()=>{j(""),setTimeout(O,1200),C.success("Sent")},onError:a=>{var f,T;return C.error(((T=(f=a.response)==null?void 0:f.data)==null?void 0:T.error)||"The reply was not sent")}});return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("header",{className:"border-b border-border px-4 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Needs reply"}),e.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:w?`${w.all} waiting${w.late?` · ${w.late} past ${I} min`:""}`:"Everybody waiting for an answer, oldest first"})]}),e.jsx("button",{onClick:()=>k(),className:"rounded-lg border border-input px-3 py-1.5 text-sm hover:bg-accent",children:"Refresh"})]}),t,e.jsx("div",{className:"mt-3 flex flex-wrap gap-1",children:zt.map(a=>e.jsxs("button",{onClick:()=>g(a.key),className:`rounded-full px-3 py-1 text-sm ${u===a.key?"bg-primary text-primary-foreground":"hover:bg-accent"}`,children:[a.label,(w==null?void 0:w[a.key==="all"?"all":a.key])>0&&e.jsx("span",{className:`ml-1.5 text-xs ${u===a.key?"opacity-80":"text-muted-foreground"}`,children:w[a.key==="all"?"all":a.key]})]},a.key))})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsxs("div",{className:`min-h-0 flex-1 overflow-y-auto ${d?"hidden lg:block":""}`,children:[b&&e.jsxs("div",{className:"flex items-center gap-2 p-6 text-sm text-muted-foreground",children:[e.jsx(Q,{size:14,className:"animate-spin"})," Looking for anybody waiting…"]}),N&&e.jsxs("div",{className:"p-6 text-sm text-muted-foreground",children:["The list could not be loaded."," ",e.jsx("button",{onClick:()=>k(),className:"underline",children:"Try again"})]}),!b&&!N&&!S.length&&e.jsx(ze,{icon:e.jsx(qe,{size:40}),title:"All caught up",description:"No customer is waiting for a reply."}),e.jsx("ul",{className:"divide-y divide-border",children:S.map(a=>e.jsx("li",{onClick:()=>p(a.id),className:`group cursor-pointer px-4 py-3 hover:bg-accent/40 sm:px-6 ${c===a.id?"bg-accent/60":""}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:`mt-0.5 w-14 shrink-0 font-mono text-sm tabular-nums ${a.late?"text-red-600 dark:text-red-400":"text-amber-600 dar
1k:text-amber-400"}`,title:`Waiting since ${new Date(a.openedAt).toLocaleString()}`,children:X(a.waitingMinutes)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground",children:[a.channel&&e.jsx(de,{channel:a.channel,size:12}),e.jsx("span",{className:"font-medium text-foreground",children:a.groupName||"Direct conversation"}),a.senderName&&e.jsxs("span",{children:["· ",a.senderName]}),e.jsx("span",{className:"rounded-full bg-muted px-1.5 py-0.5",children:a.reason}),a.messageCount>1&&e.jsxs("span",{children:["· ",a.messageCount," messages"]}),a.ownerName?e.jsx("span",{className:"ml-auto",children:a.ownerName}):e.jsx("span",{className:"ml-auto italic",children:"Nobody owns this group"})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm",children:a.text?e.jsx(se,{text:a.text,labels:a.tags??{}}):a.hasMedia?"Sent a file with no message":"(no text)"})]}),n("chats:write")&&e.jsxs("div",{className:"hidden shrink-0 items-center gap-1 group-hover:flex",children:[e.jsx("button",{onClick:f=>{f.stopPropagation(),H.mutate(a.id)},className:"rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground",title:"Raise a ticket from this","aria-label":`Raise a ticket from ${a.senderName||"this message"}`,children:e.jsx(oe,{size:14})}),e.jsx("button",{onClick:f=>{f.stopPropagation(),p(a.id)},className:"rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground",title:"Reply","aria-label":"Reply",children:e.jsx(at,{size:14})}),e.jsx(Dt,{reasons:(w==null?void 0:w.dismissReasons)||[],busy:B.isPending,onPick:f=>B.mutate({id:a.id,reason:f})})]})]})},a.id))})]}),d&&e.jsxs("aside",{className:"flex min-h-0 w-full flex-col border-l border-border lg:w-[26rem]",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:d.groupName||"Direct conversation"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx(nt,{size:11,className:"mr-1 inline"}),d.senderName||"Someone"," has waited ",X(d.waitingMinutes)]})]}),e.jsx("button",{onClick:()=>p(null),className:"rounded-md p-1 hover:bg-accent","aria-label":"Close",children:e.jsx(ie,{size:16})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-card p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:d.senderName||"Someone"}),e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-sm",children:d.text?e.jsx(se,{text:d.text,labels:d.tags??{}}):d.hasMedia?"Sent a file with no message":"(no text)"})]}),e.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",children:["Picked up by: ",d.reason]}),P.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"mb-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"What came before"}),e.jsx("ol",{className:"space-y-1.5",children:P.map(a=>e.jsxs("li",{className:"rounded-lg border border-dashed border-border px-2.5 py-1.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a.fromMe?"Us":a.senderName||"Someone"}),e.jsx("p",{className:"line-clamp-2 text-xs",children:a.content?e.jsx(se,{text:a.content,labels:($==null?void 0:$.tags)??{}}):"(a file)"})]},a.id))})]}),d.groupId&&e.jsxs("button",{onClick:()=>r(`/groups?group=${d.groupId}`),className:"mt-3 inline-flex items-center gap-1.5 text-xs text-primary hover:underline",children:[e.jsx(st,{size:12})," Open the group to read what came before"]})]}),n("chats:write")&&e.jsxs("div",{className:"border-t border-border p-3",children:[e.jsx("textarea",{value:m,onChange:a=>j(a.target.value),onKeyDown:a=>{(a.metaKey||a.ctrlKey)&&a.key==="Enter"&&m.trim()&&D.mutate({question:d,text:m.trim()})},rows:3,placeholder:`Reply to ${d.groupName||d.senderName||"them"}…`,"aria-label":"Reply to this question",className:"w-full resize-none rounded-lg border border-input bg-background px-3 py-2 text-sm focus:border-primary"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>H.mutate(d.id),disabled:H.isPending,className:"inline-flex items-center gap-1.5 rounded-lg border border-input px-3 py-1.5 text-xs hover:bg-accent disabled:opacity-50",children:[e.jsx(oe,{size:12})," Raise a ticket"]}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"⌘↵ to send"}),e.jsxs("button",{onClick:()=>m.trim()&&D.mutate({question:d,text:m.trim()}),disabled:!m.trim()||D.isPending,className:"ml-auto inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50",children:[D.isPending?e.jsx(Q,{size:12,className:"animate-spin"}):e.jsx(Me,{size:12}),D.isPending?"Sending…":"Send"]})]})]})]})]})]})}function Dt({reasons:t,busy:s,onPick:r}){const[n,u]=l.useState(!1),g=l.useRef(null);return l.useEffect(()=>{if(!n)return;const c=m=>{var j;(j=g.current)!=null&&j.contains(m.target)||u(!1)},p=m=>{m.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",c),document.addEventListener("keydown",p),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",p)}},[n]),t.length?e.jsxs("div",{className:"relative",ref:g,onClick:c=>c.stopPropagation(),children:[e.jsx("button",{onClick:()=>u(c=>!c),disabled:s,"aria-expanded":n,"aria-haspopup":"true",className:"rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50",title:"Take it off the list","aria-label":"Take it off the list",children:e.jsx(ie,{size:14})}),n&&e.jsxs("div",{className:"absolute right-0 z-30 mt-1 w-64 roun
1ded-xl border border-border bg-background p-1.5 text-left shadow-lg",children:[e.jsx("p",{className:"px-2 pb-1 pt-0.5 text-[11px] text-muted-foreground",children:"Why is this not a question?"}),t.map(c=>e.jsxs("button",{onClick:()=>{u(!1),r(c.code)},className:"block w-full rounded-lg px-2 py-1.5 text-left hover:bg-accent",children:[e.jsx("span",{className:"block text-sm",children:c.label}),e.jsx("span",{className:"block text-[11px] leading-snug text-muted-foreground",children:c.hint})]},c.code))]})]}):e.jsx("button",{onClick:c=>{c.stopPropagation(),r("")},className:"rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground",title:"Not a question","aria-label":"Not a question",children:e.jsx(ie,{size:14})})}export{tn 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.