PageSourceSearch

https://orygofrontend-production.up.railway.app/_next/static/chunks/4538-ec47d0e938410056.js

js orygofrontend-production.up.railway.app collected 2026-10-03 12:16:08 UTC 126,744 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4538],{64538:(e,t,r)=>{r.d(t,{A:()=>eq});var s=r(37876),n=r(14232),l=r(48230),i=r.n(l),o=r(89099),a=r(30488),c=r(49301),d=r(9463),u=r(92146),x=r(72953),h=r(39822),p=r(1924),g=r(77362),m=r(76839),f=r(65955),j=r(43123),b=r(63132),y=r(8091),z=r(95563),v=r(70294),S=r(55102),C=r(84361),_=r(14741),w=r(53224),k=r(75306),E=r(44276),W=r(40811),T=r(77543),A=r(13376),R=r(94179),P=r(75656),D=r(34333),I=r(8863),H=r(72943);let N=e=>{let{user:t,loading:r}=(0,H.J)();return(0,P.Ay)(!r&&t&&e?["/fetch_inbox_macros?agent_id=".concat(e),t.accessToken]:null,e=>(0,I.we)(e).then(e=>e.data))},M=e=>{let{user:t,loading:r}=(0,H.J)();return(0,D.A)(!r&&t&&e?["/create_inbox_macro?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t;return(0,I.eh)(e,{arg:r})})},$=e=>{let{user:t,loading:r}=(0,H.J)();return(0,D.A)(!r&&t&&e?["/edit_inbox_macro?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t;return(0,I.wf)(e,{arg:r})})},X=e=>{let{user:t,loading:r}=(0,H.J)();return(0,D.A)(!r&&t&&e?["/delete_inbox_macro?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t;return(0,I.Nw)(e,{arg:r})})};var L=r(68831),F=r(23941),B=r(61385),K=r(82703),G=r(80161),O=r(12324),Y=r(25119),J=r(83239),U=r(40950),q=r(88293),V=r(4741),Q=r(26849),Z=r(51231),ee=r(34214);let et="Prepare a complete draft of the response, ready for an operator to review and send. Write only the message body — no preamble, options, or commentary.",er=e=>{let{instruction:t,onInstructionChange:r,onGenerate:n,onStop:l,isStreaming:i,isDisabled:o=!1,hasCurrentDraft:c,destination:d,instructionRef:g,hideTitle:f=!1}=e,{resolvedTheme:j}=(0,K.j)(),b=G.kY.blockBorderColor[j],y="dark"===j?"gray.400":"gray.500",v=()=>{if(o||i)return;let e=t.trim();return e?void n(e):c?void n(void 0):void n(et,{skipCurrentDraft:!0})},C=c?"Rewrite draft":"Draft reply",_="compose"===d?"The draft appears in the message field. Edit it there, then send.":"The draft appears in the reply box. Edit it there, then send.";return(0,s.jsxs)(p.T,{align:"stretch",gap:3,flex:1,minH:0,children:[!f&&(0,s.jsxs)(u.z,{gap:2,alignItems:"flex-start",children:[(0,s.jsx)(h.a,{mt:"2px",color:"purple.400",flexShrink:0,children:(0,s.jsx)(S.pCw,{size:16})}),(0,s.jsxs)(p.T,{align:"stretch",gap:.5,children:[(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"semibold",children:"Drafter"}),(0,s.jsx)(a.E,{fontSize:"2xs",color:y,lineHeight:"tall",children:_})]})]}),f&&(0,s.jsx)(a.E,{fontSize:"2xs",color:y,lineHeight:"tall",children:_}),(0,s.jsx)(m.T,{ref:g,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),v())},placeholder:"e.g. Convert the voucher to a gift card, keep it warm and concise",size:"sm",minH:"compose"===d?"80px":"120px",resize:"vertical",fontSize:"xs",borderColor:b,disabled:o||i}),c&&!i&&(0,s.jsxs)(a.E,{fontSize:"2xs",color:y,lineHeight:"tall",children:["The ","compose"===d?"message field":"reply box"," already has text. Drafter will rewrite it",t.trim()?" using your instructions":"","."]}),i?(0,s.jsx)(x.$,{size:"sm",variant:"outline",colorPalette:"red",onClick:l,w:"full",children:(0,s.jsxs)(u.z,{gap:2,children:[(0,s.jsx)(z.y,{size:"xs",color:"purple.400"}),(0,s.jsx)(a.E,{fontSize:"xs",children:"Stop"})]})}):(0,s.jsx)(x.$,{size:"sm",colorPalette:"purple",onClick:v,disabled:o,w:"full",title:"".concat(C," (Ctrl+Enter)"),children:(0,s.jsxs)(u.z,{gap:1.5,children:[(0,s.jsx)(S.pCw,{size:13}),(0,s.jsx)(a.E,{fontSize:"xs",children:C})]})}),i&&(0,s.jsxs)(a.E,{fontSize:"2xs",color:"purple.400",fontWeight:"medium",children:["Drafter is writing into the ","compose"===d?"message":"reply"," box…"]})]})},es=new Set(["escalate_to_inbox","send_to_inbox"]),en=["image/png","image/jpeg","image/webp","image/heic","image/heif","application/pdf","text/plain","text/csv"],el=e=>e.split(",").map(e=>e.trim()).filter(Boolean);var ei=r(29900),eo=r(98477);let ea=e=>{let{agentId:t,isOpen:r,onClose:l,onUseMacro:i,resolvedTheme:o}=e,[c,d]=(0,n.useState)(null),[f,j]=(0,n.useState)(!1),[b,y]=(0,n.useState)(""),[z,S]=(0,n.useState)(""),[C,_]=(0,n.use
1State)(""),w=(0,n.useRef)(null),k="dark"===o?"gray.700":"gray.200",E="dark"===o?"gray.800":"gray.50",W="dark"===o?"gray.400":"gray.500",{data:T,mutate:A}=N(t),{trigger:R,isMutating:P}=M(t),{trigger:D,isMutating:I}=$(t),{trigger:H}=X(t),L=null==T?void 0:T.filter(e=>e.title.toLowerCase().includes(C.toLowerCase())||e.content.toLowerCase().includes(C.toLowerCase())),F=()=>{d(null),j(!1),y(""),S("")},K=async()=>{if(b.trim()&&z.trim())try{await R({title:b.trim(),content:z.trim()}),A(),F(),B.X.create({title:"Macro created",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error creating macro",type:"error",duration:3e3,closable:!0})}},G=async()=>{if(c&&b.trim()&&z.trim())try{await D({macro_id:c.id,title:b.trim(),content:z.trim()}),A(),F(),B.X.create({title:"Macro updated",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error updating macro",type:"error",duration:3e3,closable:!0})}},O=async e=>{try{await H({macro_id:e}),A(),(null==c?void 0:c.id)===e&&F(),B.X.create({title:"Macro deleted",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error deleting macro",type:"error",duration:3e3,closable:!0})}};if((0,n.useEffect)(()=>{r||F()},[r]),!r||"undefined"==typeof document)return null;let Y=f||c;return(0,eo.createPortal)((0,s.jsx)(h.a,{ref:w,position:"fixed",top:0,left:0,right:0,bottom:0,bg:"blackAlpha.600",zIndex:1500,display:"flex",justifyContent:"flex-end",onClick:e=>{e.target===w.current&&l()},children:(0,s.jsxs)(h.a,{w:"50%",maxW:"700px",minW:"400px",h:"100%",bg:"dark"===o?"gray.900":"white",borderLeftWidth:"1px",borderColor:k,display:"flex",flexDirection:"column",boxShadow:"xl",children:[(0,s.jsxs)(u.z,{px:5,py:4,borderBottomWidth:"1px",borderColor:k,justifyContent:"space-between",children:[(0,s.jsxs)(u.z,{gap:2,children:[(0,s.jsx)(v.FrA,{size:18}),(0,s.jsx)(a.E,{fontWeight:"semibold",fontSize:"md",children:"Macros"})]}),(0,s.jsxs)(u.z,{gap:2,children:[!Y&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"blue",onClick:()=>{F(),j(!0)},children:[(0,s.jsx)(v.GGD,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"New Macro"})]}),(0,s.jsx)(x.$,{size:"xs",variant:"ghost",onClick:l,children:(0,s.jsx)(v.yGN,{size:16})})]})]}),Y?(0,s.jsx)(h.a,{flex:1,overflowY:"auto",px:5,py:4,children:(0,s.jsxs)(p.T,{gap:4,align:"stretch",children:[(0,s.jsx)(a.E,{fontWeight:"medium",fontSize:"sm",children:f?"Create New Macro":"Edit Macro"}),(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"xs",mb:1,color:W,fontWeight:"medium",children:"Title"}),(0,s.jsx)(g.p,{value:b,onChange:e=>y(e.target.value),placeholder:"e.g. Greeting, Follow-up, Closing...",size:"sm",autoFocus:!0})]}),(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"xs",mb:1,color:W,fontWeight:"medium",children:"Content"}),(0,s.jsx)(m.T,{value:z,onChange:e=>S(e.target.value),placeholder:"Type the macro message content...",size:"sm",minH:"150px",resize:"vertical"})]}),(0,s.jsxs)(u.z,{gap:2,children:[(0,s.jsx)(x.$,{size:"sm",colorPalette:"blue",onClick:f?K:G,disabled:!b.trim()||!z.trim()||P||I,loading:P||I,children:f?"Create":"Save"}),(0,s.jsx)(x.$,{size:"sm",variant:"ghost",onClick:F,children:"Cancel"})]})]})}):(0,s.jsxs)(h.a,{flex:1,display:"flex",flexDirection:"column",minH:0,children:[(0,s.jsx)(h.a,{px:5,py:3,borderBottomWidth:"1px",borderColor:k,children:(0,s.jsxs)(u.z,{px:3,py:1.5,borderWidth:"1px",borderRadius:"md",borderColor:k,gap:2,children:[(0,s.jsx)(v.CKj,{size:14,color:"dark"===o?"#A0AEC0":"#718096"}),(0,s.jsx)(g.p,{value:C,onChange:e=>_(e.target.value),placeholder:"Search macros...",size:"sm",variant:"flushed",fontSize:"sm",border:"none",borderBottom:"none",_focus:{boxShadow:"none",borderColor:"transparent"}})]})}),(0,s.jsx)(h.a,{flex:1,overflowY:"auto",px:5,py:3,children:L&&L.length>0?(0,s.jsx)(p.T,{gap:2,align:"stretch",children:L.map(e=>(0,s.jsxs)(h.a,{p:3,borderWidth:"1px",borderColor:k,borderRadius:"md",_hover:{bg:E},transition:"background 0.15s",children:[(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"flex-start",mb:1,children:[(0,s.jsx)(a.E,{fontWeight:"medium",fontSize:"sm",children:e.title}),(0,s.jsxs)(u.z,{gap:1,flexShrink:0,children:[(0,s.jsxs)(x.$,{size:"2xs",colorPalette:"blue",onClick:()=>{i(e.content),l()},title:"Use this macro",children:[(0,s.jsx)(v.YrT,{size:12}),(0,s.jsx)(a.E,{fontSize:"2xs",ml:.5,children:"Use"})]}),(0,s.jsx)(x.$,{size:"2xs",variant:"ghost",onClick:()=>{d(e),y(e.title),S(e.content),j(!1)}
1,title:"Edit macro",children:(0,s.jsx)(v.SG1,{size:12})}),(0,s.jsx)(x.$,{size:"2xs",variant:"ghost",colorPalette:"red",onClick:()=>O(e.id),title:"Delete macro",children:(0,s.jsx)(v.IXo,{size:12})})]})]}),(0,s.jsx)(a.E,{fontSize:"xs",color:W,lineClamp:3,children:e.content})]},e.id))}):(0,s.jsxs)(h.a,{textAlign:"center",py:12,children:[(0,s.jsx)(v.FrA,{size:28,color:"dark"===o?"#4A5568":"#CBD5E0",style:{margin:"0 auto 8px"}}),(0,s.jsx)(a.E,{color:W,fontSize:"sm",children:C?"No macros match your search.":"No macros yet. Create one to speed up your replies."})]})})]})]})}),document.body)},ec=[{value:"widget",label:"Chat"},{value:"whatsapp",label:"WhatsApp"},{value:"email",label:"Email"},{value:"form",label:"Form"},{value:"instagram",label:"Instagram"},{value:"messenger",label:"Messenger"},{value:"playground",label:"Playground"}],ed=e=>{if(!e)return"N/A";try{return(0,C.GP)(new Date(e),"MMM dd, yyyy HH:mm")}catch(t){return e}},eu=e=>{let{content:t,resolvedTheme:r}=e,[l,i]=(0,n.useState)(!1),o="dark"===r;return(0,s.jsxs)(h.a,{mt:2,children:[(0,s.jsx)(x.$,{type:"button",onClick:()=>i(e=>!e),"aria-expanded":l,size:"2xs",variant:"ghost",bg:o?"gray.700":"gray.100",color:o?"gray.300":"gray.600",borderRadius:"full",px:2,py:0,h:"auto",minH:"20px",fontSize:"xs",fontWeight:"normal",_hover:{bg:o?"gray.600":"gray.200"},children:(0,s.jsxs)(u.z,{gap:1,alignItems:"center",children:[l?(0,s.jsx)(v.fK4,{size:11}):(0,s.jsx)(v.fOo,{size:11}),(0,s.jsx)(a.E,{fontSize:"xs",children:l?"Hide previous conversation":"Show previous conversation"})]})}),l&&(0,s.jsx)(h.a,{mt:2,pl:3,borderLeftWidth:"3px",borderLeftColor:o?"gray.600":"gray.300",color:o?"gray.400":"gray.600",children:(0,s.jsx)(a.E,{fontSize:"xs",whiteSpace:"pre-wrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",children:t})})]})},ex=n.memo(e=>{var t;let r,n,{message:l,resolvedTheme:i}=e,o=(0,J.r)(l.sender_name,l.sender_email),c="human"===l.role&&o?o:"note"===l.role&&o?"Note by ".concat(o):void 0,d=((e,t,r)=>{switch(e){case"customer":return{bg:"dark"===t?"blue.900":"blue.50",borderColor:"dark"===t?"blue.700":"blue.200",color:"dark"===t?"blue.200":"blue.700",label:"Customer"};case"ai":return{bg:"dark"===t?"purple.900":"purple.50",borderColor:"dark"===t?"purple.700":"purple.200",color:"dark"===t?"purple.200":"purple.700",label:"AI"};case"human":return{bg:"dark"===t?"green.900":"green.50",borderColor:"dark"===t?"green.700":"green.200",color:"dark"===t?"green.200":"green.700",label:r||"Agent"};case"note":return{bg:"dark"===t?"yellow.900":"yellow.50",borderColor:"dark"===t?"yellow.700":"yellow.200",color:"dark"===t?"yellow.200":"yellow.700",label:r||"Note"};default:return{bg:"dark"===t?"gray.800":"gray.100",borderColor:"dark"===t?"gray.600":"gray.300",color:"dark"===t?"gray.300":"gray.600",label:e}}})(l.role,i,c),x=G.kY.blockBgColor[i],g="customer"===l.role;g?(r="dark"===i?"blue.900":"blue.50",n="dark"===i?"blue.700":"blue.200"):(r="dark"===i?"gray.800":"gray.50",n="dark"===i?"gray.700":"gray.200");let m=!g;return(0,s.jsx)(h.a,{w:"100%",mb:2,display:"flex",flexDirection:"column",alignItems:m?"flex-end":"flex-start",children:(0,s.jsxs)(h.a,{maxW:"80%",children:[(0,s.jsxs)(u.z,{gap:1,mb:.5,justifyContent:m?"flex-end":"flex-start",children:[(0,s.jsx)(h.a,{px:1.5,py:0,borderRadius:"sm",bg:d.bg,borderWidth:"1px",borderColor:d.borderColor,children:(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",color:d.color,children:d.label})}),(0,s.jsx)(a.E,{fontSize:"2xs",color:"dark"===i?"gray.500":"gray.400",children:(e=>{if(!e)return"";try{return(0,C.GP)(new Date(e),"HH:mm")}catch(e){return""}})(l.created_at)})]}),(0,s.jsxs)(h.a,{bg:r,borderWidth:"1px",borderColor:n,borderRadius:"md",px:3,py:2,children:["ai"===l.role?(0,s.jsxs)(h.a,{fontSize:"sm",children:[(0,s.jsx)(_.oz,{rehypePlugins:[E.A],remarkPlugins:[k.A,w.A],components:(0,O.A)({codeblock:{backgroundColor:x}},void 0,void 0,i,"sm",!1),children:(0,Q.m)(l.content)}),(()=>{let e=(0,Z.Q)(l.content).tickets;return 0===e.length?null:(0,s.jsx)(p.T,{align:"stretch",gap:1.5,mt:2,children:e.map((e,t)=>(0,s.jsx)(ee.f,{ticket:e,colorMode:i,language:"en"},"".concat(e.source,"-").concat(e.reference,"-").concat(t)))})})()]}):(0,s.jsx)(a.E,{fontSize:"sm",whiteSpace:"pre-wrap",children:l.content}),g&&!!(null==(t=l.quoted_content)?void 0:t.trim())&&(0,s.jsx)(eu,{content:l.quoted_content,resolvedTheme:i}),(()=>{let e=(0,V.d6)(l.attachments,l.images_urls);return 0===e.length?null:(0,s.jsx)(u.z,{gap:2,flexWrap:"wrap",mt:2,children:e.map((e,t)=>(0,s.jsx)(q.E,{resolved:e,imageMaxH:"180px",imageMaxW:"240px",borderColor:n},e.key||e.url||t))})})(),g&&l.page_url&&(0,s.jsxs)(u.z,{mt:2,gap:1,alignItems:"center",children:[(0,s.jsx)(v.HaR,{size:11,color:"dark"===i?"#A0AEC0":"#718096",style:{flexShrink:0}}),(0,s.jsx)(a.E,{fontSize:"xs",color:"dark"===i?"gray.400":"gray.500",flexShrink:0,children:"Browsing"}),(0,s.jsx)("a",{href:l.page_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"dark"===i?"#63B3ED":"#2B6CB0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l.page_url})]})]})]})})},(e,t)=>{var r,s;if(e.resolvedTheme!==t.resolvedTheme)return!1;let n=e.message,l=t.message;return n===l||n.id===l.id&&n.content===l.content&&n.created_at===l.created_at&&n.role===l.role&&n.sender_email===l.sender_email&&n.sender_name===l.sender_name&&n.page_url===l.page_url&&(null!=(r=n.quoted_content)?r:null)===(null!=(s=l.quoted_content)?s:null)&&!0}),eh=e=>{let{session:t,variant:r="classic",compact:l=!1,isFocused:i=!0,hasUnreadPulse:o=!1,isDisabled:c=!1,currentAccountId:b=null,onFocus:y,onCloseSession:C,onReopenSession:_,onAssignToAi:w,onSkip:k,onClaim:E,onRelease:T,onAssign:A,onOpenTags:P,onOpenNotes:D,onOpenSummary:I,dismissedEscalationNotes:H,dismissEscalationNote:N,restoreEscalationNote:M,agentId:$,isClosing:X=!1,isReopening:L=!1,isClaiming:F=!1}=e,O=function(e){var t;let r=null!=(t=null==e?void 0:e.session_id)?t:null,{data:s,mutate:l}=(0,W.a)(r),{trigger:i,isMutating:o}=(0,W.mn)(),{trigger:a}=(0,W.nm)(),{trigger:c,isMutating:d}=(0,W.Lh)(),{invoke:u}=(0,W.eu)(),{subscribe:x}
1=(0,R.r)(),[h,p]=(0,n.useState)(""),[g,m]=(0,n.useState)([]),[f,j]=(0,n.useState)(""),[b,y]=(0,n.useState)(""),[z,v]=(0,n.useState)(!1),[S,C]=(0,n.useState)(!1),[_,w]=(0,n.useState)(""),[k,E]=(0,n.useState)(!1),[T,A]=(0,n.useState)(""),P=(0,n.useRef)(null),D=(0,n.useRef)(null),I=(0,n.useRef)(0),H=(0,n.useRef)(null),N=(0,n.useRef)(!0),M=(0,n.useRef)(null),$=(0,n.useRef)(null),X=(0,n.useRef)(null),L=(0,n.useRef)(""),F=(0,n.useRef)(!1),K=(0,n.useRef)(null),G=(0,n.useRef)(null),O=(0,n.useRef)(null),Y=(0,n.useRef)(0),J=(0,n.useRef)(null);(0,n.useEffect)(()=>{X.current=r},[r]),(0,n.useEffect)(()=>{L.current=h},[h]),(0,n.useEffect)(()=>{F.current=S},[S]);let U=(0,n.useMemo)(()=>{var e;return null!=(e=null==s?void 0:s.filter(e=>"note"!==e.role))?e:[]},[s]),q=(0,n.useMemo)(()=>{var e;return null!=(e=null==s?void 0:s.filter(e=>"note"===e.role))?e:[]},[s]),V=(0,n.useMemo)(()=>{var e;return null!=(e=[...q].sort((e,t)=>new Date(t.created_at||0).getTime()-new Date(e.created_at||0).getTime())[0])?e:null},[q]),Q=!!e&&(es.has(e.source||"")||["email","amazon","form"].includes((e.channel||"").toLowerCase())),Z=!!e&&["widget","playground"].includes((e.channel||"").toLowerCase())&&"transfer_to_human"===e.source,ee=Q||Z,et=Q?"async":"live";(0,n.useEffect)(()=>{let t=(null==e?void 0:e.draft_text)||"";p(t),$.current=t||null,m([]),j(""),y(""),w(""),v(!1),E(!1),A(""),I.current=0,N.current=!0},[r]),(0,n.useEffect)(()=>x(e=>{var t,r;if("draft_ready"!==e.type)return;let s=null==(t=e.data)?void 0:t.session_id,n=null==(r=e.data)?void 0:r.draft_text;if(!s||!n||s!==X.current||F.current)return;let l=L.current,i=$.current;(""===l.trim()||l===i)&&(p(n),$.current=n)}),[x]);let er=(0,n.useCallback)((e,t)=>{if(e)if(t){let t=Date.now();(t-Y.current>1e3||J.current!==e)&&(Y.current=t,J.current=e,a({session_id:e,is_typing:!0}).catch(()=>{})),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{J.current=null,a({session_id:e,is_typing:!1}).catch(()=>{})},3e3)}else O.current&&(clearTimeout(O.current),O.current=null),J.current=null,a({session_id:e,is_typing:!1}).catch(()=>{})},[a]),ei=(0,n.useCallback)(()=>{let e=G.current;e&&(e.style.height="auto",e.style.height="".concat(Math.min(e.scrollHeight,160),"px"))},[]);(0,n.useEffect)(()=>{requestAnimationFrame(ei)},[h,ei]);let eo=(0,n.useCallback)(()=>{let e=P.current;e&&(N.current=e.scrollHeight-e.scrollTop-e.clientHeight<80)},[]);(0,n.useEffect)(()=>{let e=U.length;if(e>I.current){let e=P.current;e&&e.scrollHeight-e.scrollTop-e.clientHeight<80&&(N.current=!0),N.current&&requestAnimationFrame(()=>{P.current&&(P.current.scrollTop=P.current.scrollHeight)})}I.current=e},[U]),(0,n.useEffect)(()=>{r&&0!==U.length&&H.current!==r&&(H.current=r,N.current=!0,requestAnimationFrame(()=>{P.current&&(P.current.scrollTop=P.current.scrollHeight)}))},[r,U.length]);let ea=(0,n.useCallback)(async()=>{var e,t;if(r&&h.trim()&&!o)try{let t={session_id:r,message:h.trim()};if(g.length>0&&(t.attachments=g),Q){let e=el(f),r=el(b);e.length>0&&(t.cc=e),r.length>0&&(t.bcc=r)}Z&&er(r,!1),await i(t),p(""),$.current=null,m([]),j(""),y(""),l(),null==(e=G.current)||e.focus(),N.current=!0,requestAnimationFrame(()=>{let e=P.current;e&&(e.scrollTop=e.scrollHeight)}),B.X.create({title:"Reply sent",type:"success",duration:3e3,closable:!0})}catch(e){console.error(e),null==(t=G.current)||t.focus(),B.X.create({title:"Error sending reply",type:"error",duration:3e3,closable:!0})}},[r,h,g,Q,Z,f,b,i,er,l,o]),ec=(0,n.useCallback)(async(e,t)=>{if(!r||S)return;let s=h.trim()||void 0,n=(null==t?void 0:t.skipCurrentDraft)?void 0:s;p(""),$.current=null,C(!0);let l=new AbortController;M.current=l,await u({sessionId:r,instruction:e||void 0,currentDraft:n},e=>p(t=>t+e),()=>{C(!1),M.current=null},e=>{C(!1),M.current=null,s&&p(s),console.error(e),B.X.create({title:"Drafter error",description:e.message,type:"error",duration:3e3,closable:!0})},l.signal)},[r,S,h,u]),ed=(0,n.useCallback)(()=>{var e;null==(e=M.current)||e.abort(),C(!1),M.current=null},[]),eu=(0,n.useCallback)(e=>{let t=e.target.files;t&&(Array.from(t).forEach(e=>{if(!en.includes(e.type))return void B.X.create({title:"Unsupported file type: ".concat(e.type),type:"error",duration:3e3,closable:!0});let t=new FileReader;t.onload=()=>{let r=t.result.split(",")[1];m(t=>[...t,{filename:e.name,content_type:e.type,data:r}])}
1,t.readAsDataURL(e)}),e.target.value="")},[]),ex=(0,n.useCallback)(e=>{m(t=>t.filter((t,r)=>r!==e))},[]),eh=(0,n.useCallback)(async()=>{if(!r)return;let t=T.trim();if(t===((null==e?void 0:e.subject)||"").trim())return void E(!1);try{await c({session_id:r,subject:t||null}),E(!1),B.X.create({title:"Subject updated",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error updating subject",type:"error",duration:3e3,closable:!0})}},[r,T,null==e?void 0:e.subject,c]);return{sessionId:r,messages:s,mutateMessages:l,timelineMessages:U,noteMessages:q,lastTeamNote:V,isEmailReply:Q,isLiveChatReply:Z,attachmentsSupported:ee,conversationKind:et,replyText:h,setReplyText:p,pendingAttachments:g,replyCC:f,setReplyCC:j,replyBCC:b,setReplyBCC:y,showCcBcc:z,setShowCcBcc:v,isDraftStreaming:S,copilotInstruction:_,setCopilotInstruction:w,isEditingSubject:k,setIsEditingSubject:E,subjectDraft:T,setSubjectDraft:A,isSendingReply:o,isUpdatingSubject:d,messagesContainerRef:P,bottomSentinelRef:D,fileInputRef:K,replyTextareaRef:G,handleMessagesScroll:eo,handleSendReply:ea,handleCopilotSubmit:ec,handleCancelDraft:ed,handleFileSelect:eu,removeAttachment:ex,handleSaveSubject:eh,handleKeyDown:(0,n.useCallback)(function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"live";if("async"===r){"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),t());return}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),t())},[]),emitOperatorTyping:er,allowedAttachmentAccept:en.join(",")+",.pdf,.txt,.csv"}}(t),{resolvedTheme:U}=(0,K.j)(),{typingBySession:q}
1=(0,R.r)(),[V,Q]=(0,n.useState)(!1),[Z,ee]=(0,n.useState)("conversation"),eo=G.kY.blockBorderColor[U]||G.kY.blockBorderColor.dark,eu="gray.500",eh="dark"===U?"gray.400":"gray.600",ep="flow"===r,eg=((e,t)=>"open"!==e.status?"closed":null==e.assigned_to?"claim":null!=t&&e.assigned_to===t?"claimed":"other")(t,b);return(0,n.useEffect)(()=>{ee("conversation")},[t.session_id]),(0,s.jsxs)(j.s,{flex:1,minW:0,minH:0,direction:"column",overflow:"hidden",bg:"dark"===U?"gray.950":"white",borderWidth:ep?"1px":"0",borderColor:o?"yellow.400":i?"blue.400":eo,borderRadius:ep?"md":"none",onClick:y,outline:ep&&i?"2px solid":void 0,outlineColor:ep&&i?"blue.400":void 0,children:[(0,s.jsx)(h.a,{flexShrink:0,px:l?3:6,py:3,bg:"dark"===U?"gray.900":"gray.50/60",children:(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"flex-start",gap:2,children:[(0,s.jsxs)(p.T,{align:"flex-start",gap:1,flex:1,minW:0,children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",flexWrap:"wrap",children:[(0,s.jsx)(v.JXP,{size:16}),(0,s.jsx)(a.E,{fontSize:l?"sm":"md",fontWeight:"semibold",truncate:!0,children:(0,Y.K9)(t)}),(0,s.jsx)(f.Ex,{colorPalette:(e=>{switch(e){case"open":return"orange";case"closed":return"green";default:return"gray"}})(t.status),size:"sm",children:(0,s.jsxs)(u.z,{gap:.5,children:[(e=>{switch(e){case"open":return(0,s.jsx)(v.Ohp,{size:12});case"closed":return(0,s.jsx)(v.A3x,{size:12});default:return null}})(t.status),(0,s.jsx)(a.E,{fontSize:"2xs",children:t.status})]})}),t.unanswered_count>0&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"yellow",variant:"solid",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:1===t.unanswered_count?"1 unanswered":"".concat(t.unanswered_count," unanswered")})}),o&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"yellow",children:"New"}),!l&&t.source&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:(e=>{switch(e){case"escalate_to_inbox":case"transfer_to_human":return"orange";case"outbound":return"green";case"inbound":return"teal";case"send_to_inbox":return"cyan";default:return"gray"}})(t.source),variant:"subtle",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.L7s,{size:10}),(0,s.jsx)(a.E,{fontSize:"2xs",children:(e=>{switch(e){case"escalate_to_inbox":case"transfer_to_human":return"Escalated";case"outbound":return"Outbound";case"inbound":return"Inbound";case"send_to_inbox":return"Sent to Inbox";default:return e||"Unknown"}})(t.source)})]})}),!l&&t.channel&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"gray",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.mEP,{size:10}),(0,s.jsx)(a.E,{fontSize:"2xs",children:(e=>{if(!e)return"";let t=e.toLowerCase(),r=ec.find(e=>e.value===t);return r?r.label:t.charAt(0).toUpperCase()+t.slice(1)})(t.channel)})]})}),t.assigned_email&&"claimed"!==eg&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"blue",variant:"subtle",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:t.assigned_name||t.assigned_email})})]}),O.isEditingSubject?(0,s.jsxs)(u.z,{gap:1,w:"100%",maxW:"560px",children:[(0,s.jsx)(g.p,{size:"sm",value:O.subjectDraft,onChange:e=>O.setSubjectDraft(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),O.handleSaveSubject()):"Escape"===e.key&&(e.preventDefault(),O.setIsEditingSubject(!1))},placeholder:"Email subject...",autoFocus:!0,disabled:O.isUpdatingSubject}),(0,s.jsx)(d.K,{"aria-label":"Save subject",size:"xs",variant:"ghost",colorPalette:"green",onClick:()=>void O.handleSaveSubject(),loading:O.isUpdatingSubject,children:(0,s.jsx)(v.YrT,{size:14})}),(0,s.jsx)(d.K,{"aria-label":"Cancel",size:"xs",variant:"ghost",onClick:()=>O.setIsEditingSubject(!1),children:(0,s.jsx)(v.yGN,{size:14})})]}):(0,s.jsxs)(u.z,{gap:1,maxW:"100%",children:[(0,s.jsx)(a.E,{fontSize:"xs",color:t.subject?eh:eu,fontStyle:t.subject?void 0:"italic",truncate:!0,children:t.subject||"No subject"}),(0,s.jsx)(d.K,{"aria-label":"Edit subject",size:"2xs",variant:"ghost",onClick:()=>{O.setSubjectDraft(t.subject||""),O.setIsEditingSubject(!0)},children:(0,s.jsx)(v.SG1,{size:12})})]})]}),ep&&(0,s.jsxs)(u.z,{gap:.5,flexShrink:0,onClick:e=>e.stopPropagation(),children:[(0,s.jsx)(d.K,{"aria-label":"Conversation",title:"Conversation",size:"xs",variant:"conversation"===Z?"solid":"ghost",colorPalette:"conversation"===Z?"blue":"gray",onClick:()=>ee("conversation"),children:(0,s.jsx)(v.mEP,{size:15})}),(0,s.jsx)(d.K,{"aria-label":"Customer profile",title:"Profile",size:"xs",variant:"profile"===Z?"solid":"ghost",colorPalette:"profile"===Z?"teal":"gray",onClick:()=>ee("profile"),children:(0,s.jsx)(v.JXP,{size:15})}),(0,s.jsx)(d.K,{"aria-label":"Drafter",title:"Drafter",size:"xs",variant:"drafter"===Z?"solid":"ghost",colorPalette:"drafter"===Z||O.isDraftStreaming?"purple":"gray",onClick:()=>ee("drafter"),children:(0,s.jsx)(S.pCw,{size:15})})]})]})}),t.escalation_note&&(H.has(t.session_id)?(0,s.jsx)(u.z,{flexShrink:0,px:l?3:6,py:1,justify:"flex-end",children:(0,s.jsx)(x.$,{size:"2xs",variant:"ghost",onClick:()=>M(t.session_id),children:"Show note"})}):(0,s.jsx)(h.a,{flexShrink:0,px:l?3:6,py:2,bg:"dark"===U?"orange.950":"orange.50",children:(0,s.jsxs)(u.z,{align:"flex-start",ga
1p:2,children:[(0,s.jsx)(v.eHT,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",flex:1,children:t.escalation_note}),(0,s.jsx)(d.K,{"aria-label":"Dismiss note",size:"2xs",variant:"ghost",onClick:()=>N(t.session_id),children:(0,s.jsx)(v.yGN,{size:12})})]})})),(!ep||"conversation"===Z)&&(0,s.jsxs)(h.a,{flex:1,minH:0,overflowY:"auto",px:l?3:6,py:3,ref:O.messagesContainerRef,onScroll:O.handleMessagesScroll,children:[O.timelineMessages.map((e,t)=>{let r=O.timelineMessages[t-1],l=!r||e.created_at&&r.created_at&&e.created_at.slice(0,10)!==r.created_at.slice(0,10);return(0,s.jsxs)(n.Fragment,{children:[l&&e.created_at&&(0,s.jsx)(u.z,{justify:"center",my:3,children:(0,s.jsx)(a.E,{fontSize:"2xs",color:eu,children:ed(e.created_at)})}),(0,s.jsx)(ex,{message:e,resolvedTheme:U})]},e.id)}),(0,s.jsx)("div",{ref:O.bottomSentinelRef})]}),ep&&"profile"===Z&&(0,s.jsx)(ei.A,{agentId:$||null,sessionId:t.session_id,embedded:!0}),ep&&"drafter"===Z&&(0,s.jsx)(h.a,{flex:1,minH:0,overflowY:"auto",px:l?3:6,py:3,children:(0,s.jsx)(er,{instruction:O.copilotInstruction,onInstructionChange:O.setCopilotInstruction,onGenerate:(e,t)=>void O.handleCopilotSubmit(e,t),onStop:O.handleCancelDraft,isStreaming:O.isDraftStreaming,isDisabled:c,hasCurrentDraft:!!O.replyText.trim(),destination:"reply"})}),"open"===t.status&&(0,s.jsxs)(h.a,{flexShrink:0,px:l?3:6,py:3,borderTopWidth:"1px",borderTopColor:eo,children:[(0,s.jsxs)(u.z,{gap:2,mb:2,flexWrap:"wrap",children:["claim"===eg&&E&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"blue",variant:"solid",onClick:()=>E(t.session_id),disabled:c||F,title:"Claim this conversation — assign it to you",children:[(0,s.jsx)(v.YrT,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Claim"})]}),"claimed"===eg&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"green",variant:"solid",cursor:"default",title:"You claimed this conversation",children:[(0,s.jsx)(v.YrT,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Claimed"})]}),"other"===eg&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"blue",variant:"subtle",cursor:"default",title:"Claimed by ".concat((0,J.r)(t.assigned_name,t.assigned_email)||"another operator"),children:[(0,s.jsx)(v.JXP,{size:12}),(0,s.jsxs)(a.E,{fontSize:"xs",ml:1,truncate:!0,maxW:"160px",children:["Claimed by ",(0,J.r)(t.assigned_name,t.assigned_email)||"another operator"]})]}),ep&&"claimed"===eg&&k&&(0,s.jsx)(x.$,{size:"xs",variant:"outline",onClick:()=>k(t.session_id),disabled:c,title:"Unassign this conversation and pull the next one from the queue",children:"Skip"}),!ep&&"claimed"===eg&&T&&(0,s.jsx)(x.$,{size:"xs",variant:"outline",onClick:()=>T(t.session_id),disabled:c,title:"Unassign this conversation and keep it open here",children:"Release"}),!ep&&A&&(0,s.jsxs)(x.$,{size:"xs",variant:"outline",colorPalette:"blue",onClick:A,title:"Assign session",children:[(0,s.jsx)(v.JXP,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Assign"})]}),I&&(0,s.jsx)(x.$,{size:"xs",variant:"outline",colorPalette:"purple",onClick:I,title:"View conversation summary",children:(0,s.jsx)(a.E,{fontSize:"xs",children:"Summary"})}),D&&(0,s.jsxs)(x.$,{size:"xs",variant:"outline",colorPalette:"yellow",onClick:D,title:"View and add notes",children:[(0,s.jsx)(v.jH2,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Notes"}),O.noteMessages.length>0&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"yellow",ml:1,children:O.noteMessages.length})]}),P&&(0,s.jsxs)(x.$,{size:"xs",variant:"outline",colorPalette:"purple",onClick:P,title:"Manage tags",children:[(0,s.jsx)(v.cnX,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Tag"})]}),"open"===t.status&&w&&"inbound"===t.source&&["email","amazon","whatsapp","messenger","instagram"].includes((t.channel||"").toLowerCase())&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"purple",variant:"outline",onClick:()=>w(t.session_id),disabled:c,title:"Hand this ticket to the AI — it replies on the same channel until it needs a human",children:[(0,s.jsx)(v.FrA,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Assign AI"})]}),"open"===t.status?(0,s.jsxs)(x.$,{size:"xs",colorPalette:"red",variant:"outline",onClick:()=>C(t.session_id),disabled:c||X,title:"Close session",children:[(0,s.jsx)(v.yGN,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Close"})]}):_?(0,s.jsxs)(x.$,{size:"xs",colorPalette:"green",variant:"outline",onClick:()=>_(t.session_id),disabled:c||L,title:"Reopen session",children:[(0,s.jsx)(v.VI6,{size:14}
1),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Reopen"})]}):null]}),O.lastTeamNote&&(0,s.jsxs)(h.a,{mb:2,p:2,borderRadius:"md",bg:"dark"===U?"yellow.950":"yellow.50",children:[(0,s.jsxs)(a.E,{fontSize:"2xs",color:eu,mb:.5,children:["Latest note \xb7 ",ed(O.lastTeamNote.created_at)]}),(0,s.jsx)(a.E,{fontSize:"sm",whiteSpace:"pre-wrap",fontStyle:"italic",children:O.lastTeamNote.content})]}),O.isEmailReply&&O.showCcBcc&&(0,s.jsxs)(p.T,{gap:1,mb:2,align:"stretch",children:[(0,s.jsxs)(u.z,{children:[(0,s.jsx)(a.E,{fontSize:"2xs",w:"36px",children:"CC"}),(0,s.jsx)(g.p,{value:O.replyCC,onChange:e=>O.setReplyCC(e.target.value),placeholder:"[email protected]",size:"xs"})]}),(0,s.jsxs)(u.z,{children:[(0,s.jsx)(a.E,{fontSize:"2xs",w:"36px",children:"BCC"}),(0,s.jsx)(g.p,{value:O.replyBCC,onChange:e=>O.setReplyBCC(e.target.value),placeholder:"[email protected]",size:"xs"})]})]}),O.pendingAttachments.length>0&&(0,s.jsx)(u.z,{gap:2,mb:2,flexWrap:"wrap",children:O.pendingAttachments.map((e,t)=>(0,s.jsxs)(u.z,{px:2,py:1,borderWidth:"1px",borderColor:eo,borderRadius:"md",gap:1.5,children:["application/pdf"===e.content_type?(0,s.jsx)(v._mV,{size:12}):e.content_type.startsWith("text/")?(0,s.jsx)(v.jH2,{size:12}):(0,s.jsx)(v.fZZ,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",maxW:"120px",truncate:!0,children:e.filename}),(0,s.jsx)(h.a,{cursor:"pointer",onClick:()=>O.removeAttachment(t),_hover:{color:"red.400"},children:(0,s.jsx)(v.yGN,{size:12})})]},t))}),(0,s.jsxs)(h.a,{position:"relative",children:[("widget"===t.channel||"playground"===t.channel)&&"visitor"===q.get(t.session_id)&&(0,s.jsxs)(u.z,{position:"absolute",top:"-20px",left:0,gap:2,h:"16px",pointerEvents:"none",children:[(0,s.jsx)(h.a,{w:1.5,h:1.5,borderRadius:"full",bg:"green.500"}),(0,s.jsx)(a.E,{fontSize:"xs",color:eu,children:"Visitor is typing..."})]}),(0,s.jsx)(m.T,{ref:O.replyTextareaRef,value:O.replyText,onChange:e=>{if(O.isDraftStreaming)return;let r=e.target.value;O.setReplyText(r),r.length>0&&("widget"===t.channel||"playground"===t.channel)&&"transfer_to_human"===t.source&&O.emitOperatorTyping(t.session_id,!0)},onKeyDown:e=>{O.isDraftStreaming||O.handleKeyDown(e,O.handleSendReply,O.conversationKind)},placeholder:O.isDraftStreaming?"Drafter is writing...":"async"===O.conversationKind?"Write your reply... (Ctrl+Enter to send)":"Type a reply to the customer...",size:"sm",minH:"44px",maxH:"180px",resize:"vertical",overflowY:"auto",disabled:c,readOnly:O.isDraftStreaming,pb:"40px"}),(0,s.jsxs)(u.z,{position:"absolute",bottom:"10px",left:"10px",right:"14px",zIndex:1,gap:.5,mb:1,children:[O.attachmentsSupported&&(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,onClick:()=>{var e;return null==(e=O.fileInputRef.current)?void 0:e.click()},disabled:c||O.isSendingReply||O.isDraftStreaming,title:"Attach files",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v._mV,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",children:"Attach"})]})}),O.isDraftStreaming?(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,colorPalette:"red",onClick:O.handleCancelDraft,children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(z.y,{size:"xs"}),(0,s.jsx)(a.E,{fontSize:"2xs",children:"Stop"})]})}):(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,color:"purple.500",onClick:()=>void O.handleCopilotSubmit(et,{skipCurrentDraft:!0}),disabled:c,title:"Generate a draft reply without extra instructions",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(S.pCw,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",children:"Quick Draft"})]})}),(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,color:"yellow.500",onClick:()=>Q(!0),disabled:c||O.isDraftStreaming,title:"Use a macro",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v.FrA,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",children:"Macro"})]})}),O.isEmailReply&&(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,onClick:()=>O.setShowCcBcc(e=>!e),children:(0,s.jsx)(a.E,{fontSize:"2xs",children:"CC/BCC"})}),(0,s.jsx)(h.a,{flex:1}),(0,s.jsxs)(x.$,{colorPalette:"blue",onClick:()=>void O.handleSendReply(),disabled:c||O.isSendingReply||O.isDraftStreaming||!O.replyText.trim(),size:"xs",px:2,py:1,loading:O.isSendingReply,children:[(0,s.jsx)(v.kGk,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Send"})]})]}),(0,s.jsx)("input",{ref:O.fileInputRef,type:"file",accept:O.allowedAttachmentAccept,multiple:!0,style:{display:"none"},onChange:O.handleFileSelect})]})]}),(0,s.jsx)(ea,{agentId:$||null,isOpen:V,onClose:()=>Q(!1),onUseMacro:e=>O.setReplyText(e),resolvedTheme:U})]})},ep=new Set(["whatsapp","social"]),eg=[{value:"all",label:"All Statuses"},{value:"open",label:"Open"},{value:"closed",label:"Closed"}],em=[{value:"all",label:"All Channels"},{value:"widget",label:"Chat"},{value:"whatsapp",label:"WhatsApp"},{value:"email",label:"Email"},{value:"form",label:"Form"},{value:"instagram",label:"Instagram"},{value:"messenger",label:"Messenger"},{value:"playground",label:"Playground"}],ef={chat:{title:"Live Chat"},whatsapp:{title:"WhatsApp"},social:{title:"Social"},inbox:{title:"Inbox"}},ej=new Set(["escalate_to_inbox","send_to_inbox"]),eb=["image/png","image/jpeg","image/webp","image/heic","image/heif","application/pdf","text/plain","text/csv"],ey=eb.join(",")+",.pdf,.txt,.csv",ez=e=>{switch(e){case"open":return"orange";case"closed":return"green";default:return"gray"}},ev=e=>{switch(e){case"open":return(0,s.jsx)(v.Ohp,{size:12});case"closed":return(0,s.jsx)(v.A3x,{size:12});default:return null}},eS=e=>{switch(e){case"escalate_to_inbox":case"transfer_to_human":return"orange";case"outbound":return"green";
1case"inbound":return"teal";case"send_to_inbox":return"cyan";default:return"gray"}},eC=e=>{switch(e){case"escalate_to_inbox":case"transfer_to_human":return"Escalated";case"outbound":return"Outbound";case"inbound":return"Inbound";case"send_to_inbox":return"Sent to Inbox";default:return e||"Unknown"}},e_=e=>{if(!e)return"";let t=e.toLowerCase(),r=em.find(e=>e.value===t);return r&&"all"!==r.value?r.label:t.charAt(0).toUpperCase()+t.slice(1)},ew=new Set(["transfer_to_human","escalate_to_inbox"]),ek=(e,t)=>!ep.has(e)&&"open"!==t,eE=(e,t)=>t&&"chat"!==e&&!ep.has(e),eW=(e,t)=>!!t&&("inbox"===e||!!ep.has(e)&&ew.has(t)),eT=e=>e.replace(/\s+/g," ").trim(),eA=e=>{if(!e)return"N/A";try{return(0,C.GP)(new Date(e),"MMM dd, yyyy HH:mm")}catch(t){return e}},eR=J.r,eP=e=>e.split(",").map(e=>e.trim()).filter(Boolean),eD=(e,t)=>{if(null==e||""===e)return"—";let r="number"==typeof e?e:Number(e);if(Number.isNaN(r))return String(e);try{return new Intl.NumberFormat(void 0,{style:"currency",currency:(t||"USD").toUpperCase(),minimumFractionDigits:2,maximumFractionDigits:2}).format(r)}catch(e){return"".concat(r.toFixed(2)).concat(t?" "+t.toUpperCase():"")}},eI=e=>null==e||"string"==typeof e&&""===e.trim(),eH={ok:{color:"green",label:"Live"},not_found:{color:"gray",label:"Not found",muted:!0},not_configured:{color:"gray",label:"Not configured",muted:!0}
1,no_email:{color:"yellow",label:"No email on session",muted:!0},error:{color:"red",label:"Error"},timeout:{color:"orange",label:"Timeout"}},eN=e=>"get_customer_history"===e.callable_name,eM=["get_shopify_customer_profile","get_medusa_customer_profile","get_magento_customer_profile","get_sfcc_customer_profile","get_bigcommerce_customer_profile","get_prestashop_customer_profile","get_woocommerce_customer_profile","get_hubspot_contact_info","get_attio_customer"],e$=c.cQ,eX=c.y3,eL=c.rm,eF=c.Dr,eB=e=>{let{icon:t,title:r,activeLabel:n,selectValue:l,options:i,onSelectChange:o,onClear:h,resolvedTheme:p,menuMinW:g="220px",activeColorPalette:m="blue"}=e,f=null!=n,j=e=>{let t=e.value;if("__all__"===t)return void h();o(t)},b=(0,s.jsx)(eX,{children:(0,s.jsx)(eL,{minW:g,children:i.map(e=>{let t="all"===e.value,r=t?"__all__":e.value,n=!t&&e.value===l;return(0,s.jsx)(eF,{value:r,fontWeight:n?"semibold":"normal",children:e.label},e.value)})})});return f?(0,s.jsxs)(u.z,{gap:0,flexShrink:0,children:[(0,s.jsxs)(c.il,{onSelect:j,positioning:{placement:"bottom-start"},children:[(0,s.jsx)(e$,{asChild:!0,children:(0,s.jsxs)(x.$,{size:"sm",variant:"solid",colorPalette:m,title:r,flexShrink:0,borderRightRadius:0,pr:2,children:[t,(0,s.jsx)(a.E,{fontSize:"xs",ml:1,maxW:"160px",truncate:!0,children:n})]})}),b]}),(0,s.jsx)(d.K,{size:"sm",variant:"solid",colorPalette:m,"aria-label":"Clear ".concat(r),title:"Clear ".concat(r),onClick:e=>{e.stopPropagation(),h()},borderLeftRadius:0,borderLeftWidth:"1px",borderLeftColor:"dark"===p?"blackAlpha.400":"whiteAlpha.500",px:2,flexShrink:0,children:(0,s.jsx)(v.yGN,{size:12})})]}):(0,s.jsxs)(c.il,{onSelect:j,positioning:{placement:"bottom-start"},children:[(0,s.jsx)(e$,{asChild:!0,children:(0,s.jsx)(d.K,{size:"sm",variant:"outline",colorPalette:"gray","aria-label":r,title:r,flexShrink:0,children:t})}),b]})},eK=e=>{let{content:t,resolvedTheme:r}=e,[l,i]=(0,n.useState)(!1),o="dark"===r;return(0,s.jsxs)(h.a,{mt:2,children:[(0,s.jsx)(x.$,{type:"button",onClick:()=>i(e=>!e),"aria-expanded":l,size:"2xs",variant:"ghost",bg:o?"gray.700":"gray.100",color:o?"gray.300":"gray.600",borderRadius:"full",px:2,py:0,h:"auto",minH:"20px",fontSize:"xs",fontWeight:"normal",_hover:{bg:o?"gray.600":"gray.200"},children:(0,s.jsxs)(u.z,{gap:1,alignItems:"center",children:[l?(0,s.jsx)(v.fK4,{size:11}):(0,s.jsx)(v.fOo,{size:11}),(0,s.jsx)(a.E,{fontSize:"xs",children:l?"Hide previous conversation":"Show previous conversation"})]})}),l&&(0,s.jsx)(h.a,{mt:2,pl:3,borderLeftWidth:"3px",borderLeftColor:o?"gray.600":"gray.300",color:o?"gray.400":"gray.600",children:(0,s.jsx)(a.E,{fontSize:"xs",whiteSpace:"pre-wrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",children:t})})]})},eG=n.memo(e=>{var t;let r,n,{message:l,resolvedTheme:i}=e,o=eR(l.sender_name,l.sender_email),c="human"===l.role&&o?o:"note"===l.role&&o?"Note by ".concat(o):void 0,d=((e,t,r)=>{switch(e){case"customer":return{bg:"dark"===t?"blue.900":"blue.50",borderColor:"dark"===t?"blue.700":"blue.200",color:"dark"===t?"blue.200":"blue.700",label:"Customer"};case"ai":return{bg:"dark"===t?"purple.900":"purple.50",borderColor:"dark"===t?"purple.700":"purple.200",color:"dark"===t?"purple.200":"purple.700",label:"AI"};case"human":return{bg:"dark"===t?"green.900":"green.50",borderColor:"dark"===t?"green.700":"green.200",color:"dark"===t?"green.200":"green.700",label:r||"Agent"};case"note":return{bg:"dark"===t?"yellow.900":"yellow.50",borderColor:"dark"===t?"yellow.700":"yellow.200",color:"dark"===t?"yellow.200":"yellow.700",label:r||"Note"};default:return{bg:"dark"===t?"gray.800":"gray.100",borderColor:"dark"===t?"gray.600":"gray.300",color:"dark"===t?"gray.300":"gray.600",label:e}}})(l.role,i,c),x=G.kY.blockBgColor[i],g="customer"===l.role;l.role,g?(r="dark"===i?"blue.900":"blue.50",n="dark"===i?"blue.700":"blue.200"):(r="dark"===i?"gray.800":"gray.50",n="dark"===i?"gray.700":"gray.200");let m=!g;return(0,s.jsx)(h.a,{w:"100%",mb:2,display:"flex",flexDirection:"column",alignItems:m?"flex-end":"flex-start",children:(0,s.jsxs)(h.a,{maxW:"80%",children:[(0,s.jsxs)(u.z,{gap:1,mb:.5,justifyContent:m?"flex-end":"flex-start",children:[(0,s.jsx)(h.a,{px:1.5,py:0,borderRadius:"sm",bg:d.bg,borderWidth:"1px",borderColor:d.borderColor,children:(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",color:d.color,children:d.label})}),(0,s.jsx)(a.E,{fontSize:"2xs",color:"dark"===i?"gray.500":"gray.400",children:(e=>{if(!e)return"";try{return(0,C.GP)(new Date(e),"HH:mm")}catch(e){return""}})(l.created_at)})]}),(0,s.jsxs)(h.a,{bg:r,borderWidth:"1px",borderColor:n,borderRadius:"md",px:3,py:2,children:["ai"===l.role?(0,s.jsxs)(h.a,{fontSize:"sm",children:[(0,s.jsx)(_.oz,{rehypePlugins:[E.A],remarkPlugins:[k.A,w.A],components:(0,O.A)({codeblock:{backgroundColor:x}},void 0,void 0,i,"sm",!1),children:(0,Q.m)(l.content)}),(()=>{let e=(0,Z.Q)(l.content).tickets;return 0===e.length?null:(0,s.jsx)(p.T,{align:"stretch",gap:1.5,mt:2,children:e.map((e,t)=>(0,s.jsx)(ee.f,{ticket:e,colorMode:i,language:"en"},"".concat(e.source,"-").concat(e.reference,"-").concat(t)))})})()]}):(0,s.jsx)(a.E,{fontSize:"sm",whiteSpace:"pre-wrap",children:l.content}),g&&!!(null==(t=l.quoted_content)?void 0:t.trim())&&(0,s.jsx)(eK,{content:l.quoted_content,resolvedTheme:i}),(()=>{let e=(0,V.d6)(l.attachments,l.images_urls);return 0===e.length?null:(0,s.jsx)(u.z,{gap:2,flexWrap:"wrap",mt:2,children:e.map((e,t)=>(0,s.jsx)(q.E,{resolved:e,imageMaxH:"180px",imageMaxW:"240px",borderColor:n},e.key||e.url||t))})})(),g&&l.page_url&&(0,s.jsxs)(u.z,{mt:2,gap:1,alignItems:"center",children:[(0,s.jsx)(v.HaR,{size:11,color:"dark"===i?"#A0AEC0":"#718096",style:{flexShrink:0}}),(0,s.jsx)(a.E,{fontSize:"xs",color:"dark"===i?"gray.400":"gray.500",flexShrink:0,children:"Browsing"}),(0,s.jsx)("a",{href:l.page_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"dark"===i?"#63B3ED":"#2B6CB0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l.page_url})]})]})]})})},(e,t)=>{var r,s,n,l,i,o,a,c,d,u;if(e.resolvedTheme!==t.resolvedTheme)return!1;let x=e.message,h=t.message;if(x===h)return!0;
1if(x.id!==h.id||x.content!==h.content||x.created_at!==h.created_at||x.role!==h.role||x.sender_email!==h.sender_email||x.sender_name!==h.sender_name||x.page_url!==h.page_url||(null!=(r=x.quoted_content)?r:null)!==(null!=(s=h.quoted_content)?s:null))return!1;let p=null!=(n=x.images_urls)?n:[],g=null!=(l=h.images_urls)?l:[];if(p.length!==g.length)return!1;for(let e=0;e<p.length;e++)if(p[e]!==g[e])return!1;let m=null!=(i=x.attachments)?i:[],f=null!=(o=h.attachments)?o:[];if(m.length!==f.length)return!1;for(let e=0;e<m.length;e++){let t=m[e],r=f[e];if(t.url!==r.url||(null!=(a=t.filename)?a:null)!==(null!=(c=r.filename)?c:null)||(null!=(d=t.content_type)?d:null)!==(null!=(u=r.content_type)?u:null))return!1}return!0}),eO=e=>{let{agentId:t,isOpen:r,onClose:l,onUseMacro:i,resolvedTheme:o}=e,[c,d]=(0,n.useState)(null),[f,j]=(0,n.useState)(!1),[b,y]=(0,n.useState)(""),[z,S]=(0,n.useState)(""),[C,_]=(0,n.useState)(""),w="dark"===o?"gray.700":"gray.200",k="dark"===o?"gray.800":"gray.50",E="dark"===o?"gray.400":"gray.500",{data:W,mutate:T}=N(t),{trigger:A,isMutating:R}=M(t),{trigger:P,isMutating:D}=$(t),{trigger:I}=X(t),H=null==W?void 0:W.filter(e=>e.title.toLowerCase().includes(C.toLowerCase())||e.content.toLowerCase().includes(C.toLowerCase())),L=()=>{d(null),j(!1),y(""),S("")},F=async()=>{if(b.trim()&&z.trim())try{await A({title:b.trim(),content:z.trim()}),T(),L(),B.X.create({title:"Macro created",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error creating macro",type:"error",duration:3e3,closable:!0})}},K=async()=>{if(c&&b.trim()&&z.trim())try{await P({macro_id:c.id,title:b.trim(),content:z.trim()}),T(),L(),B.X.create({title:"Macro updated",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error updating macro",type:"error",duration:3e3,closable:!0})}},G=async e=>{try{await I({macro_id:e}),T(),(null==c?void 0:c.id)===e&&L(),B.X.create({title:"Macro deleted",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error deleting macro",type:"error",duration:3e3,closable:!0})}};if((0,n.useEffect)(()=>{r||(L(),_(""))},[r]),!r)return null;let O=f||c;return(0,s.jsxs)(h.a,{borderWidth:"1px",borderColor:w,borderRadius:"md",overflow:"hidden",children:[(0,s.jsxs)(u.z,{px:3,py:2,borderBottomWidth:"1px",borderColor:w,justifyContent:"space-between",children:[(0,s.jsxs)(u.z,{gap:1.5,children:[(0,s.jsx)(v.FrA,{size:14}),(0,s.jsx)(a.E,{fontWeight:"semibold",fontSize:"sm",children:"Macros"})]}),(0,s.jsxs)(u.z,{gap:1.5,children:[!O&&(0,s.jsxs)(x.$,{size:"2xs",colorPalette:"blue",onClick:()=>{L(),j(!0)},children:[(0,s.jsx)(v.GGD,{size:11}),(0,s.jsx)(a.E,{fontSize:"2xs",ml:.5,children:"New"})]}),(0,s.jsx)(x.$,{size:"2xs",variant:"ghost",onClick:l,children:(0,s.jsx)(v.yGN,{size:14})})]})]}),O?(0,s.jsx)(h.a,{px:3,py:3,children:(0,s.jsxs)(p.T,{gap:3,align:"stretch",children:[(0,s.jsx)(a.E,{fontWeight:"medium",fontSize:"xs",children:f?"Create New Macro":"Edit Macro"}),(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"2xs",mb:1,color:E,fontWeight:"medium",children:"Title"}),(0,s.jsx)(g.p,{value:b,onChange:e=>y(e.target.value),placeholder:"e.g. Greeting, Follow-up, Closing...",size:"xs",autoFocus:!0})]}),(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"2xs",mb:1,color:E,fontWeight:"medium",children:"Content"}),(0,s.jsx)(m.T,{value:z,onChange:e=>S(e.target.value),placeholder:"Type the macro message content...",size:"xs",minH:"80px",resize:"vertical"})]}),(0,s.jsxs)(u.z,{gap:2,children:[(0,s.jsx)(x.$,{size:"xs",colorPalette:"blue",onClick:f?F:K,disabled:!b.trim()||!z.trim()||R||D,loading:R||D,children:f?"Create":"Save"}),(0,s.jsx)(x.$,{size:"xs",variant:"ghost",onClick:L,children:"Cancel"})]})]})}):(0,s.jsxs)(h.a,{children:[(0,s.jsx)(h.a,{px:3,py:2,borderBottomWidth:"1px",borderColor:w,children:(0,s.jsxs)(u.z,{px:2,py:1,borderWidth:"1px",borderRadius:"md",borderColor:w,gap:1.5,children:[(0,s.jsx)(v.CKj,{size:12,color:"dark"===o?"#A0AEC0":"#718096"}),(0,s.jsx)(g.p,{value:C,onChange:e=>_(e.target.value),placeholder:"Search macros...",size:"xs",variant:"flushed",fontSize:"xs",border:"none",borderBottom:"none",_focus:{boxShadow:"none",borderColor:"transparent"}})]})}),(0,s.jsx)(h.a,{maxH:"200px",overflowY:"auto",px:3,py:2,children:H&&H.length>0?(0,s.jsx)(p.T,{gap:1.5,align:"stretch",children:H.map(e=>(0,s.jsxs)(h.a,{p:2,borderWidth:"1px",borderColor:w,borderRadius:"md",_hover:{bg:k},transition:"background 0.15s",children:[(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"flex-start",mb:.5,children:[(0,s.jsx)(a.E,{fontWeight:"medium",fontSize:"xs",children:e.title}),(0,s.jsxs)(u.z,{gap:.5,flexShrink:0,children:[(0,s.jsxs)(x.$,{size:"2xs",colorPalette:"blue",onClick:()=>{i(e.content)},title:"Use this macro",children:[(0,s.jsx)(v.YrT,{size:11}),(0,s.jsx)(a.E,{fontSize:"2xs",ml:.5,children:"Use"})]}),(0,s.jsx)(x.$,{size:"2xs",variant:"ghost",onClick:()=>{d(e),y(e.title),S(e.content),j(!1)}
1,title:"Edit macro",children:(0,s.jsx)(v.SG1,{size:11})}),(0,s.jsx)(x.$,{size:"2xs",variant:"ghost",colorPalette:"red",onClick:()=>G(e.id),title:"Delete macro",children:(0,s.jsx)(v.IXo,{size:11})})]})]}),(0,s.jsx)(a.E,{fontSize:"2xs",color:E,lineClamp:2,children:e.content})]},e.id))}):(0,s.jsxs)(h.a,{textAlign:"center",py:6,children:[(0,s.jsx)(v.FrA,{size:20,color:"dark"===o?"#4A5568":"#CBD5E0",style:{margin:"0 auto 6px"}}),(0,s.jsx)(a.E,{color:E,fontSize:"xs",children:C?"No macros match your search.":"No macros yet. Create one to speed up your replies."})]})})]})]})},eY={info:{palette:"blue",borderColor:"blue.300"},warning:{palette:"yellow",borderColor:"yellow.400"},error:{palette:"red",borderColor:"red.400"}},eJ=e=>{let{source:t,resolvedTheme:r,mutedTextColor:n,blockBorderColor:l,formatDate:i}=e,o=eH[t.result_status]||eH.error,c=(e=>{if(!e)return null;if(!e.cached)return"Just refreshed";if(null==e.age_minutes)return"Cached";let t=e.age_minutes;if(t<1)return"Cached just now";if(t<60)return"Cached ".concat(t,"m ago");let r=Math.floor(t/60);if(r<24)return"Cached ".concat(r,"h ago");let s=Math.floor(r/24);return"Cached ".concat(s,"d ago")})(t.cache),d=(t.profile||[]).filter(e=>!eI(e.value)),g=(t.recent_orders||[]).length>0,m=t.notices||[],j=m.length>0,b="ok"===t.result_status;return(0,s.jsxs)(p.T,{align:"stretch",gap:3,children:[(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"center",gap:2,flexWrap:"wrap",children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",children:[(0,s.jsx)(a.E,{fontSize:"md",fontWeight:"semibold",children:t.service}),(0,s.jsx)(f.Ex,{colorPalette:o.color,variant:"subtle",size:"sm",children:o.label})]}),c&&(0,s.jsxs)(u.z,{gap:1,color:n,fontSize:"xs",children:[(0,s.jsx)(v.Hbo,{size:11}),(0,s.jsx)(a.E,{children:c})]})]}),!b&&"no_email"===t.result_status&&(0,s.jsxs)(u.z,{p:3,borderWidth:"1px",borderColor:l,borderRadius:"md",bg:"dark"===r?"yellow.950/40":"yellow.50",gap:2,children:[(0,s.jsx)(v.eHT,{size:14}),(0,s.jsx)(a.E,{fontSize:"sm",color:n,children:t.message||"This session has no email — cannot query ".concat(t.service,".")})]}),!b&&"not_found"===t.result_status&&(0,s.jsxs)(u.z,{p:3,borderWidth:"1px",borderColor:l,borderRadius:"md",bg:"dark"===r?"gray.800":"gray.50",gap:2,children:[(0,s.jsx)(v.JXP,{size:14}),(0,s.jsx)(a.E,{fontSize:"sm",color:n,children:t.message||"No customer record found in ".concat(t.service,".")})]}),!b&&("error"===t.result_status||"timeout"===t.result_status)&&(0,s.jsxs)(u.z,{p:3,borderWidth:"1px",borderColor:"red.400",borderRadius:"md",bg:"dark"===r?"red.950/40":"red.50",gap:2,children:[(0,s.jsx)(v.eHT,{size:14,color:"#E53E3E"}),(0,s.jsx)(a.E,{fontSize:"sm",color:n,children:t.message||"".concat(t.service," lookup failed.")})]}),d.length>0&&(0,s.jsx)(p.T,{align:"stretch",gap:0,fontSize:"sm",children:d.map((e,t)=>(0,s.jsxs)(h.a,{py:2,borderBottomWidth:t<d.length-1?"1px":"0",borderBottomColor:l,children:[(0,s.jsx)(a.E,{fontSize:"xs",fontWeight:500,color:"dark"===r?"gray.400":"gray.500",mb:1,children:e.label}),(0,s.jsx)(h.a,{wordBreak:"break-word",children:(e=>{let{value:t,type:r,currency:n}=e;if(eI(t))return null;switch(r){case"email":{let e=String(t);return(0,s.jsx)("a",{href:"mailto:".concat(e),style:{color:"#3182CE",textDecoration:"none"},children:e})}case"phone":{let e=String(t),r=e.replace(/[^+\d]/g,"");return(0,s.jsx)("a",{href:"tel:".concat(r),style:{color:"#3182CE",textDecoration:"none"},children:e})}case"currency":return(0,s.jsx)(a.E,{as:"span",children:eD(t,n)});case"datetime":return(0,s.jsx)(a.E,{as:"span",children:eA(String(t))});case"number":return(0,s.jsx)(a.E,{as:"span",children:"number"==typeof t?t.toLocaleString():String(t)});case"bool":return(0,s.jsx)(a.E,{as:"span",children:t?"Yes":"No"});default:return(0,s.jsx)(a.E,{as:"span",whiteSpace:"pre-wrap",children:String(t)})}})(e)})]},e.key))}),j&&(0,s.jsx)(p.T,{align:"stretch",gap:2,children:m.map((e,t)=>{let l=eY[String(e.severity||"info")]||eY.info;return(0,s.jsxs)(u.z,{p:3,borderWidth:"1px",borderColor:l.borderColor,borderRadius:"md",bg:"dark"===r?"".concat(l.palette,".950/40"):"".concat(l.palette,".50"),gap:2,alignItems:"flex-start",children:[(0,s.jsx)(h.a,{flexShrink:0,mt:.5,children:(0,s.jsx)(v.eHT,{size:14})}),(0,s.jsx)(a.E,{fontSize:"sm",color:n,whiteSpace:"pre-wrap",children:e.text})]},t)})}),g&&(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontWeight:"semibold",fontSize:"sm",mb:2,children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v.y52,{size:14}),(0,s.jsxs)(a.E,{children:["Recent Orders (",t.recent_orders.length,")"]})]})}),(0,s.jsx)(p.T,{align:"stretch",gap:2,children:t.recent_orders.map((e,t)=>(0,s.jsx)(h.a,{p:3,borderWidth:"1px",borderColor:l,borderRadius:"md",bg:"dark"===r?"gray.800":"gray.50",children:(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"flex-start",ga
1p:2,flexWrap:"wrap",children:[(0,s.jsxs)(p.T,{align:"flex-start",gap:1,flex:"1",minW:"0",children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",flexWrap:"wrap",children:[(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"semibold",truncate:!0,children:e.order_number||"Order"}),e.status&&(0,s.jsx)(f.Ex,{size:"xs",colorPalette:"blue",variant:"subtle",children:e.status})]}),(0,s.jsxs)(u.z,{gap:3,fontSize:"xs",color:n,flexWrap:"wrap",children:[e.created_at&&(0,s.jsx)(a.E,{children:i(e.created_at)}),null!=e.total&&""!==e.total&&(0,s.jsx)(a.E,{children:eD(e.total,e.currency)}),e.tracking_number&&(0,s.jsxs)(a.E,{children:["Tracking: ",e.tracking_number]})]})]}),e.url&&(0,s.jsx)(x.$,{size:"xs",variant:"outline",onClick:()=>window.open(e.url,"_blank"),title:"Open order",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v.HaR,{size:11}),(0,s.jsx)(a.E,{children:"Open"})]})})]})},"".concat(e.order_number||"o","-").concat(t)))})]}),b&&0===d.length&&!g&&!j&&(0,s.jsx)(p.T,{py:6,gap:2,children:(0,s.jsxs)(a.E,{color:n,fontSize:"sm",textAlign:"center",children:[t.service," returned no data for this customer."]})})]})},eU=e=>{let{source:t,resolvedTheme:r,mutedTextColor:n,blockBorderColor:l,formatDate:i}=e,o=t.sessions||[],c="ok"===t.result_status;return(0,s.jsxs)(h.a,{children:[(0,s.jsxs)(u.z,{gap:1,mb:2,children:[(0,s.jsx)(v.mEP,{size:14}),(0,s.jsxs)(a.E,{fontWeight:"semibold",fontSize:"sm",children:["Past conversations",c&&o.length>0?" (".concat(o.length,")"):""]})]}),!c&&"no_email"===t.result_status&&(0,s.jsxs)(u.z,{p:3,borderWidth:"1px",borderColor:l,borderRadius:"md",bg:"dark"===r?"yellow.950/40":"yellow.50",gap:2,children:[(0,s.jsx)(v.eHT,{size:14}),(0,s.jsx)(a.E,{fontSize:"sm",color:n,children:t.message||"This session has no email yet — past conversations will appear here once the AI collects one."})]}),!c&&("error"===t.result_status||"timeout"===t.result_status)&&(0,s.jsxs)(u.z,{p:3,borderWidth:"1px",borderColor:"red.400",borderRadius:"md",bg:"dark"===r?"red.950/40":"red.50",gap:2,children:[(0,s.jsx)(v.eHT,{size:14,color:"#E53E3E"}),(0,s.jsx)(a.E,{fontSize:"sm",color:n,children:t.message||"Failed to load past conversations."})]}),c&&o.length>0&&(0,s.jsx)(p.T,{align:"stretch",gap:2,children:o.map(e=>(0,s.jsxs)(h.a,{p:3,borderWidth:"1px",borderColor:l,borderRadius:"md",bg:"dark"===r?"gray.800":"gray.50",children:[(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"center",mb:1.5,flexWrap:"wrap",gap:2,children:[(0,s.jsxs)(u.z,{gap:1.5,flexWrap:"wrap",children:[e.channel&&(0,s.jsx)(f.Ex,{size:"xs",variant:"subtle",colorPalette:"gray",children:e_(e.channel)}),e.summary_language&&(0,s.jsx)(f.Ex,{size:"xs",variant:"outline",colorPalette:"gray",textTransform:"uppercase",children:e.summary_language})]}),(0,s.jsx)(a.E,{fontSize:"2xs",color:n,children:i(e.last_update||e.created_at)})]}),e.summary?(0,s.jsx)(a.E,{fontSize:"xs",whiteSpace:"pre-wrap",lineHeight:"tall",children:e.summary}):(0,s.jsx)(a.E,{fontSize:"xs",color:n,fontStyle:"italic",children:"No summary generated yet."})]},e.session_id))}),c&&0===o.length&&(0,s.jsx)(a.E,{fontSize:"xs",color:n,fontStyle:"italic",children:"No past conversations for this customer yet."})]})},eq=e=>{var t,l,c,P,D,I,H,N,M,$;let{agentId:X,isDisabled:J=!1,view:q="inbox"}=e,V=ef[q],Q=(0,o.useRouter)(),Z=(0,n.useRef)(null),[ee,es]=(0,n.useState)("open"),[en,el]=(0,n.use
1State)(null),[ei,eo]=(0,n.useState)(null),[ec,ed]=(0,n.useState)(null),[eu,ex]=(0,n.useState)(!1),[em,ew]=(0,n.useState)(()=>{try{return"1"===window.localStorage.getItem("inbox:flowMode")}catch(e){return!1}}),[eD,eI]=(0,n.useState)(()=>{try{let e=window.localStorage.getItem("inbox:flowSlots"),t=e?parseInt(e,10):1;return 2===t||3===t?t:1}catch(e){return 1}}),[eH,e$]=(0,n.useState)([null,null,null]),[eX,eL]=(0,n.useState)(0),[eF,eK]=(0,n.useState)(new Set),[eY,eq]=(0,n.useState)(new Set),[eV,eQ]=(0,n.useState)(!1),[eZ,e0]=(0,n.useState)(!1),e1=(0,n.useRef)([null,null,null]),e2=(0,n.useRef)(new Set),e3=(0,n.useRef)(!1),e5=(0,n.useCallback)(e=>{ew(e);try{window.localStorage.setItem("inbox:flowMode",e?"1":"0")}catch(e){}e||eL(0)},[]),e4=(0,n.useCallback)(e=>{eI(e);try{window.localStorage.setItem("inbox:flowSlots",String(e))}catch(e){}},[]);(0,n.useEffect)(()=>{let e=window.matchMedia("(max-width: 1100px)"),t=()=>e0(e.matches);return t(),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]);let[e6,e9]=(0,n.useState)(1),[e8,e7]=(0,n.useState)(!1),[te,tt]=(0,n.useState)("session_id"),[tr,ts]=(0,n.useState)(""),[tn,tl]=(0,n.useState)(""),[ti,to]=(0,n.useState)(null),[ta,tc]=(0,n.useState)(null),[td,tu]=(0,n.useState)(""),[tx,th]=(0,n.useState)(""),[tp,tg]=(0,n.useState)(""),[tm,tf]=(0,n.useState)([]),[tj,tb]=(0,n.useState)(!1),[ty,tz]=(0,n.useState)(""),[tv,tS]=(0,n.useState)(()=>{try{return"drafter"===window.localStorage.getItem("inbox:rightPanelTab")?"drafter":"profile"}catch(e){return"profile"}}),[tC,t_]=(0,n.useState)(""),[tw,tk]=(0,n.useState)(""),[tE,tW]=(0,n.useState)(!1),[tT,tA]=(0,n.useState)(!1),[tR,tP]=(0,n.useState)(""),[tD,tI]=(0,n.useState)(new Set),[tH,tN]=(0,n.useState)(!1),[tM,t$]=(0,n.useState)(null),[tX,tL]=(0,n.useState)(!1),[tF,tB]=(0,n.useState)(!1),[tK,tG]=(0,n.useState)(!1),[tO,tY]=(0,n.use
1State)(!1),[tJ,tU]=(0,n.useState)(()=>{try{return"1"===window.localStorage.getItem("inbox:profileSidebarCollapsed")}catch(e){return!1}}),[tq,tV]=(0,n.useState)(0),[tQ,tZ]=(0,n.useState)(!1),[t0,t1]=(0,n.useState)(!1),[t2,t3]=(0,n.useState)(()=>{try{let e=window.localStorage.getItem("inbox:dismissedEscalationNotes");if(!e)return new Set;let t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(e=>"string"==typeof e)):new Set}catch(e){return new Set}}),t5=(0,n.useCallback)(e=>{try{window.localStorage.setItem("inbox:dismissedEscalationNotes",JSON.stringify(Array.from(e)))}catch(e){}},[]),t4=(0,n.useCallback)(e=>{t3(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),t5(r),r})},[t5]),t6=(0,n.useCallback)(e=>{t3(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),t5(r),r})},[t5]),[t9,t8]=(0,n.useState)(""),[t7,re]=(0,n.useState)(""),[rt,rr]=(0,n.useState)(""),[rs,rn]=(0,n.useState)(""),[rl,ri]=(0,n.useState)(""),[ro,ra]=(0,n.useState)([]),[rc,rd]=(0,n.useState)(""),[ru,rx]=(0,n.useState)(!1),[rh,rp]=(0,n.useState)(!1),rg=(0,n.useRef)(null),rm=(0,n.useRef)(null),rf=(0,n.useRef)(0),rj=(0,n.useRef)(null),rb=(0,n.useRef)(!0),ry=(0,n.useRef)(null),rz=(0,n.useRef)(null),rv=(0,n.useRef)(null),rS=(0,n.useRef)(null),rC=(0,n.useRef)(null),r_=(0,n.useRef)(""),rw=(0,n.useRef)(!1),rk=(0,n.useRef)(null),rE=(0,n.useRef)(null),rW=(0,n.useRef)(null),rT=(0,n.useRef)(null),rA=(0,n.useRef)(null),rR=(0,n.useRef)("reply"),rP=(0,n.useRef)(null),rD=(0,n.useRef)(0),rI=(0,n.useRef)(null),rH=(0,n.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:200;e.current&&(e.current.style.height="auto",e.current.style.height="".concat(Math.min(e.current.scrollHeight,t),"px"))},[]),rN=(0,n.useCallback)(()=>{let e=rg.current;e&&(rb.current=e.scrollHeight-e.scrollTop-e.clientHeight<80)},[]),rM=(0,n.useCallback)(()=>{requestAnimationFrame(()=>{let e=rg.current;e&&(e.scrollTop=e.scrollHeight),rb.current=!0})},[]),{resolvedTheme:r$}=(0,K.j)(),rX=G.kY.blockBorderColor[r$]||G.kY.blockBorderColor.dark,rL="dark"===r$?"gray.400":"gray.600",rF="gray.500",{typingBySession:rB,subscribe:rK}=(0,R.r)();(0,n.useEffect)(()=>{rS.current=ta},[ta]),(0,n.useEffect)(()=>{rC.current=null},[ta]),(0,n.useEffect)(()=>{r_.current=td},[td]),(0,n.useEffect)(()=>{rw.current=tj},[tj]),(0,n.useEffect)(()=>rK(e=>{var t,r;if("draft_ready"!==e.type)return;let s=null==(t=e.data)?void 0:t.session_id,n=null==(r=e.data)?void 0:r.draft_text;if(!s||!n||s!==rS.current||rw.current)return;let l=r_.current,i=rv.current;(""===l.trim()||l===i)&&(tu(n),rv.current=n)}),[rK]);let{data:rG,mutate:rO,error:rY}=(0,W.hU)(X||null,ee,e6,20,null,null,ei,en,ec,eu,q),{data:rJ}=(0,L.c4)(X||null),{data:rU,mutate:rq}=(0,W.WL)(X||null),rV=eZ?1:eD,rQ=eH.slice(0,rV).map(e=>null==e?void 0:e.session_id).filter(e=>!!e),{data:rZ,mutate:r0}=(0,W.MO)(X||null,q,ei,eu,rQ,em);(0,n.useEffect)(()=>{let e=setTimeout(()=>tl(tr),400);return()=>clearTimeout(e)},[tr]);let r1=ti?null:tn&&tn.trim().length>=T.Ak[te]?{[te]:tn.trim()}:null,{data:r2,isLoading:r3}=(0,W.lE)(X||null,r1,q),r5=!!tr&&!ti&&(tr!==tn||r3),r4=null==rG?void 0:rG.sessions,r6=(0,n.useMemo)(()=>ti?[ti]:r4?[...r4].sort((e,t)=>{var r,s;if("chat"!==q){let r=Number(+!!t.is_live)-Number(+!!e.is_live);if(0!==r)return r}let n=null!=(r=e.last_message_at)?r:"";return(null!=(s=t.last_message_at)?s:"").localeCompare(n)}):r4,[r4,ti,q]),r9=null==rG?void 0:rG.pagination,r8=r9?Math.ceil(r9.total/r9.page_size):1,{data:r7,mutate:se}=(0,W.a)(ta),{trigger:st,isMutating:sr}=(0,W.mn)(),{trigger:ss,isMutating:sn}=(0,W.cK)(),{trigger:sl,isMutating:si}=(0,W.KK)(),{trigger:so,isMutating:sa}=(0,W.rZ)(),{trigger:sc,isMutating:sd}=(0,W.my)(),{trigger:su,isMutating:sx}=(0,W.R_)(),{trigger:sh}=(0,W.Gu)(),{trigger:sp}=(0,W.Le)(),{trigger:sg}=(0,W.kB)(X||null),{trigger:sm}=(0,W.rA)(X||null),{trigger:sf}=(0,W.HT)(),{trigger:sj,isMutating:sb}=(0,W.Mj)(),{trigger:sy}=(0,W.JW)(),{trigger:sz}=(0,W.jO)(),{trigger:sv,isMutating:sS}=(0,W.sf)(),{trigger:sC}=(0,W.nm)(),{trigger:s_,isMutating:sw}=(0,W.Lh)(),sk=(0,n.useCallback)((e,t)=>{if(e)if(t){let t=Date.now();(t-rD.current>1e3||rI.current!==e)&&(rD.current=t,rI.current=e,sC({session_id:e,is_typing:!0}
1).catch(()=>{})),rP.current&&clearTimeout(rP.current),rP.current=setTimeout(()=>{rI.current=null,sC({session_id:e,is_typing:!1}).catch(()=>{})},3e3)}else rP.current&&(clearTimeout(rP.current),rP.current=null),rI.current=null,sC({session_id:e,is_typing:!1}).catch(()=>{})},[sC]),{data:sE}=(0,F.mW)(),{data:sW}=(0,F.fq)(),sT=null!=(I=null==sW?void 0:sW.id)?I:null,{data:sA,mutate:sR}=(0,W.e8)(tO?ta:null),{trigger:sP,isMutating:sD}=(0,W.p0)(),{invoke:sI}=(0,W.eu)(),{data:sH,isLoading:sN,isValidating:sM}=(0,W.fn)(ta&&!em&&!tJ&&X||null,!ta||em||tJ?null:ta,tq),s$=(0,n.useCallback)(e=>{tS(e);try{window.localStorage.setItem("inbox:rightPanelTab",e)}catch(e){}},[]),sX=(0,n.useCallback)(e=>{tU(e);try{window.localStorage.setItem("inbox:profileSidebarCollapsed",e?"1":"0")}catch(e){}},[]),sL=(0,n.useCallback)(e=>{s$(e),sX(!1),"drafter"===e&&setTimeout(()=>{var e;return null==(e=rT.current)?void 0:e.focus()},50)},[s$,sX]),sF=(0,n.useMemo)(()=>(null==sH?void 0:sH.sources)?sH.sources.filter(e=>"not_configured"!==e.result_status):[],[sH]),sB=(0,n.useMemo)(()=>(e=>{let t=e=>{if(eN(e))return Number.MAX_SAFE_INTEGER;let t=e.callable_name||"",r=eM.indexOf(t);return -1===r?999:r};return[...e].sort((e,r)=>t(e)-t(r))})(sF.filter(e=>!eN(e))),[sF]),sK=(0,n.useMemo)(()=>sF.find(eN)||null,[sF]);(0,n.useEffect)(()=>{tV(0),tA(!1),tP("")},[ta]);let sG=em&&(eH.find(e=>(null==e?void 0:e.session_id)===ta)||eH[eX])||(null==r6?void 0:r6.find(e=>e.session_id===ta))||null;sG&&(rC.current=sG);let sO=sG||(ta&&(null==(t=rC.current)?void 0:t.session_id)===ta?rC.current:null),sY=(0,n.useMemo)(()=>{var e;return null!=(e=null==r7?void 0:r7.filter(e=>"note"!==e.role))?e:[]},[r7]),sJ=(0,n.useMemo)(()=>{var e;return null!=(e=null==r7?void 0:r7.filter(e=>"note"===e.role))?e:[]},[r7]),sU=(0,n.useMemo)(()=>{var e;return null!=(e=[...sJ].sort((e,t)=>new Date(t.created_at||0).getTime()-new Date(e.created_at||0).getTime())[0])?e:null},[sJ]),sq=!!sO&&(ej.has(sO.source||"")||["email","amazon","form"].includes(null==(l=sO.channel)?void 0:l.toLowerCase())),sV=!!sO&&["widget","playground"].includes((null==(c=sO.channel)?void 0:c.toLowerCase())||"")&&"transfer_to_human"===sO.source,sQ=sq||sV,sZ=sq?"async":"live",s0=null!=(H=null==r6?void 0:r6.findIndex(e=>e.session_id===ta))?H:-1,s1=e=>{tc(e);let t=(null==r6?void 0:r6.find(t=>t.session_id===e))||null,r=(null==t?void 0:t.draft_text)||"";tu(r),rv.current=r||null,tf([]),t_(""),tk(""),tz(""),tW(!1),rf.current=0};(0,n.useEffect)(()=>{let e=()=>{if(em)return void e5(!1);tc(null)};return window.addEventListener("inboxNavigate",e),()=>window.removeEventListener("inboxNavigate",e)},[em,e5]),(0,n.useEffect)(()=>{if(!Q.isReady)return;let e=Q.query.session,t=Array.isArray(e)?e[0]:e;if(!t||Z.current===t)return;Z.current=t,tc(t),e9(1);let{session:r,...s}=Q.query;Q.replace({pathname:Q.pathname,query:s},void 0,{shallow:!0})},[Q.isReady,Q.query.session]),(0,n.useEffect)(()=>{e9(1)},[ee,en,ei,ec,eu]),(0,n.useEffect)(()=>{tI(new Set),tN(!1)},[ee,en,ei,ec,eu,e6,q,ti]),(0,n.useEffect)(()=>{if(!tH)return;let e=e=>{"Escape"===e.key&&s9()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[tH]),(0,n.useEffect)(()=>{requestAnimationFrame(()=>rH(rW,160))},[td,rH]),(0,n.useEffect)(()=>{let e=sY.length;if(e>rf.current){let e=rg.current;e&&e.scrollHeight-e.scrollTop-e.clientHeight<80&&(rb.current=!0),rb.current&&requestAnimationFrame(()=>{let e=rg.current;e&&(e.scrollTop=e.scrollHeight)})}rf.current=e},[sY]),(0,n.useEffect)(()=>{if(!ta){rj.current=null;return}0!==sY.length&&rj.current!==ta&&(rj.current=ta,rb.current=!0,requestAnimationFrame(()=>{let e=rg.current;e&&(e.scrollTop=e.scrollHeight)}))},[ta,sY.length]),(0,n.useEffect)(()=>{let e=rg.current;if(!e)return;let t=t=>{if(!rb.current)return;let r=t.target;if(!r)return;let s=r.tagName;("IMG"===s||"VIDEO"===s)&&(e.scrollTop=e.scrollHeight)};return e.addEventListener("load",t,!0),()=>e.removeEventListener("load",t,!0)},[]),(0,n.useEffect)(()=>{let e=rg.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=new ResizeObserver(()=>{let e=rg.current;if(!e)return;let t=rb.current;rb.current=e.scrollHeight-e.scrollTop-e.clientHeight<80,t&&(e.scrollTop=e.scrollHeight,rb.current=!0)});return t.observe(e),()=>t.disconnect()},[]),(0,n.useEffect)(()=>{tg(""),tL(!1),tB(!1)},[ta]);let s2=async()=>{var e,t;if(ta&&td.trim()&&!sr)try{let t={session_id:ta,message:td.trim()};if(tm.length>0&&(t.attachments=tm),sq){let e=eP(tC),r=eP(tw);e.length>0&&(t.cc=e),r.length>0&&(t.bcc=r)}((null==sO?void 0:sO.channel)==="widget"||(null==sO?void 0:sO.channel)==="playground")&&(null==sO?void 0:sO.source)==="transfer_to_human"&&sk(ta,!1),await st(t),tu(""),rv.current=null,tf([]),t_(""),tk(""),se(),rO(),null==(e=rW.current)||e.focus(),rM(),B.X.create({title:"Reply sent",type:"success",duration:3e3,closable:!0})}
1catch(e){console.error(e),null==(t=rW.current)||t.focus(),B.X.create({title:"Error sending reply",type:"error",duration:3e3,closable:!0})}},s3=async()=>{if(ta&&tx.trim())try{await ss({session_id:ta,message:tx.trim()}),th(""),se(),B.X.create({title:"Note added",type:"success",duration:3e3,closable:!0})}catch(e){console.error(e),B.X.create({title:"Error adding note",type:"error",duration:3e3,closable:!0})}},s5=async e=>{let t=e||ta;if(t)try{var r,s;if(await sl({session_id:t}),await rO(),B.X.create({title:"Session closed",type:"success",duration:3e3,closable:!0}),em){let e=eH.findIndex(e=>(null==e?void 0:e.session_id)===t);e>=0&&await nd(e,{extraExclude:[t]}),r0();return}let e=t===ta,n=e&&r6&&null!=(s=null!=(r=r6[s0+1])?r:r6[s0-1])?s:null;e&&(n&&"closed"!==ee?s1(n.session_id):"closed"!==ee&&tc(null))}catch(e){console.error(e),B.X.create({title:"Error closing session",type:"error",duration:3e3,closable:!0})}},s4=async()=>{if(ta)try{await so({session_id:ta}),rO(),B.X.create({title:"Session reopened",type:"success",duration:3e3,closable:!0})}catch(e){console.error(e),B.X.create({title:"Error reopening session",type:"error",duration:3e3,closable:!0})}},s6=async e=>{let t=e||ta;if(t)try{var r,s;if(await sc({session_id:t}),await rO(),B.X.create({title:"Ticket assigned to AI",type:"success",duration:3e3,closable:!0}),em){let e=eH.findIndex(e=>(null==e?void 0:e.session_id)===t);e>=0&&await nd(e,{extraExclude:[t]}),r0();return}let e=t===ta,n=e&&r6&&null!=(s=null!=(r=r6[s0+1])?r:r6[s0-1])?s:null;e&&(n&&"closed"!==ee?s1(n.session_id):"closed"!==ee&&tc(null))}catch(e){console.error(e),B.X.create({title:"Error assigning ticket to AI",type:"error",duration:3e3,closable:!0})}},s9=()=>{tI(new Set),tN(!1)},s8=async e=>{let t=Array.from(tD);if(0!==t.length)try{var r,s;let n=await su({session_ids:t,status:e}),l=null!=(r=null==n?void 0:n.updated)?r:0,i="closed"===e&&null!=ta&&tD.has(ta),o=i&&r6&&null!=(s=r6.find(e=>!tD.has(e.session_id)))?s:null;await rO(),s9(),t$(null),i&&"closed"!==ee&&(o?s1(o.session_id):tc(null));let a="closed"===e?"closed":"reopened";B.X.create({title:l===t.length?"".concat(l," ").concat(1===l?"conversation":"conversations"," ").concat(a):"".concat(l," of ").concat(t.length," ").concat(a," (others were already ").concat(e,")"),type:"success",duration:3e3,closable:!0})}catch(t){console.error(t),t$(null),B.X.create({title:"Error ".concat("closed"===e?"closing":"reopening"," conversations"),type:"error",duration:3e3,closable:!0})}},[s7,ne]=(0,n.useState)(!1),nt=async()=>{if(sO){ne(!0);try{let{downloadInboxConversationPdf:e}=await Promise.all([r.e(4155),r.e(347),r.e(2244),r.e(6985)]).then(r.bind(r,46985));e(sO,null!=r7?r7:[],e_(sO.channel))}catch(e){console.error(e),B.X.create({title:"Error generating PDF",type:"error",duration:3e3,closable:!0})}finally{ne(!1)}}},nr=async e=>{if(ta)try{await sh({session_id:ta,tag_ids:[e]}),rO(),rq(),tg(""),B.X.create({title:"Tag added",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error adding tag",type:"error",duration:3e3,closable:!0})}},ns=async e=>{if(ta&&e.trim())try{var t;let r=await sg({name:e.trim()}),s=null==r||null==(t=r.data)?void 0:t.id;s&&await sh({session_id:ta,tag_ids:[s]}),rO(),rq(),tg(""),B.X.create({title:"Tag created & added",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error creating tag",type:"error",duration:3e3,closable:!0})}},nn=async e=>{if(ta)try{await sp({session_id:ta,tag_ids:[e]}),rO(),rq(),B.X.create({title:"Tag removed",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error removing tag",type:"error",duration:3e3,closable:!0})}},nl=async e=>{try{await sm({tag_id:e}),rO(),rq(),B.X.create({title:"Tag deleted",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error deleting tag",type:"error",duration:3e3,closable:!0})}},ni=async e=>{if(ta)try{await sf({session_id:ta,account_id:e}),rO(),B.X.create({title:e?"Session assigned":"Session unassigned",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error assigning session",type:"error",duration:3e3,closable:!0})}},no=(e,t)=>e&&"object"==typeof e&&"message"in e&&"string"==typeof e.message?e.message:t,na=async e=>{try{let t=await sj({session_id:e}),r=null==t?void 0:t.data;return await rO(),r&&e$(t=>t.map(t=>(null==t?void 0:t.session_id)===e?r:t)),B.X.create({title:"Conversation claimed",type:"success",duration:2e3,closable:!0}),!0}catch(e){return B.X.create({title:no(e,"Could not claim this conversation"),type:"error",duration:4e3,closable:!0}),!1}},nc=async e=>{try{await sz({session_id:e}),await rO(),B.X.create({title:"Conversation released",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error releasing conversation",type:"error",duration:3e3,closable:!0})}},nd=(0,n.useCallback)(async(e,t)=>{if(!X)return;let r=[...e1.current.map(e=>null==e?void 0:e.session_id).filter(e=>!!e),...Array.from(e2.current),...(null==t?void 0:t.extraExclude)||[]];try{var s;let t=await sy({agent_id:X,channel_group:q,tag_ids:ei,unanswered_only:eu,exclude_session_ids:r}),n=null!=(s=null==t?void 0:t.data)?s:null;e$(t=>{let r=[...t];return r[e]=n,r}),n&&eq(e=>{let t=new Set(e);return t.delete(n.session_id),t}),r0(),rO()}catch(e){console.error(e),B.X.create({title:"Could not load the next conversation",type:"error",duration:3e3,closable:!0})}},[X,q,ei,eu,sy,r0,rO]),nu=(0,n.useCallback)(async e=>{if(X){eQ(!0);try{var t,r,s;let n=[null,null,null],l=Array.from(e2.current);if(e&&"open"===e.status)if(null!=e.assigned_to&&null!=sT&&e.assigned_to!==sT)B.X.create({title:"Open ticket belongs to ".concat(e.assigned_name||e.assigned_email||"another operator"),type:"info",duration:4e3,closable:!0});else try{if(null==e.assigned_to){let t=await sj({session_id:e.session_id});n[0]=null!=(r=null==t?void 0:t.data)?r:e}else n[0]=e;(null==(t=n[0])?void 0:t.session_id)&&l.push(n[0].session_id)}catch(e){B.X.create({title:no(e,"Could not claim the open conversation"),type:"info",duration:4e3,closable:!0})}for(let e=0;e<rV;e++)if(!n[e])try{let t=await sy({agent_id:X,channel_group:q,tag_ids:ei,unanswered_only:eu,exclude_session_ids:l}),r=null!=(s=null==t?void 0:t.data)?s:null;n[e]=r,(null==r?void 0:r.session_id)&&l.push(r.session_id)}catch(e){console.error(e)}e$(n),eL(0),r0(),rO()}finally{eQ(!1)}}},[X,sT,rV,q,ei,eu,sj,sy,r0,rO]),nx=(0,n.useCallback)(()=>{e3.current=!0,e5(!0),s$("profile"),sX(!0),nu(sO)},[e5,s$,nu,sO,sX]),nh=(0,n.useCallback)(()=>{let e=eH[eX];e3.current=!1,e5(!1),eK(new Set),(null==e?void 0:e.session_id)&&tc(e.session_id)},[e5,eH,eX]),np=async e=>{try{await sz({session_id:e}),eK(t=>{let r=new Set(t);return r.add(e),r});let t=eH.findIndex(t=>(null==t?void 0:t.session_id)===e);t>=0&&await nd(t,{extraExclude:[e]}),B.X.create({title:"Skipped",type:"success",duration:1500,closable:!0})}catch(e){B.X.create({title:"Could not skip this conversation",type:"error",duration:3e3,closable:!0})}};(0,n.useEffect)(()=>{e1.current=eH},[eH]),(0,n.useEffect)(()=>{e2.current=eF},[eF]),(0,n.useEffect)(()=>{em&&X&&!e3.current&&(e3.current=!0,sX(!0),nu(null))},[em,X,nu,sX]);let ng=(0,n.useRef)(rV);(0,n.useEffect)(()=>
1{if(!em){ng.current=rV;return}if(rV>ng.current)for(let e=ng.current;e<rV;e++)nd(e);ng.current=rV},[em,rV,nd]),(0,n.useEffect)(()=>{if(em)return rK(e=>{var t,r;let s=null==(t=e.data)?void 0:t.session_id,n=e1.current,l=s?n.findIndex(e=>(null==e?void 0:e.session_id)===s):-1;if("new_message_in_session"===e.type&&l>=0&&l!==eX&&eq(e=>new Set(e).add(s)),"session_closed"===e.type&&l>=0&&nd(l,{extraExclude:s?[s]:[]}),"session_assigned"===e.type&&l>=0){let t=null==(r=e.data)?void 0:r.account_id;null!=t&&null!=sT&&t!==sT&&(B.X.create({title:"This conversation was claimed by someone else",type:"info",duration:4e3,closable:!0}),nd(l,{extraExclude:s?[s]:[]}))}if(("new_conversation"===e.type||"session_reopened"===e.type)&&em){let e=n.findIndex((e,t)=>t<rV&&!e);e>=0&&nd(e),r0()}})},[em,rK,nd,eX,sT,rV,r0]),(0,n.useEffect)(()=>{if(!em)return;let e=e=>{if(e.altKey&&("1"===e.key||"2"===e.key||"3"===e.key)){e.preventDefault();let t=parseInt(e.key,10)-1;t<rV&&eL(t);return}let t=e.target;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||"p"!==e.key&&"P"!==e.key||(e.preventDefault(),sX(!1),s$("profile"))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[em,rV,s$,sX]);let nm=()=>{tA(!1),tP("")},nf=async()=>{if(!ta)return;let e=tR.trim();if(e===((null==sO?void 0:sO.subject)||"").trim())return void nm();try{await s_({session_id:ta,subject:e||null});let t=t=>t.session_id===ta?{...t,subject:e||null}:t;await rO(e=>e?{...e,sessions:e.sessions.map(t)}:e,{revalidate:!1}),(null==ti?void 0:ti.session_id)===ta&&to(t=>t?{...t,subject:e||null}:t),tA(!1),tP(""),B.X.create({title:"Subject updated",type:"success",duration:2e3,closable:!0})}catch(e){B.X.create({title:"Error updating subject",type:"error",duration:3e3,closable:!0})}},nj=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"live";if("async"===r){"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),t());return}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),t())},nb=async()=>{if(ta)try{await sP({session_id:ta,language:"en"}),sR(),B.X.create({title:"Summary generated",type:"success",duration:2e3,closable:!0})}catch(e){console.error(e),B.X.create({title:"Error generating summary",type:"error",duration:3e3,closable:!0})}},ny=(0,n.useCallback)(async(e,t)=>{if(!ta||tj)return;let r=td.trim()||void 0,s=(null==t?void 0:t.skipCurrentDraft)?void 0:r;tu(""),rv.current=null,tb(!0);let n=new AbortController;ry.current=n,await sI({sessionId:ta,instruction:e||void 0,currentDraft:s},e=>tu(t=>t+e),()=>{tb(!1),ry.current=null},e=>{tb(!1),ry.current=null,r&&tu(r),console.error(e),B.X.create({title:"Drafter error",description:e.message,type:"error",duration:3e3,closable:!0})},n.signal)},[ta,tj,td,sI]),nz=()=>{var e;null==(e=ry.current)||e.abort(),tb(!1),ry.current=null},nv=(0,n.useCallback)(async(e,t)=>{if(!ta||ru)return;let r=rt.trim()||void 0,s=(null==t?void 0:t.skipCurrentDraft)?void 0:r;rr(""),rx(!0);let n=new AbortController;rz.current=n,await sI({sessionId:ta,instruction:e||void 0,currentDraft:s},e=>rr(t=>t+e),()=>{rx(!1),rz.current=null},e=>{rx(!1),rz.current=null,r&&rr(r),console.error(e),B.X.create({title:"Drafter error",description:e.message,type:"error",duration:3e3,closable:!0})},n.signal)},[ta,ru,rt,sI]),nS=()=>{var e;null==(e=rz.current)||e.abort(),rx(!1),rz.current=null},nC=(e,t)=>{let r=e.target.files;if(!r)return;let s="reply"===t?tf:ra;Array.from(r).forEach(e=>{if(!eb.includes(e.type))return void B.X.create({title:"Unsupported file type: ".concat(e.type),type:"error",duration:3e3,closable:!0});let t=new FileReader;t.onload=()=>{let r=t.result.split(",")[1];s(t=>[...t,{filename:e.name,content_type:e.type,data:r}])},t.readAsDataURL(e)}),e.target.value=""},n_=(e,t)=>{("reply"===t?tf:ra)(t=>t.filter((t,r)=>r!==e))},nw=async()=>{if(X&&t9.trim()&&t7.trim()&&rt.trim())try{let e=eP(t9);if(0===e.length)return;let t={agent_id:X,to:e,subject:t7.trim(),message:rt.trim()},r=eP(rs),s=eP(rl);r.length>0&&(t.cc=r),s.length>0&&(t.bcc=s),ro.length>0&&(t.attachments=ro),await sv(t),rO(),t1(!1),t8(""),re(""),rr(""),rn(""),ri(""),ra([]),B.X.create({title:"Email sent",description:"Inbox session created",type:"success",duration:3e3,closable:!0})}catch(e){console.error(e),B.X.create({title:"Error sending email",type:"error",duration:3e3,closable:!0})}},nk=()=>{ts(""),tl(""),to(null),e7(!1)};return rY?(0,s.jsx)(a.E,{color:"red.500",children:"Failed to load inbox sessions."}):(0,s.jsxs)(j.s,{direction:"column",h:"100%",minH:0,overflow:"hidden",children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",flexShrink:0,px:4,py:2,borderBottomWidth:"1px",borderBottomColor:rX,children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",flexShrink:0,children:[(0,s.jsx)(a.E,{fontSize:"xl",fontWeight:"bold",children:V.title}),em?(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"purple",variant:"solid",children:"Flow"}):r9?(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"blue",variant:"subtle",children:r9.total}):null,em&&(0,s.jsx)(a.E,{fontSize:"sm",color:rF,children:eV?"Loading…":"".concat(null!=(N=null==rZ?void 0:rZ.remaining)?N:0," waiting")})]}),!em&&(0,s.jsxs)(u.z,{gap:2,alignItems:"center",flex:1,minW:0,overflowX:"auto",css:{scrollbarWidth:"thin"},children:[(0,s.jsx)(b.MQ,{size:"sm",w:"120px",flexShrink:0,children:(0,s.jsx)(b.uT,{value:ee||"all",onChange:e=>{let t=e.target.value;es("all"===t?null:t)},children:eg.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,s.jsxs)(x.$,{size:"sm",variant:eu?"solid":"outline",colorPalette:eu?"yellow":"gray",onClick:()=>ex(e=>!e),title:"Show only tickets with unanswered customer messages",flexShrink:0,children:[(0,s.jsx)(v.eHT,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Needs response"})]}),rU&&rU.length>0&&(0,s.jsx)(eB,{icon:(0,s.jsx)(v.cnX,{size:14}),title:"Filter by tag",menuMinW:"220px",activeColorPalette:"purple",activeLabel:ei&&null!=(M=null==(P=rU.find(e=>e.id===ei))?void 0:P.name)?M:null,selectValue:ei||"all",options:[{value:"all",label:"All Tags"},...rU.map(e=>({value:e.id,label:e.name}))],onSelectChange:e=>eo("all"===e?null:e),onClear:()=>eo(null),resolvedTheme:r$}),sE&&sE.length>0&&(0,s.jsx)(eB,{icon:(0,s.jsx)(v.JXP,{size:14}),title:"Filter by assignee",menuMinW:"260px",activeColorPalette:"teal",activeLabel:null!=ec?null!=($=null==(D=sE.find(e=>
1e.id===ec))?void 0:D.email)?$:"#".concat(ec):null,selectValue:null!=ec?String(ec):"all",options:[{value:"all",label:"All Assignees"},...sE.map(e=>({value:String(e.id),label:e.email}))],onSelectChange:e=>ed("all"===e?null:parseInt(e,10)),onClear:()=>ed(null),resolvedTheme:r$})]}),(0,s.jsx)(u.z,{gap:2,flexShrink:0,children:em?(0,s.jsxs)(s.Fragment,{children:[!eZ&&(0,s.jsx)(u.z,{gap:1,borderWidth:"1px",borderColor:rX,borderRadius:"md",p:.5,children:[1,2,3].map(e=>(0,s.jsx)(x.$,{size:"xs",variant:rV===e&&eD===e?"solid":"ghost",colorPalette:eD===e?"purple":"gray",onClick:()=>e4(e),title:"Work ".concat(e," conversation").concat(1===e?"":"s"," at a time"),children:e},e))}),(0,s.jsx)(x.$,{size:"sm",variant:"outline",onClick:nh,title:"Exit Flow mode and return to the mailbox",children:"Exit Flow mode"})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(x.$,{size:"sm",variant:"outline",colorPalette:"purple",onClick:nx,title:"Enter Flow mode — work the next conversations one after another",children:(0,s.jsxs)(u.z,{gap:1.5,children:[(0,s.jsx)(a.E,{children:"Flow mode"}),(0,s.jsx)(f.Ex,{colorPalette:"teal",size:"xs",variant:"subtle",css:{letterSpacing:"0.04em"},children:"NEW"})]})}),(0,s.jsx)(x.$,{size:"sm",variant:e8||ti?"solid":"outline",colorPalette:e8||ti?"blue":"gray",onClick:()=>{e8?nk():e7(!0)},title:e8?"Close search":"Search inbox",borderColor:"dark"===r$?"gray.600":"gray.300",px:2,children:(0,s.jsx)(v.CKj,{size:14})}),(0,s.jsxs)(x.$,{size:"sm",variant:tH?"solid":"outline",colorPalette:tH?"blue":"gray",onClick:()=>{tH?s9():tN(!0)},disabled:!!ti,title:tH?"Cancel selection":"Select conversations",borderColor:tH||"dark"!==r$?void 0:"gray.600",px:2,children:[(0,s.jsx)(v.NLe,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:tH?"Cancel":"Select"})]}),sO&&(0,s.jsxs)(u.z,{gap:2,alignItems:"center",mr:1,children:[r6&&s0>=0&&(0,s.jsxs)(a.E,{fontSize:"xs",color:rF,children:[s0+1," of ",r6.length]}),(0,s.jsx)(x.$,{size:"sm",variant:"outline",onClick:()=>{r6&&!(s0<=0)&&s1(r6[s0-1].session_id)},disabled:s0<=0,borderColor:"dark"===r$?"gray.600":"gray.300",px:2,title:"Previous ticket",children:(0,s.jsx)(v.irw,{size:14})}),(0,s.jsxs)(x.$,{size:"sm",variant:"outline",onClick:()=>{!r6||s0<0||s0>=r6.length-1||s1(r6[s0+1].session_id)},disabled:!r6||s0>=r6.length-1,borderColor:"dark"===r$?"gray.600":"gray.300",children:[(0,s.jsx)(a.E,{fontSize:"xs",mr:1,children:"Next"}),(0,s.jsx)(v.fOo,{size:14})]})]}),(0,s.jsxs)(x.$,{size:"sm",colorPalette:"blue",onClick:()=>t1(!0),children:[(0,s.jsx)(v.kGk,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Send Email"})]})]})})]}),e8&&!em&&(0,s.jsxs)(h.a,{px:4,py:2,flexShrink:0,borderBottomWidth:"1px",borderBottomColor:rX,bg:"dark"===r$?"gray.950":"gray.50",children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",children:[(0,s.jsx)(h.a,{flex:1,children:(0,s.jsx)(A.Ay,{selectedField:te,onFieldChange:e=>{tt(e),ts(""),tl(""),to(null)},value:tr,onValueChange:e=>{ts(e),ti&&to(null)},results:r1?r2:void 0,loading:r5,onResultSelect:e=>{to(e),tt("session_id"),ts(e.session_id),tl(e.session_id),tc(e.session_id),tu(""),tf([]),t_(""),tk(""),tz(""),tW(!1),rf.current=0},getResultKey:e=>e.session_id,emptyHint:"No inbox sessions found",autoFocus:!0,renderResult:e=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",children:[(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"semibold",truncate:!0,flex:1,children:(0,Y.K9)(e)}),ek(q,ee)&&(0,s.jsx)(f.Ex,{colorPalette:ez(e.status),size:"sm",variant:"subtle",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:e.status})}),eE(q,!!e.is_live)&&(0,s.jsx)(f.Ex,{colorPalette:"green",size:"sm",variant:"solid",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:"Live"})}),eW(q,e.source)&&(0,s.jsx)(f.Ex,{colorPalette:eS(e.source),size:"sm",variant:"subtle",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:eC(e.source)})}),e.channel&&(0,s.jsx)(f.Ex,{colorPalette:"gray",size:"sm",variant:"subtle",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:e_(e.channel)})})]}),(0,s.jsxs)(u.z,{gap:2,mt:.5,flexWrap:"wrap",children:[e.customer_email&&(0,s.jsx)(a.E,{fontSize:"xs",color:rF,truncate:!0,children:e.customer_email}),e.customer_phone&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(a.E,{fontSize:"xs",color:rF,children:"\xb7"}),(0,s.jsx)(a.E,{fontSize:"xs",color:rF,children:e.customer_phone})]}),e.order_id&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(a.E,{fontSize:"xs",color:rF,children:"\xb7"}),(0,s.jsxs)(a.E,{fontSize:"xs",color:rF,children:["Order #",e.order_id]})]})]}),e.subject&&(0,s.jsx)(a.E,{fontSize:"xs",color:rF,truncate:!0,mt:.5,children:e.subject})]})})}),(0,s.jsx)(x.$,{size:"sm",variant:"ghost",onClick:nk,title:"Close search",children:(0,s.jsx)(v.yGN,{size:14})})]}),ti&&(0,s.jsx)(a.E,{fontSize:"xs",color:rF,mt:1,children:"Showing matched session — clear search to return to your filtered inbox."})]}),(0,s.jsxs)(j.s,{flex:1,minH:0,minW:0,overflow:"hidden",children:[!em&&(0,s.jsxs)(j.s,{direction:"column",w:"360px",flexShrink:0,minH:0,borderRightWidth:"1px",borderRightColor:rX,bg:"dark"===r$?"gray.950":"white",children:[tH&&tD.size>0&&(0,s.jsxs)(u.z,{flexShrink:0,px:3,py:2,gap:2,borderBottomWidth:"1px",borderBottomColor:rX,bg:"dark"===r$?"blue.950":"blue.50",children:[(0,s.jsxs)(a.E,{fontSize:"sm",fontWeight:"semibold",flex:1,children:[tD.size," selected"]}),(0,s.jsxs)(x.$,{size:"xs",colorPalette:"red",variant:"outline",onClick:()=>t$("closed"),disabled:sx,title:"Close selected conversations",children:[(0,s.jsx)(v.yGN,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Close"})]}),(0,s.jsxs)(x.$,{size:"xs",colorPalette:"green",variant:"outline",onClick:()=>t$("open"),disabled:sx,title:"Reopen selected conversations",children:[(0,s.jsx)(v.VI6,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Open"})]}),(0,s.jsx)(x.$,{size:"xs",variant:"ghost",onClick:()=>tI(new Set),disabled:sx,title:"Clear selection",children:(0,s.jsx)(v.yGN,{size:14})})]}),(0,s.jsxs)(h.a,{flex:1,minH:0,overflowY:"auto",children:[r6&&r6.length>0&&(0,s.jsx)(j.s,{direction:"column",children:r6.map((e,t)=>{var r,l;let i=e.session_id===ta,o=tD.has(e.session_id),c=e.unanswered_count>0,d=(null!=(l=e.channel)?l:"").toLowerCase(),x="whatsapp"===d?{icon:(0,s.jsx)(v.QFc,{size:12}),text:e.customer_phone||e.whatsapp_username||(0,Y.K9)(e)}:"email"===d||"form"===d?{icon:(0,s.jsx)(v.pHD,{size:12}),text:e.customer_email||(0,Y.K9)(e)}:"instagram"===d?{icon:(0,s.jsx)(v.mEP,{size:12}),text:e.instagram_username?"@".concat(e.instagram_username):(0,Y.K9)(e)}:"messenger"===d?{icon:(0,s.jsx)(v.mEP,{size:12}),text:e.messenger_username||(0,Y.K9)(e)}:{icon:(0,s.jsx)(v.JXP,{size:12}),text:e.customer_name||(0,Y.K9)(e)},g=(e=>{var t,r,s,n;if((e=>{let t=(null!=e?e:"").toLowerCase();return"email"===t||"form"===t||"amazon"===t})(e.channel)){let t=null==(n=e.subject)?void 0:n.trim();return t?{text:eT(t),kind:"subject"}:null}let l=null==(t=e.last_customer_message)?void 0:t.trim();if(l)return{text:eT(l),kind:"customer"};let i=null==(r=e.escalation_note)?void 0:r.trim();if(i)return{text:eT(i),kind:"escalation_note"};let o=null==(s=e.subject)?void 0:s.trim();if(o)return{text:eT(o),kind:"subject"};let a=(e=>{switch(e){case"transfer_to_human":return"Handed over — waiting for customer";case"escalate_to_inbox":return"Escalated — awaiting customer reply";
1case"inbound":return"Inbound — no message yet";case"outbound":return"Outbound email";case"send_to_inbox":return"Sent to inbox";default:return null}})(e.source);return a?{text:a,kind:"placeholder"}:null})(e),m=i?"dark"===r$?"blue.950":"blue.50":c?"dark"===r$?"yellow.950":"yellow.50":void 0;return(0,s.jsxs)(n.Fragment,{children:[(0,s.jsx)(h.a,{px:3,py:2.5,cursor:"pointer",transition:"background 0.1s",borderLeftWidth:"3px",borderLeftColor:i?"blue.500":c?"yellow.500":"transparent",bg:m,_hover:{bg:i?m:"dark"===r$?"gray.800":"gray.50"},onClick:()=>tH?(e=>{tI(t=>{let r=new Set(t);if(r.has(e))r.delete(e);else{if(r.size>=25)return B.X.create({title:"You can select up to ".concat(25," at a time"),type:"info",duration:3e3,closable:!0}),t;r.add(e)}return r})})(e.session_id):s1(e.session_id),children:(0,s.jsxs)(u.z,{gap:2.5,align:"flex-start",children:[tH&&(0,s.jsx)(h.a,{role:"checkbox","aria-checked":o,mt:.5,flexShrink:0,w:"18px",h:"18px",borderWidth:"1.5px",borderRadius:"sm",borderColor:o?"blue.500":"dark"===r$?"gray.600":"gray.400",bg:o?"blue.500":"transparent",color:"white",display:"flex",alignItems:"center",justifyContent:"center",children:o&&(0,s.jsx)(v.YrT,{size:12})}),(0,s.jsxs)(p.T,{gap:1.5,align:"stretch",flex:1,minW:0,children:[(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"center",gap:2,children:[(0,s.jsxs)(u.z,{gap:1.5,flex:1,minW:0,color:i?void 0:rL,children:[x.icon,(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"semibold",truncate:!0,children:x.text})]}),(0,s.jsx)(a.E,{fontSize:"2xs",color:rF,flexShrink:0,children:eA(e.last_message_at||e.updated_at)})]}),(0,s.jsxs)(u.z,{gap:1.5,flexWrap:"wrap",children:[ek(q,ee)&&(0,s.jsx)(f.Ex,{colorPalette:ez(e.status),size:"sm",variant:"subtle",children:(0,s.jsxs)(u.z,{gap:.5,children:[ev(e.status),(0,s.jsx)(a.E,{fontSize:"2xs",children:e.status})]})}),eE(q,!!e.is_live)&&(0,s.jsx)(f.Ex,{colorPalette:"green",size:"sm",variant:"solid",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.X6_,{size:9}),(0,s.jsx)(a.E,{fontSize:"2xs",children:"Live"})]})}),eW(q,e.source)&&(0,s.jsx)(f.Ex,{colorPalette:eS(e.source),size:"sm",variant:"subtle",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.L7s,{size:9}),(0,s.jsx)(a.E,{fontSize:"2xs",children:eC(e.source)})]})}),!!e.channel&&"whatsapp"!==q&&(0,s.jsx)(f.Ex,{colorPalette:"gray",size:"sm",variant:"subtle",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:e_(e.channel)})}),c&&(0,s.jsx)(f.Ex,{colorPalette:"yellow",size:"sm",variant:"solid",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.pHD,{size:9}),(0,s.jsx)(a.E,{fontSize:"2xs",children:1===e.unanswered_count?"1 unanswered":"".concat(e.unanswered_count," unanswered")})]})}),!ep.has(q)&&(null==(r=e.tags)?void 0:r.map(e=>(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"purple",variant:ei===e.id?"solid":"subtle",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:e.name})},e.id)))]}),g&&(0,s.jsx)(a.E,{fontSize:"xs",color:rF,fontWeight:"normal",lineClamp:2,lineHeight:"short",children:g.text})]})]})}),t<r6.length-1&&(0,s.jsx)(y.w,{})]},e.session_id)})}),r6&&0===r6.length&&(0,s.jsx)(h.a,{m:3,p:6,textAlign:"center",borderWidth:"1px",borderRadius:"md",borderStyle:"dashed",children:(0,s.jsx)(a.E,{color:rF,fontSize:"sm",children:ee||en||ei||null!=ec||eu?"No inbox sessions match the current filters.":"No inbox sessions yet. Sessions will appear here when the AI escalates or hands over."})})]}),r9&&r8>1&&(0,s.jsx)(h.a,{flexShrink:0,px:3,py:2,borderTopWidth:"1px",borderTopColor:rX,children:(0,s.jsxs)(u.z,{justifyContent:"center",gap:3,children:[(0,s.jsxs)(x.$,{size:"xs",variant:"outline",onClick:()=>e9(e=>Math.max(1,e-1)),disabled:e6<=1,children:[(0,s.jsx)(v.irw,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Previous"})]}),(0,s.jsxs)(a.E,{fontSize:"xs",color:rF,children:["Page ",e6," of ",r8]}),(0,s.jsxs)(x.$,{size:"xs",variant:"outline",onClick:()=>e9(e=>e+1),disabled:e6>=r8,children:[(0,s.jsx)(a.E,{fontSize:"xs",mr:1,children:"Next"}),(0,s.jsx)(v.fOo,{size:14})]})]})})]}),em?(0,s.jsx)(u.z,{flex:1,minW:0,minH:0,gap:2,p:2,align:"stretch",justify:1===rV?"center":void 0,children:Array.from({length:r
1V}).map((e,t)=>{let r=eH[t],n=1===rV;return r?(0,s.jsx)(h.a,{flex:1,minW:0,minH:0,maxW:n?"900px":void 0,w:n?"100%":void 0,display:"flex",children:(0,s.jsx)(eh,{session:r,variant:"flow",compact:rV>1,isFocused:eX===t,hasUnreadPulse:eY.has(r.session_id),isDisabled:J,currentAccountId:sT,onFocus:()=>{eL(t),tc(r.session_id),eq(e=>{if(!e.has(r.session_id))return e;let t=new Set(e);return t.delete(r.session_id),t})},onCloseSession:e=>void s5(e),onAssignToAi:e=>void s6(e),onSkip:e=>void np(e),onClaim:e=>void na(e),onRelease:e=>void nc(e),onOpenTags:()=>{tc(r.session_id),tB(!0)},onOpenNotes:()=>{tc(r.session_id),tZ(!0)},onOpenSummary:()=>{tc(r.session_id),tY(!0)},dismissedEscalationNotes:t2,dismissEscalationNote:t4,restoreEscalationNote:t6,agentId:X||null,isClosing:si,isClaiming:sb})},r.session_id):(0,s.jsxs)(j.s,{flex:1,minW:0,maxW:n?"900px":void 0,w:n?"100%":void 0,direction:"column",align:"center",justify:"center",borderWidth:"1px",borderColor:rX,borderRadius:"md",bg:"dark"===r$?"gray.950":"white",children:[(0,s.jsx)(v._Y7,{size:28}),(0,s.jsx)(a.E,{mt:3,fontWeight:"semibold",children:"You're caught up"}),(0,s.jsx)(a.E,{fontSize:"sm",color:rF,mt:1,children:"New conversations will appear here automatically."})]},"empty-".concat(t))})}):(0,s.jsx)(j.s,{flex:1,minW:0,minH:0,direction:"column",overflow:"hidden",bg:"dark"===r$?"gray.950":"white",children:sO?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(h.a,{flexShrink:0,px:6,py:3,bg:"dark"===r$?"gray.900":"gray.50/60",children:(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"flex-start",children:[(0,s.jsxs)(p.T,{align:"flex-start",gap:1,flex:1,children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",flexWrap:"wrap",children:[(0,s.jsx)(v.JXP,{size:16}),(0,s.jsx)(a.E,{fontSize:"md",fontWeight:"semibold",children:(0,Y.K9)(sO)}),(0,s.jsx)(f.Ex,{colorPalette:ez(sO.status),size:"sm",children:(0,s.jsxs)(u.z,{gap:.5,children:[ev(sO.status),(0,s.jsx)(a.E,{fontSize:"2xs",children:sO.status})]})}),sO.unanswered_count>0&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"yellow",variant:"solid",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.pHD,{size:10}),(0,s.jsx)(a.E,{fontSize:"2xs",children:1===sO.unanswered_count?"1 unanswered":"".concat(sO.unanswered_count," unanswered")})]})}),sO.source&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:eS(sO.source),variant:"subtle",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.L7s,{size:10}),(0,s.jsx)(a.E,{fontSize:"2xs",children:eC(sO.source)})]})}),sO.order_id&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"blue",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.est,{size:10}),(0,s.jsx)(a.E,{fontSize:"2xs",children:sO.order_id})]})}),sO.channel&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"gray",children:(0,s.jsxs)(u.z,{gap:.5,children:[(0,s.jsx)(v.mEP,{size:10}),(0,s.jsx)(a.E,{fontSize:"2xs",children:e_(sO.channel)})]})}),sO.assigned_email&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"blue",variant:"subtle",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:sO.assigned_email})}),sO.tags&&sO.tags.length>0&&sO.tags.map(e=>(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"purple",variant:"subtle",children:(0,s.jsx)(a.E,{fontSize:"2xs",children:e.name})},e.id))]}),tT?(0,s.jsxs)(u.z,{gap:1,w:"100%",maxW:"560px",children:[(0,s.jsx)(g.p,{size:"sm",value:tR,onChange:e=>tP(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),nf()):"Escape"===e.key&&(e.preventDefault(),nm())},placeholder:"Email subject...",autoFocus:!0,disabled:sw}),(0,s.jsx)(d.K,{"aria-label":"Save subject",size:"xs",variant:"ghost",colorPalette:"green",onClick:nf,loading:sw,disabled:sw,children:(0,s.jsx)(v.YrT,{size:14})}),(0,s.jsx)(d.K,{"aria-label":"Cancel editing subject",size:"xs",variant:"ghost",onClick:nm,disabled:sw,children:(0,s.jsx)(v.yGN,{size:14})})]}):(0,s.jsxs)(u.z,{gap:1,maxW:"100%",children:[(0,s.jsx)(a.E,{fontSize:"sm",color:sO.subject?rL:rF,fontWeight:"medium",truncate:!0,fontStyle:sO.subject?void 0:"italic",children:sO.subject||"No subject"}),(0,s.jsx)(d.K,{"aria-label":"Edit subject",size:"2xs",variant:"ghost",onClick:()=>{tP((null==sO?void 0:sO.subject)||""),tA(!0)}
1,title:"Edit subject",flexShrink:0,children:(0,s.jsx)(v.SG1,{size:12})})]})]}),(0,s.jsx)(x.$,{size:"sm",variant:"outline",onClick:nt,disabled:s7||!r7,loading:s7,borderColor:"dark"===r$?"gray.600":"gray.300",_hover:{bg:"dark"===r$?"gray.700":"gray.100"},title:"Download conversation as PDF","aria-label":"Download conversation as PDF",flexShrink:0,p:0,minW:"32px",h:"32px",borderRadius:"md",mt:-1,mr:-2,children:(0,s.jsx)(v.a4x,{size:16})})]})}),sO.escalation_note&&(t2.has(sO.session_id)?(0,s.jsx)(h.a,{flexShrink:0,px:6,py:1.5,borderBottomWidth:"1px",borderBottomColor:rX,children:(0,s.jsxs)(x.$,{size:"xs",variant:"ghost",colorPalette:"orange",onClick:()=>t6(sO.session_id),title:"Show AI escalation note",children:[(0,s.jsx)(v.eHT,{size:12}),(0,s.jsx)(a.E,{fontSize:"2xs",ml:1,children:"Show AI escalation note"})]})}):(0,s.jsx)(h.a,{flexShrink:0,px:6,py:2,bg:"dark"===r$?"orange.950/40":"orange.50/60",borderBottomWidth:"1px",borderBottomColor:"dark"===r$?"orange.800":"orange.200",borderLeftWidth:"3px",borderLeftColor:"dark"===r$?"orange.600":"orange.300",children:(0,s.jsxs)(u.z,{gap:2,alignItems:"flex-start",children:[(0,s.jsx)(h.a,{pt:.5,flexShrink:0,color:"dark"===r$?"orange.300":"orange.700",children:(0,s.jsx)(v.eHT,{size:14})}),(0,s.jsxs)(p.T,{align:"stretch",gap:.5,flex:1,minW:0,children:[(0,s.jsx)(a.E,{fontSize:"xs",fontWeight:"semibold",color:"dark"===r$?"orange.300":"orange.700",children:"AI Escalation Note"}),(0,s.jsx)(a.E,{fontSize:"sm",whiteSpace:"pre-wrap",color:"dark"===r$?"orange.200":"orange.800",children:sO.escalation_note})]}),(0,s.jsx)(x.$,{size:"xs",variant:"ghost",onClick:()=>t4(sO.session_id),title:"Dismiss escalation note","aria-label":"Dismiss escalation note",p:1,minW:"22px",h:"22px",flexShrink:0,children:(0,s.jsx)(v.yGN,{size:14})})]})})),(0,s.jsx)(h.a,{ref:rg,flex:1,overflowY:"auto",px:6,py:4,onScroll:rN,children:sY.length>0?(0,s.jsxs)(p.T,{align:"stretch",gap:0,children:[(()=>{let e="";return sY.map(t=>{let r=t.created_at?(0,C.GP)(new Date(t.created_at),"MMM dd, yyyy"):"",l=r!==e;return e=r,(0,s.jsxs)(n.Fragment,{children:[l&&r&&(0,s.jsxs)(j.s,{align:"center",my:3,children:[(0,s.jsx)(y.w,{flex:1}),(0,s.jsx)(a.E,{fontSize:"2xs",color:rF,px:3,flexShrink:0,children:r}),(0,s.jsx)(y.w,{flex:1})]}),(0,s.jsx)(eG,{message:t,resolvedTheme:r$})]},t.id)})})(),(0,s.jsx)("div",{ref:rm,"aria-hidden":!0})]}):(0,s.jsx)(h.a,{textAlign:"center",py:8,children:(0,s.jsx)(a.E,{color:rF,fontSize:"sm",children:"No messages in this conversation yet."})})}),(0,s.jsxs)(h.a,{flexShrink:0,px:6,py:3,boxShadow:"dark"===r$?"0 -1px 0 0 rgba(255,255,255,0.06)":"0 -1px 0 0 rgba(0,0,0,0.06)",children:[sU&&(0,s.jsx)(p.T,{align:"stretch",gap:2,mb:3,children:sU&&(0,s.jsxs)(h.a,{p:3,borderWidth:"1px",borderColor:"dark"===r$?"yellow.700":"yellow.200",borderLeftWidth:"3px",borderLeftColor:"dark"===r$?"yellow.600":"yellow.300",borderRadius:"sm",bg:"dark"===r$?"yellow.900":"yellow.50",children:[(0,s.jsxs)(u.z,{gap:2,mb:1,justifyContent:"space-between",children:[(0,s.jsxs)(u.z,{gap:2,children:[(0,s.jsx)(v.jH2,{size:14,color:"dark"===r$?"#ECC94B":"#B7791F"}),(0,s.jsxs)(a.E,{fontSize:"xs",fontWeight:"semibold",color:"dark"===r$?"yellow.300":"yellow.700",children:["Last Team Note",(()=>{let e=eR(sU.sender_name,sU.sender_email);return e?" \xb7 ".concat(e):""})()]})]}),(0,s.jsx)(a.E,{fontSize:"2xs",color:rF,children:eA(sU.created_at)})]}),(0,s.jsx)(a.E,{fontSize:"sm",whiteSpace:"pre-wrap",fontStyle:"italic",color:"dark"===r$?"yellow.100":"yellow.900",children:sU.content})]})}),(0,s.jsxs)(u.z,{gap:2,mb:2,flexWrap:"wrap",children:["open"===sO.status&&null==sO.assigned_to&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"blue",variant:"solid",onClick:()=>void na(sO.session_id),disabled:J||sb,title:"Claim this conversation — assign it to you",children:[(0,s.jsx)(v.YrT,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Claim"})]}),"open"===sO.status&&null!=sT&&sO.assigned_to===sT&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"green",variant:"solid",cursor:"default",title:"You claimed this conversation",children:[(0,s.jsx)(v.YrT,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Claimed"})]}),"open"===sO.status&&null!=sO.assigned_to&&(null==sT||sO.assigned_to!==sT)&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"blue",variant:"subtle",cursor:"default",title:"Claimed by ".concat(sO.assigned_name||sO.assigned_email||"another operator"),children:[(0,s.jsx)(v.JXP,{size:12}),(0,s.jsxs)(a.E,{fontSize:"xs",ml:1,truncate:!0,maxW:"160px",children:["Claimed by ",sO.assigned_name||sO.assigned_email||"another operator"]})]}),"open"===sO.status&&null!=sT&&sO.assigned_to===sT&&(0,s.jsx)(x.$,{size:"xs",variant:"outline",onClick:()=>
1void nc(sO.session_id),disabled:J,title:"Unassign this conversation and keep it open here",children:"Release"}),(0,s.jsxs)(x.$,{size:"xs",variant:"outline",colorPalette:"blue",onClick:()=>tL(!0),title:"Assign session",children:[(0,s.jsx)(v.JXP,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Assign"})]}),(0,s.jsxs)(x.$,{size:"xs",variant:"outline",colorPalette:"purple",onClick:()=>tY(!0),title:"View conversation summary",children:[(0,s.jsx)(v.D1A,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Summary"})]}),(0,s.jsxs)(x.$,{size:"xs",variant:"outline",colorPalette:"yellow",onClick:()=>tZ(!0),title:"View and add notes",children:[(0,s.jsx)(v.jH2,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Notes"}),sJ.length>0&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"yellow",ml:1,children:sJ.length})]}),sq&&(0,s.jsx)(x.$,{size:"xs",variant:tE?"solid":"outline",colorPalette:"gray",onClick:()=>tW(!tE),children:(0,s.jsx)(a.E,{fontSize:"xs",children:"CC/BCC"})}),(0,s.jsxs)(x.$,{size:"xs",variant:"outline",colorPalette:"purple",onClick:()=>tB(!0),title:"Manage tags",children:[(0,s.jsx)(v.cnX,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Tag"})]}),"open"===sO.status&&"inbound"===sO.source&&["email","amazon","whatsapp","messenger","instagram"].includes((sO.channel||"").toLowerCase())&&(0,s.jsxs)(x.$,{size:"xs",colorPalette:"purple",variant:"outline",onClick:()=>void s6(),disabled:J||sd,title:"Hand this ticket to the AI — it replies on the same channel until it needs a human",children:[(0,s.jsx)(v.FrA,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Assign AI"})]}),"open"===sO.status?(0,s.jsxs)(x.$,{size:"xs",colorPalette:"red",variant:"outline",onClick:()=>s5(),disabled:J||si,title:"Close session",children:[(0,s.jsx)(v.yGN,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Close"})]}):(0,s.jsxs)(x.$,{size:"xs",colorPalette:"green",variant:"outline",onClick:s4,disabled:J||sa,title:"Reopen session",children:[(0,s.jsx)(v.VI6,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Reopen"})]})]}),sO&&(()=>{let e,t,r;if(sq)e=(0,s.jsx)(v.pHD,{size:12}),t="Email",r=sO.customer_email||(0,Y.K9)(sO);else{var n;let l=null==(n=sO.channel)?void 0:n.toLowerCase();r=("whatsapp"===l?sO.customer_phone||sO.whatsapp_username:"instagram"===l?sO.instagram_username?"@".concat(sO.instagram_username):null:"messenger"===l?sO.messenger_username:null)||(0,Y.K9)(sO),e="whatsapp"===l?(0,s.jsx)(v.QFc,{size:12}):(0,s.jsx)(v.mEP,{size:12}),t=e_(sO.channel)}return(0,s.jsxs)(u.z,{gap:3,mb:2,flexWrap:"wrap",alignItems:"center",children:[(0,s.jsxs)(u.z,{gap:1.5,flexShrink:0,children:[e,(0,s.jsxs)(a.E,{fontSize:"xs",color:rL,children:["Replying via ",(0,s.jsx)(a.E,{as:"span",fontWeight:"semibold",children:t})," to"," ",(0,s.jsx)(a.E,{as:"span",fontWeight:"semibold",children:r})]})]}),(0,s.jsxs)(u.z,{gap:1,flexShrink:0,title:"Conversation ID",children:[(0,s.jsx)(v.Qz2,{size:11,color:"dark"===r$?"#718096":"#A0AEC0"}),(0,s.jsx)(a.E,{fontSize:"2xs",color:rF,fontFamily:"mono",children:sO.session_id})]})]})})(),sq&&tE&&(0,s.jsxs)(p.T,{gap:1.5,mb:2,align:"stretch",children:[(0,s.jsxs)(u.z,{gap:2,alignItems:"center",children:[(0,s.jsx)(a.E,{fontSize:"xs",color:rF,w:"30px",flexShrink:0,children:"CC"}),(0,s.jsx)(g.p,{value:tC,onChange:e=>t_(e.target.value),placeholder:"[email protected], [email protected]",size:"xs"})]}),(0,s.jsxs)(u.z,{gap:2,alignItems:"center",children:[(0,s.jsx)(a.E,{fontSize:"xs",color:rF,w:"30px",flexShrink:0,children:"BCC"}),(0,s.jsx)(g.p,{value:tw,onChange:e=>tk(e.target.value),placeholder:"[email protected], [email protected]",size:"xs"})]})]}),tm.length>0&&(0,s.jsx)(u.z,{gap:2,mb:2,flexWrap:"wrap",children:tm.map((e,t)=>(0,s.jsxs)(u.z,{px:2,py:1,borderWidth:"1px",borderColor:rX,borderRadius:"md",bg:"dark"===r$?"gray.800":"gray.100",gap:1.5,children:["application/pdf"===e.content_type?(0,s.jsx)(v._mV,{size:12}):"text/csv"===e.content_type||"text/plain"===e.content_type?(0,s.jsx)(v.jH2,{size:12}):(0,s.jsx)(v.fZZ,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",maxW:"120px",truncate:!0,children:e.filename}),(0,s.jsx)(h.a,{cursor:"pointer",onClick:()=>n_(t,"reply"),_hover:{color:"red.400"},children:(0,s.jsx)(v.yGN,{size:12})})]},t))}),(0,s.jsxs)(h.a,{position:"relative",flex:1,children:[((null==sO?void 0:sO.channel)==="widget"||(null==sO?void 0:sO.channel)==="playground")&&ta&&"visitor"===rB.get(ta)&&(0,s.jsxs)(u.z,{position:"absolute",top:"-20px",left:0,gap:2,alignItems:"center",h:"16px",pointerEvents:"none",children:[(0,s.jsx)(h.a,{w:1.5,h:1.5,borderRadius:"full",bg:"green.500"}),(0,s.jsx)(a.E,{fontSize:"xs",color:rF,children:"Visitor is typing..."})]}),(0,s.jsx)(m.T,{ref:rW,value:td,onChange:e=>{if(!tj){let t=e.target.value;tu(t),ta&&t.length>0&&((null==sO?void 0:sO.channel)==="widget"||(null==sO?void 0:sO.channel)==="playground")&&(null==sO?void 0:sO.source)==="transfer_to_human"&&sk(ta,!0)}},onKeyDown:e=>{tj||nj(e,s2,sZ)},placeholder:tj?"Drafter is writing...":"async"===sZ?"Write your reply... (Ctrl+Enter to send)":"Type a reply to the customer...",size:"sm",minH:"44px",maxH:"180px",resize:"vertical",overflowY:"auto",disabled:J,borderColor:tj?"purple.400":rX,readOnly:tj,pb:"40px"}),(0,s.jsxs)(u.z,{position:"absolute",bottom:"10px",left:"10px",right:"14px",zIndex:1,gap:.5,mb:1,children:[sQ&&(0,s.jsx)(x.$,{variant:"ghost",colorPalette:"gray",color:"dark"===r$?"gray.400":"gray.500",onClick:()=>{var e;return null==(e=rk.current)?void 0:e.click()},disabled:J||sr||tj,size:"2xs",title:"Attach files (images, PDF, TXT, CSV)",px:2,py:1,borderRadius:"md",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v._mV,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",children:"Attach"})]})}),tj?(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,borderRadius:"md",colorPalette:"red",onClick:nz,title:"Stop generation",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(z.y,{size:"xs",color:"purple.400"}),(0,s.jsx)(a.E,{fontSize:"2xs",color:"purple.400",fontWeight:"medium",children:"Stop"})]})}):(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,borderRadius:"md",color:"purple.500",onClick:()=>ny(et,{skipCurrentDraft:!0}),disabled:J,title:"Generate a draft reply without extra instructions",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(S.pCw,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",children:"Qu
1ick Draft"})]})}),(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,borderRadius:"md",color:"yellow.500",onClick:()=>{rR.current="reply",tG(!0)},disabled:J||tj,title:"Use a macro",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v.FrA,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",children:"Macro"})]})}),(0,s.jsx)(h.a,{flex:1}),(0,s.jsx)(x.$,{colorPalette:"blue",onClick:s2,disabled:J||sr||tj||!td.trim(),size:"xs",px:2,py:1,borderRadius:"md",loading:sr,title:"async"===sZ?"Send reply (Ctrl+Enter)":"Send reply (Enter)",children:(0,s.jsx)(v.kGk,{size:13})})]}),tj&&(0,s.jsxs)(u.z,{position:"absolute",top:"-18px",right:"4px",gap:1,children:[(0,s.jsx)(z.y,{size:"xs",color:"purple.400"}),(0,s.jsx)(a.E,{fontSize:"2xs",color:"purple.400",fontWeight:"medium",children:"Drafter is writing..."})]}),(0,s.jsx)("input",{ref:rk,type:"file",accept:ey,multiple:!0,style:{display:"none"},onChange:e=>nC(e,"reply")})]})]})]}):(0,s.jsx)(j.s,{flex:1,alignItems:"center",justifyContent:"center",children:(0,s.jsxs)(p.T,{gap:2,children:[(0,s.jsx)(v._Y7,{size:36,color:"dark"===r$?"#4A5568":"#CBD5E0"}),(0,s.jsx)(a.E,{color:rF,fontSize:"sm",children:"Select a conversation from the list"})]})})}),sO&&!em&&(tJ?(0,s.jsxs)(h.a,{w:"44px",flexShrink:0,minH:0,borderLeftWidth:"1px",borderLeftColor:rX,bg:"dark"===r$?"gray.950":"white",display:"flex",flexDirection:"column",alignItems:"center",py:2,gap:2,children:[(0,s.jsx)(x.$,{size:"sm",colorPalette:"teal",onClick:()=>sL("profile"),title:"Open customer profile","aria-label":"Open customer profile",p:0,minW:"32px",h:"32px",borderRadius:"md",children:(0,s.jsx)(v.JXP,{size:16})}),(0,s.jsx)(x.$,{size:"sm",colorPalette:"purple",variant:tj?"solid":"outline",onClick:()=>sL("drafter"),title:"Open Drafter","aria-label":"Open Drafter",p:0,minW:"32px",h:"32px",borderRadius:"md",children:tj?(0,s.jsx)(z.y,{size:"xs"}):(0,s.jsx)(S.pCw,{size:16})})]}):(0,s.jsxs)(h.a,{w:"340px",flexShrink:0,minH:0,borderLeftWidth:"1px",borderLeftColor:rX,bg:"dark"===r$?"gray.950":"white",display:"flex",flexDirection:"column",overflow:"hidden",px:4,py:3,children:[(0,s.jsxs)(u.z,{justifyContent:"space-between",alignItems:"center",flexShrink:0,mb:3,children:[(0,s.jsxs)(u.z,{gap:0,p:"2px",borderRadius:"md",borderWidth:"1px",borderColor:rX,bg:"dark"===r$?"gray.900":"gray.50",flex:1,children:[(0,s.jsx)(x.$,{size:"xs",variant:"profile"===tv?"solid":"ghost",colorPalette:"profile"===tv?"teal":"gray",onClick:()=>s$("profile"),flex:1,borderRadius:"sm",h:"26px",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v.JXP,{size:12}),(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",children:"Profile"})]})}),(0,s.jsx)(x.$,{size:"xs",variant:"drafter"===tv?"solid":"ghost",colorPalette:"drafter"===tv?"purple":"gray",onClick:()=>{s$("drafter"),setTimeout(()=>{var e;return null==(e=rT.current)?void 0:e.focus()},50)},flex:1,borderRadius:"sm",h:"26px",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(S.pCw,{size:12}),(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",children:"Drafter"})]})})]}),(0,s.jsx)(x.$,{size:"xs",variant:"ghost",onClick:()=>{sX(!tJ)},title:"Close sidebar","aria-label":"Close sidebar",p:1,minW:"22px",h:"22px",ml:1,children:(0,s.jsx)(v.yGN,{size:14})})]}),"drafter"===tv?(0,s.jsx)(h.a,{flex:1,minH:0,overflowY:"auto",children:(0,s.jsx)(er,{instruction:ty,onInstructionChange:tz,onGenerate:ny,onStop:nz,isStreaming:tj,isDisabled:J,hasCurrentDraft:!!td.trim(),destination:"reply",instructionRef:rT,hideTitle:!0})}):(0,s.jsx)(h.a,{flex:1,minH:0,overflowY:"auto",children:(0,s.jsxs)(p.T,{align:"stretch",gap:3,children:[(null==sH?void 0:sH.fetched_at)&&(0,s.jsxs)(p.T,{align:"stretch",gap:1,children:[(0,s.jsxs)(a.E,{fontSize:"2xs",color:rF,children:["Fetched ",eA(sH.fetched_at)]}),(0,s.jsx)(h.a,{children:(0,s.jsx)(x.$,{size:"xs",variant:"outline",onClick:()=>{tV(e=>e+1)},disabled:sM,title:"Bypass the 24h cache and re-fetch every external source",children:(0,s.jsxs)(u.z,{gap:1,children:[sM?(0,s.jsx)(z.y,{size:"xs"}):(0,s.jsx)(v.jTZ,{size:11}),(0,s.jsx)(a.E,{fontSize:"2xs",children:sM?"Refreshing…":"Refresh"})]})})})]}),sN&&!sH?(0,s.jsxs)(p.T,{py:8,gap:2,children:[(0,s.jsx)(z.y,{size:"sm"}),(0,s.jsx)(a.E,{color:rF,fontSize:"xs",children:"Loading profile…"})]}
1):sH?(0,s.jsxs)(p.T,{align:"stretch",gap:4,children:[sB.map((e,t)=>(0,s.jsxs)(n.Fragment,{children:[(0,s.jsx)(eJ,{source:e,resolvedTheme:r$,mutedTextColor:rF,blockBorderColor:rX,formatDate:eA}),t<sB.length-1&&(0,s.jsx)(y.w,{})]},e.id)),X&&0===sB.length&&(0,s.jsx)(h.a,{p:3,borderWidth:"1px",borderRadius:"md",borderColor:rX,bg:"dark"===r$?"gray.900":"gray.50",children:(0,s.jsxs)(p.T,{align:"stretch",gap:2,children:[(0,s.jsx)(a.E,{fontSize:"xs",color:rF,lineHeight:"tall",children:"Enable Customer Profile lookup on your actions to see external customer data here."}),(0,s.jsx)(i(),{href:"/agents/".concat(X,"/actions"),style:{textDecoration:"none"},children:(0,s.jsx)(x.$,{size:"xs",variant:"outline",colorPalette:"blue",w:"full",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(a.E,{fontSize:"2xs",children:"Manage actions"}),(0,s.jsx)(v.dyV,{size:11})]})})})]})}),sK&&(0,s.jsxs)(s.Fragment,{children:[sB.length>0&&(0,s.jsx)(y.w,{}),(0,s.jsx)(eU,{source:sK,resolvedTheme:r$,mutedTextColor:rF,blockBorderColor:rX,formatDate:eA})]}),0===sB.length&&!sK&&(0,s.jsxs)(p.T,{py:6,gap:2,children:[(0,s.jsx)(v.JXP,{size:24,color:"dark"===r$?"#4A5568":"#CBD5E0"}),(0,s.jsx)(a.E,{color:rF,fontSize:"xs",textAlign:"center",children:"No customer profile found for this session."})]})]}):null]})})]}))]}),(0,s.jsx)(ea,{agentId:X||null,isOpen:tK,onClose:()=>tG(!1),onUseMacro:e=>{"compose"===rR.current?rr(e):tu(e)},resolvedTheme:r$}),(0,s.jsx)(U.A,{isOpen:tO,onClose:()=>tY(!1),title:"Conversation Summary",onSubmit:nb,isSubmitting:sD,submitButtonText:sA?"Regenerate":"Generate Summary",showActions:!0,headerRight:(null==sA?void 0:sA.last_generated_at)?(0,s.jsxs)(a.E,{fontSize:"xs",color:rF,children:["Last generated: ",eA(sA.last_generated_at)]}):void 0,children:(null==sA?void 0:sA.summary)?(0,s.jsx)(h.a,{fontSize:"sm",children:(0,s.jsx)(_.oz,{rehypePlugins:[E.A],remarkPlugins:[k.A,w.A],components:(0,O.A)({codeblock:{backgroundColor:G.kY.blockBgColor[r$]}},void 0,void 0,r$,"sm",!1),children:sA.summary})}):(0,s.jsxs)(p.T,{py:12,gap:3,children:[(0,s.jsx)(v.D1A,{size:32,color:"dark"===r$?"#4A5568":"#CBD5E0"}),(0,s.jsx)(a.E,{color:rF,fontSize:"sm",textAlign:"center",children:'No summary yet. Click "Generate Summary" to create an AI-powered summary of this conversation.'})]})}),tM&&(0,s.jsx)(h.a,{position:"fixed",top:0,left:0,right:0,bottom:0,bg:"blackAlpha.600",zIndex:2e3,display:"flex",alignItems:"center",justifyContent:"center",onClick:()=>{sx||t$(null)},children:(0,s.jsx)(h.a,{w:"90%",maxW:"400px",bg:"dark"===r$?"gray.900":"white",borderWidth:"1px",borderColor:rX,borderRadius:"lg",boxShadow:"xl",p:5,onClick:e=>e.stopPropagation(),children:(0,s.jsxs)(p.T,{align:"stretch",gap:4,children:[(0,s.jsx)(a.E,{fontSize:"md",fontWeight:"semibold",children:"closed"===tM?"Close conversations?":"Reopen conversations?"}),(0,s.jsx)(a.E,{fontSize:"sm",color:rF,children:"closed"===tM?"You're about to close ".concat(tD.size," selected ").concat(1===tD.size?"conversation":"conversations","."):"You're about to reopen ".concat(tD.size," selected ").concat(1===tD.size?"conversation":"conversations",".")}),(0,s.jsxs)(u.z,{justifyContent:"flex-end",gap:2,children:[(0,s.jsx)(x.$,{size:"sm",variant:"outline",onClick:()=>t$(null),disabled:sx,children:"Cancel"}),(0,s.jsx)(x.$,{size:"sm",colorPalette:"closed"===tM?"red":"green",onClick:()=>s8(tM),loading:sx,children:"closed"===tM?"Close":"Reopen"})]})]})})}),(0,s.jsx)(U.A,{isOpen:tX,onClose:()=>tL(!1),title:"Assign Session",onSubmit:()=>tL(!1),showActions:!1,children:sO&&(0,s.jsxs)(p.T,{align:"stretch",gap:4,children:[(0,s.jsx)(a.E,{fontSize:"sm",color:rF,children:"Select a team member to assign this session to, or unassign it."}),(0,s.jsx)(h.a,{px:4,py:3,borderWidth:"1px",borderColor:null==sO.assigned_to?"blue.400":rX,borderRadius:"md",bg:null==sO.assigned_to?"dark"===r$?"blue.900":"blue.50":"dark"===r$?"gray.800":"gray.50",cursor:"pointer",_hover:{bg:"dark"===r$?"gray.700":"gray.100"},onClick:()=>{ni(null),tL(!1)},children:(0,s.jsxs)(u.z,{gap:2,alignItems:"center",children:[(0,s.jsx)(v.JXP,{size:14}),(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"medium",children:"Unassigned"})]})}),sE&&sE.map(e=>(0,s.jsx)(h.a,{px:4,py:3,borderWidth:"1px",borderColor:sO.assigned_to===e.id?"blue.400":rX,borderRadius:"md",bg:sO.assigned_to===e.id?"dark"===r$?"blue.900":"blue.50":"dark"===r$?"gray.800":"gray.50",cursor:"pointer",_hover:{bg:"dark"===r$?"gray.700":"gray.100"},onClick:()=>{ni(e.id),tL(!1)},children:(0,s.jsxs)(u.z,{gap:2,alignItems:"center",children:[(0,s.jsx)(v.JXP,{size:14}
1),(0,s.jsxs)(p.T,{align:"flex-start",gap:0,children:[(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"medium",children:e.email}),(0,s.jsx)(a.E,{fontSize:"xs",color:rF,children:e.role_name})]}),sO.assigned_to===e.id&&(0,s.jsx)(f.Ex,{size:"sm",colorPalette:"blue",ml:"auto",children:"Current"})]})},e.id))]})}),(0,s.jsx)(U.A,{isOpen:tF,onClose:()=>{tB(!1),tg("")},title:"Manage Tags",onSubmit:()=>{tB(!1),tg("")},showActions:!1,children:sO&&(()=>{let e=sO.tags||[],t=new Set(e.map(e=>e.id)),r=(rU||[]).filter(e=>!t.has(e.id)),n=tp.trim()?r.filter(e=>e.name.toLowerCase().includes(tp.toLowerCase())):r,l=tp.trim(),i=l&&!(rU||[]).some(e=>e.name.toLowerCase()===l.toLowerCase());return(0,s.jsxs)(p.T,{align:"stretch",gap:5,children:[(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"medium",mb:2,children:"Current Tags"}),e.length>0?(0,s.jsx)(p.T,{align:"stretch",gap:2,children:e.map(e=>(0,s.jsxs)(u.z,{px:4,py:2,borderWidth:"1px",borderColor:"dark"===r$?"purple.700":"purple.200",borderRadius:"md",bg:"dark"===r$?"purple.900":"purple.50",justifyContent:"space-between",children:[(0,s.jsxs)(u.z,{gap:2,children:[(0,s.jsx)(v.cnX,{size:14,color:"dark"===r$?"#B794F4":"#805AD5"}),(0,s.jsx)(a.E,{fontSize:"sm",children:e.name})]}),(0,s.jsx)(x.$,{size:"2xs",variant:"ghost",colorPalette:"red",onClick:()=>nn(e.id),title:"Remove tag",children:(0,s.jsx)(v.yGN,{size:14})})]},e.id))}):(0,s.jsx)(a.E,{fontSize:"sm",color:rF,children:"No tags assigned to this session yet."})]}),(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"medium",mb:2,children:"Add Tag"}),(0,s.jsxs)(u.z,{gap:2,children:[(0,s.jsx)(g.p,{value:tp,onChange:e=>tg(e.target.value),onKeyDown:e=>{if("Enter"===e.key&&l){e.preventDefault();let t=r.find(e=>e.name.toLowerCase()===l.toLowerCase());t?nr(t.id):ns(l)}},placeholder:"Search existing or type new...",size:"sm",flex:1}),i&&(0,s.jsxs)(x.$,{size:"sm",colorPalette:"purple",onClick:()=>ns(l),children:[(0,s.jsx)(v.GGD,{size:14}),(0,s.jsx)(a.E,{fontSize:"xs",ml:1,children:"Create"})]})]}),n.length>0&&(0,s.jsx)(p.T,{align:"stretch",gap:1,mt:3,children:n.map(e=>(0,s.jsxs)(u.z,{px:4,py:2,borderWidth:"1px",borderColor:rX,borderRadius:"md",justifyContent:"space-between",children:[(0,s.jsxs)(u.z,{gap:2,flex:1,cursor:"pointer",_hover:{color:"purple.400"},onClick:()=>nr(e.id),children:[(0,s.jsx)(v.cnX,{size:14}),(0,s.jsx)(a.E,{fontSize:"sm",children:e.name})]}),(0,s.jsx)(x.$,{size:"2xs",variant:"ghost",colorPalette:"red",onClick:()=>nl(e.id),title:"Delete tag permanently",children:(0,s.jsx)(v.IXo,{size:12})})]},e.id))}),0===n.length&&!i&&tp.trim()&&(0,s.jsx)(a.E,{fontSize:"sm",color:rF,mt:2,children:"No matching tags found."})]})]})})()}),(0,s.jsx)(U.A,{isOpen:tQ,onClose:()=>tZ(!1),title:"Notes",onSubmit:()=>tZ(!1),showActions:!1,children:(0,s.jsxs)(p.T,{align:"stretch",gap:5,h:"100%",children:[(null==sO?void 0:sO.escalation_note)&&(0,s.jsxs)(h.a,{p:4,bg:"dark"===r$?"orange.900":"orange.50",borderWidth:"1px",borderColor:"dark"===r$?"orange.700":"orange.200",borderLeftWidth:"4px",borderLeftColor:"orange.400",borderRadius:"md",children:[(0,s.jsxs)(u.z,{gap:2,mb:2,children:[(0,s.jsx)(v.eHT,{size:14,color:"dark"===r$?"#ED8936":"#C05621"}),(0,s.jsx)(a.E,{fontSize:"xs",fontWeight:"semibold",color:"dark"===r$?"orange.300":"orange.700",children:"AI Escalation Note"})]}),(0,s.jsx)(a.E,{fontSize:"sm",whiteSpace:"pre-wrap",color:"dark"===r$?"orange.200":"orange.800",children:sO.escalation_note})]}),(0,s.jsxs)(h.a,{flex:1,children:[(0,s.jsxs)(a.E,{fontSize:"sm",fontWeight:"medium",mb:2,children:["Internal Notes ",sJ.length>0&&"(".concat(sJ.length,")")]}),sJ.length>0?(0,s.jsx)(p.T,{align:"stretch",gap:2,children:sJ.map(e=>(0,s.jsxs)(h.a,{p:3,borderWidth:"1px",borderColor:"dark"===r$?"yellow.700":"yellow.200",borderRadius:"md",bg:"dark"===r$?"yellow.900":"yellow.50",children:[(0,s.jsxs)(u.z,{gap:2,mb:1,justifyContent:"space-between",children:[(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",color:"dark"===r$?"yellow.300":"yellow.700",children:eR(e.sender_name,e.sender_email)||"Agent"}),(0,s.jsx)(a.E,{fontSize:"2xs",color:rF,children:eA(e.created_at)})]}),(0,s.jsx)(a.E,{fontSize:"sm",whiteSpace:"pre-wrap",fontStyle:"italic",children:e.content})]},e.id))}):(0,s.jsx)(a.E,{fontSize:"sm",color:rF,children:"No internal notes yet."})]}),(0,s.jsxs)(h.a,{pt:3,borderTopWidth:"1px",borderColor:rX,children:[(0,s.jsx)(a.E,{fontSize:"sm",fontWeight:"medium",mb:2,children:"Add Note"}),(0,s.jsxs)(u.z,{gap:2,alignItems:"flex-end",children:[(0,s.jsx)(m.T,{value:tx,onChange:e=>th(e.target.value),onKeyDown:e=>nj(e,s3),placeholder:"Add an internal note (not visible to customer)...",size:"sm",minH:"60px",maxH:"150px",resize:"none",overflowY:"auto",disabled:J||sn,borderColor:rX}),(0,s.jsx)(x.$,{colorPalette:"yellow",onClick:s3,disabled:J||sn||!tx.trim(),size:"sm",minH:"60px",loading:sn,children:(0,s.jsx)(v.jH2,{size:16})})]})]})]})}),(0,s.jsx)(U.A,{isOpen:t0,onClose:()=>t1(!1),title:"Compose Email",onSubmit:nw,isSubmitting:sS,submitButtonText:"Send Email",showActions:!0,children:(0,s.jsxs)(p.T,{align:"stretch",gap:4,children:[(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"xs",mb:1,color:rF,fontWeight:"medium",children:"To"}),(0,s.jsx)(g.p,{value:t9,onChange:e=>t8(e.target.value),placeholder:"[email protected], [email protected]",size:"sm"})]}),(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"xs",mb:1,color:rF,fontWeight:"medium",children:"Subject"}),(0,s.jsx)(g.p,{value:t7,onChange:e=>re(e.target.value),placeholder:"Email subject...",size:"sm"})]}),(0,s.jsxs)(u.z,{gap:4,children:[(0,s.jsxs)(h.a,{flex:1,children:[(0,s.jsx)(a.E,{fontSize:"xs",mb:1,color:rF,fontWeight:"medium",children:"CC"}),(0,s.jsx)(g.p,{value:rs,onChange:e=>rn(e.target.value),placeholder:"Optional CC recipients...",size:"sm"})]}),(0,s.jsxs)(h.a,{flex:1,children:[(0,s.jsx)(a.E,{fontSize:"xs",mb:1,color:rF,fontWeight:"medium",children:"BCC"}),(0,s.jsx)(g.p,{value:rl,onChange:e=>ri(e.target.value),placeholder:"Optional BCC recipients...",size:"sm"})]})]}),(0,s.jsx)(h.a,{p:3,borderWidth:"1px",borderColor:rX,borderRadius:"md",bg:"dark"===r$?"gray.900":"gray.50",children:(0,s.jsx)(er,{instruction:rc,onInstructionChange:rd,onGenerate:nv,onStop:nS,isStreaming:ru,isDisabled:!ta,hasCurrentDraft:!!rt.trim(),destination:"compose",instructionRef:rA})}),(0,s.jsxs)(h.a,{children:[(0,s.jsx)(a.E,{fontSize:"xs",mb:1,color:rF,fontWeight:"medium",children:"Message"}),ro.length>0&&(0,s.jsx)(u.z,{gap:2,mb:2,flexWrap:"wrap",children:ro.map((e,t)=>(0,s.jsxs)(u.z,{px:2,py:1,borderWidth:"1px",borderColor:rX,borderRadius:"md",bg:"dark"===r$?"gray.800":"gray.100",gap:1.5,children:["application/pdf"===e.content_type?(0,s.jsx)(v._mV,{size:12}):"text/csv"===e.content_type||"text/plain"===e.content_type?(0,s.jsx)(v.jH2,{size:12}):(0,s.jsx)(v.fZZ,{size:12}),(0,s.jsx)(a.E,{fontSize:"xs",maxW:"120px",truncate:!0,children:e.filename}),(0,s.jsx)(h.a,{cursor:"pointer",onClick:()=>n_(t,"compose"),_hover:{color:"red.400"},children:(0,s.jsx)(v.yGN,{size:12})})]},t))}),(0,s.jsxs)(h.a,{position:"relative",children:[(0,s.jsx)(m.T,{value:rt,onChange:e=>{ru||rr(e.target.value)},placeholder:ru?"Drafter is writing...":"Write your email message...",size:"sm",minH:"200px",resize:"vertical",borderColor:ru?"purple.400":rX,readOnly:ru,pb:"40px"}),(0,s.jsxs)(u.z,{position:"absolute",bottom:"6px",left:"6px",right:"6px",zIndex:1,gap:.5,mb:1,children:[(0,s.jsx)(x.$,{variant:"ghost",colorPalette:"gray",color:"dark"===r$?"gray.400":"gray.500",onClick:()=>{var e;return null==(e=rE.current)?void 0:e.click()},disabled:ru,size:"2xs",title:"Attach files (images, PDF, TXT, CSV)",px:2,py:1,borderRadius:"md",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v._mV,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",children:"Attach"})]})}),ru?(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,borderRadius:"md",colorPalette:"red",onClick:nS,title:"Stop generation",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(z.y,{size:"xs",color:"purple.400"}),(0,s.jsx)(a.E,{fontSize:"2xs",color:"purple.400",fontWeight:"medium",children:"Stop"})]})}):(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,borderRadius:"md",color:"purple.500",onClick:()=>nv(et,{skipCurrentDraft:!0}),title:"Generate a draft reply without extra instructions",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(S.pCw,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",children:"Qu
1ick Draft"})]})}),(0,s.jsx)(x.$,{variant:"ghost",size:"2xs",px:2,py:1,borderRadius:"md",color:"yellow.500",onClick:()=>rp(!rh),disabled:ru,title:"Use a macro",children:(0,s.jsxs)(u.z,{gap:1,children:[(0,s.jsx)(v.FrA,{size:13}),(0,s.jsx)(a.E,{fontSize:"2xs",fontWeight:"medium",children:"Macro"})]})})]}),ru&&(0,s.jsxs)(u.z,{position:"absolute",top:"-18px",right:"4px",gap:1,children:[(0,s.jsx)(z.y,{size:"xs",color:"purple.400"}),(0,s.jsx)(a.E,{fontSize:"2xs",color:"purple.400",fontWeight:"medium",children:"Drafter is writing..."})]})]}),(0,s.jsx)("input",{ref:rE,type:"file",accept:ey,multiple:!0,style:{display:"none"},onChange:e=>nC(e,"compose")})]}),(0,s.jsx)(eO,{agentId:X||null,isOpen:rh,onClose:()=>rp(!1),onUseMacro:e=>{rr(e),rp(!1)},resolvedTheme:r$})]})})]})}},68831:(e,t,r)=>{r.d(t,{Mn:()=>h,Q7:()=>d,Q9:()=>u,S0:()=>p,bT:()=>c,c4:()=>o,nB:()=>x,zr:()=>a});var s=r(75656),n=r(34333),l=r(8863),i=r(72943);let o=e=>{let{user:t}=(0,i.J)();return(0,s.Ay)(t&&e?["/fetch_procedures?agent_id=".concat(e),t.accessToken]:null,e=>(0,l.we)(e).then(e=>e.data))},a=e=>{let{user:t}=(0,i.J)();return(0,n.A)(t&&e?["/create_procedure?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{var r;let{arg:s}=t;return(0,l.eh)(e,{arg:{name:s.name,description:s.description,instructions:s.instructions,actions:s.actions,is_escalation:null!=(r=s.is_escalation)&&r}})})},c=e=>{let{user:t}=(0,i.J)();return(0,n.A)(t&&e?["/edit_procedure?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t,s={procedure_id:r.procedure_id};return void 0!==r.name&&null!==r.name&&(s.name=r.name),void 0!==r.description&&null!==r.description&&(s.description=r.description),void 0!==r.instructions&&null!==r.instructions&&(s.instructions=r.instructions),void 0!==r.actions&&null!==r.actions&&(s.actions=r.actions),void 0!==r.is_escalation&&null!==r.is_escalation&&(s.is_escalation=r.is_escalation),(0,l.wf)(e,{arg:s})})},d=e=>{let{user:t}=(0,i.J)();return(0,n.A)(t&&e?["/delete_procedure?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t;return(0,l.Nw)(e,{arg:r})})},u=e=>{let{user:t}=(0,i.J)();return(0,n.A)(t&&e?["/set_procedure_enabled?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t;return(0,l.wf)(e,{arg:r})})},x=e=>{let{user:t}=(0,i.J)();return(0,n.A)(t&&e?["/set_procedure_disabled?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t;return(0,l.wf)(e,{arg:r})})},h=e=>{let{user:t}=(0,i.J)();return(0,n.A)(t&&e?["/update_procedure_excluded_channels?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t;return(0,l.wf)(e,{arg:{procedure_id:r.procedure_id,excluded_channels:r.excluded_channels}})})},p=e=>{let{user:t}=(0,i.J)();return(0,n.A)(t&&e?["/set_procedure_escalation?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:r}=t;return(0,l.wf)(e,{arg:{procedure_id:r.procedure_id,is_escalation:r.is_escalation}})})}},75306:(e,t,r)=>{r.d(t,{A:()=>l});var s=r(59971);function n(){return{type:"break"}}function l(){return function(e){(0,s.T)(e,[/\r?\n|\r/g,n])}}}}]);

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.