1import{j as t,i as pe,an as ue,r as i,T as c,B as T,e as G,a3 as me,a0 as Tt,a7 as kt,a8 as Et,f as Lt,br as It,bs as Rt}from"./MarketingSiteLoadingFallback-DfYAzeIM.js";import{a as N,h as o,T as oe,B as Oe,ai as dt,eb as Mt,ec as Dt,u as ze,dV as Bt,dT as Ot,dU as zt,D as Ze,aO as Nt,aP as Wt,aQ as Ft,cu as Pt,aR as Ut,bl as Ht,c8 as $t,cD as qt,cE as Vt,a3 as Gt,J as Yt,a4 as J,a8 as te,a6 as re,a5 as se,F as Xe}from"./renderJungleWebApp-DZgne_TB.js";import{I as ct}from"./IconMagnifyingGlass-XxLJObL8.js";import{F as C,I as pt,L as ut}from"./landingHandoffUploadClaim-B2LBwAI7.js";import{C as Kt,a as Jt,g as Qt}from"./customerSupportFeedbackTypeDisplay-h2ktDj7X.js";import{f as Ne}from"./formatTimeSince-D2c9cw_Y.js";import{B as mt}from"./badge-DS7nl7GY.js";import{j as Zt,t as Xt,m as er,k as ht,p as tr,n as rr,o as sr,q as ce,v as nr,w as or,x as ar,y as ir,z as lr,A as dr}from"./SupportConversationsApiClient-BUjRC98s.js";import{trackError as ne}from"./track-error-DEre5AXz.js";import{W as cr,g as pr,r as ur,A as mr,u as hr,h as _r,c as fr}from"./SupportUserServiceLinks-BOj8jtkX.js";import{i as gr}from"./react-textarea-autosize.browser.esm-C1iVgKxJ.js";import{T as xr}from"./textarea-BxfDy4nw.js";import{S as br}from"./select-CHURZt1F.js";import{B as yr}from"./button-group-qmBHU0rs.js";import{u as We}from"./use-toast-BZJ66mJi.js";import{I as je}from"./icon-button-BKnGN1H6.js";import{b as Ce,I as Sr}from"./stripe-price-details-DClgIPIw.js";import{I as Cr}from"./IconCopy-B8-hvn3S.js";import{S as jr}from"./switch-ByP4t2G9.js";import{P as wr,b as Ar,c as vr}from"./popover-trigger-D2NNnbd-.js";import{P as Tr,a as kr}from"./popover-body-CFRQTXkd.js";import{M as Er}from"./modal-close-button-DNTbARan.js";import{T as Lr,a as Ir,b as et,c as Rr,d as tt}from"./tab-panels-Dt9EpWR6.js";import{u as Mr}from"./useSupportConversationListener-BlbVQYyn.js";import{I as Dr}from"./IconArrowBack-BzhylVwC.js";import"./frontend-release-BHg_hj9G.js";import"./hub-D89kKFfg.js";import"./index-rQLcFmgX.js";import"./legacy-referrer-id-43tytWzp.js";import"./main-YoYAMf6n.js";import"./document-upload-sentry-Dl2_Y04U.js";import"./sentry-init-BRm8Bcin.js";import"./client-environment-BMTHOZAb.js";import"./supportApiHttpClient-C7CH2x07.js";import"./SupportConversationMessageAttachmentsRenderer-DGOutHmF.js";import"./chevron-right-7iYPKuZ3.js";import"./close-CKCy2mmL.js";import"./MarkdownWithMath-CLxXCppZ.js";import"./remark-gfm-for-older-webkit-QGdm8VJ7.js";import"./IconCheckmarkWithCircle-dKhL5erd.js";import"./IconEmail-D4lZLDPd.js";import"./IconSearch-C_iAv_XQ.js";import"./IconFileSearch-CYzn_wPV.js";import"./popover-header-BaCVg-co.js";import"./avatar-cxQL5qbl.js";import"./split-CzYrjwZo.js";import"./use-checkbox-BdaQFSRs.js";import"./index-BbAC0Ngi.js";import"./visually-hidden.style-BUiBK_kv.js";function Br({value:e,onChange:r}){const{t:s}=N(),n=s("admin.support.threads.types.all","All"),a=[{value:null,title:n,label:n},...Kt.map(({feedbackTypeTag:d})=>{const p=Jt(d);return{value:d,title:p.emoji,label:s(p.lowercaseLabel.translationKey,p.lowercaseLabel.defaultTranslation)}})];return t.jsx(C,{role:"group","aria-label":s("admin.support.threads.types.label","Message type"),gap:1,mt:3,p:1,borderRadius:"16px",bg:o.surface.background,children:a.map(d=>t.jsx(oe,{label:d.label,openDelay:300,hasArrow:!0,isDisabled:pe||ue,children:t.jsx("span",{style:{display:"flex",flex:1,minWidth:0},children:t.jsx(Oe,{title:d.title,"aria-label":d.label,"aria-pressed":e===d.value,buttonPrimaryOrSecondaryType:"primary",buttonStyleType:"ghost",pressed:e===d.value,pressedBackgroundColor:o.primaryAction.selectedLight,pressedHoverBackgroundColor:o.primaryAction.selectedLightHover,border:"1px solid",borderColor:e===d.value?o.primaryAction.selectedLightBorder:"transparent",onClick:()=>r(e===d.value?null:d.value),w:"100%",minW:0,h:{base:"44px",md:"40px"},justifyContent:"center",p:0,borderRadius:"12px",buttonTitleTextProps:{fontSize:d.value?"19px":"12px",fontWeight:700},_focusVisible:{outline:"2px solid",outlineColor:o.primaryAction.default}})})},d.value??"all"))})}const rt="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20id='mdi-star'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M12,17.27L18.18,21L16.54,13.97L22,9.24L14.81,8.62L12,2L9.19,8.62L2,9.24L7.45,13.97L5.82,21L12,17.27Z'%20/%3e%3c/svg%3e",Fe=i.memo(({status:e})=>{const r={open:"yellow",waiting_for_customer:"blue",pending_to_check:"orange",done:"green",ignored:"green"},s={open:"Open",waiting_for_customer:"Waiting for customer",pending_to_check:"Needs review",done:"Done",ignored:"Done"};return t.jsx(mt,{colorScheme:r[e]??"gray",variant:"subtle",fontSize:"10px",textTransform:"uppercase",borderRadius:"full",px:2,children:s[e]??e})});Fe.displayName="AdminSupportThreadStatusBadge";function Or(e){const r=e.trim().toUpperCase();return/^[A-Z]{2}$/.test(r)?String.fromCodePoint(...Array.from(r).map(s=>127462+s.charCodeAt(0)-65)):null}function zr(e){try{return new Intl.DisplayNames(["en"],{type:"region"}).of(e)??e}catch{return e}}function st(e){const r=new Date(e);return Number.isFinite(r.getTime())?new Intl.DateTimeFormat("en",{day:"numeric",month:"short",year:"numeric",timeZone:"UTC"}).format(r):null}function Nr(e){var n;const r=(n=e.subscriptionPlan)==null?void 0:n.trim().toLowerCase().replace(/[ _-]+/g,"");return e.subscriptionStatus==="active"||e.subscriptionStatus==="cancellation_pending"?r==="elite"?"ð¤¯":r==="superlearner"||r==="megamind"?"â¡":null:null}function Wr(e,r){var n,a;const s=(n=e.subscriptionPlan)==null?void 0:n.trim().toLowerCase().replace(/[ _-]+/g,"");return s==="elite"?r.elite:s==="superlearner"?r.pro:s==="megamind"?r.megaMind:((a=e.subscriptionPlan)==null?void 0:a.trim())||r.paidPlan}function nt({label:e,children:r}){return pe||ue?r:t.jsx(oe,{label:e,placement:"top",openDelay:200,hasArrow:!0,children:r})}const _t=i.memo(({customerProfile:e,showLeadingSeparator:r=!1})=>{const{t:s}=N();if(!e)return null;const n=e.countryCode?Or(e.countryCode):null,a=e.countryCode?zr(e.countryCode):null,d=Nr(e);
1if(!n&&!d)return null;const p=e.firstSubscriptionActivatedAt?st(e.firstSubscriptionActivatedAt):null,u=e.willCancelAtPeriodEnd&&e.scheduledCancellationAt?st(e.scheduledCancellationAt):null,l=Wr(e,{elite:s("admin.support.threads.customer.plan.elite","Elite"),megaMind:s("admin.support.threads.customer.plan.mega_mind","Mega Mind"),paidPlan:s("admin.support.threads.customer.paid_plan","Paid plan"),pro:s("admin.support.threads.customer.plan.pro","Pro")}),x=e.subscriptionPeriod==="annual"?s("admin.support.threads.customer.period.annual","annual"):e.subscriptionPeriod==="monthly"?s("admin.support.threads.customer.period.monthly","monthly"):null,f=x?s("admin.support.threads.customer.subscription_accessible_label_with_period","{plan}, {period} plan",{plan:l,period:x}):s("admin.support.threads.customer.subscription_accessible_label","{plan} subscriber",{plan:l}),y=t.jsxs(dt,{spacing:.5,align:"start",py:.5,children:[t.jsx(c,{fontSize:"12px",fontWeight:"700",children:f}),p?t.jsx(c,{fontSize:"12px",children:s("admin.support.threads.customer.first_subscribed","First subscribed {date}",{date:p})}):null,u?t.jsx(c,{fontSize:"12px",children:s("admin.support.threads.customer.cancels_on","Cancels on {date}",{date:u})}):null,e.resubscriptionCount&&e.resubscriptionCount>0?t.jsx(c,{fontSize:"12px",children:e.resubscriptionCount===1?s("admin.support.threads.customer.resubscribed_once","Resubscribed 1 time"):s("admin.support.threads.customer.resubscribed_multiple","Resubscribed {count} times",{count:e.resubscriptionCount})}):null]});return t.jsxs(C,{align:"center",gap:1.5,flexShrink:0,children:[r?t.jsx(c,{as:"span","aria-hidden":!0,color:o.text.placeholder,fontSize:"10px",children:"â¢"}):null,n&&a?t.jsx(nt,{label:a,children:t.jsx(c,{as:"span","aria-label":a,fontSize:"15px",lineHeight:"1",cursor:pe||ue?"default":"help",children:n})}):null,d?t.jsx(nt,{label:y,children:t.jsx(c,{as:"span","aria-label":f,fontSize:"15px",lineHeight:"1",cursor:pe||ue?"default":"help",color:o.text.body,children:d})}):null]})});_t.displayName="AdminSupportCustomerMetadata";function Fr(e,r){const s=n=>typeof n=="string"?n.trim():"";return s(e.investigation_title)||s(e.title)||s(e.first_message_preview_english)||s(e.first_message_preview)||s(e.gmail_subject)||s(e.last_message_preview_english)||s(e.last_message_preview)||r}const Pe=i.memo(({conversation:e,fontSize:r="13px",fontWeight:s="700",noOfLines:n=1})=>{const{t:a}=N(),d=Fr(e,a("customer_support.feedback_type.fallback.label","conversation"));return t.jsxs(C,{align:"center",gap:1.5,minW:0,children:[t.jsx(c,{as:"span","aria-hidden":"true",flexShrink:0,fontSize:r,lineHeight:"1",children:Qt(e.feedback_type_tag)}),t.jsx(c,{as:"span",fontSize:r,fontWeight:s,color:o.text.header,noOfLines:n,minW:0,children:d})]})});Pe.displayName="AdminSupportThreadTitle";function Pr(e){var d,p;const r=((d=e==null?void 0:e.userType)==null?void 0:d.trim())??"",s=((p=e==null?void 0:e.studentType)==null?void 0:p.trim())??"",n=s.toLowerCase().replace(/[ _-]+/g,""),a=["","notspecified","undefined","null"].includes(n)?"":s;return r.toLowerCase()==="student"&&a?a:r||null}const ft=i.memo(({conversation:e,customerProfile:r,isSelected:s,onSelectConversation:n})=>{const{t:a}=N(),d=(typeof e.user_name=="string"?e.user_name.trim():"")||a("admin.support.threads.anonymous_user","Anonymous user"),p=(e.unread_for_admin_count??0)>0,u=Pr(r);return t.jsx(T,{position:"relative",borderBottomWidth:"1px",borderColor:o.surface.border,bg:s?o.primaryAction.light:p?o.surface.background:"transparent",_hover:{bg:s?o.primaryAction.light:o.surface.hover},transition:"background 120ms ease",children:t.jsxs(T,{role:"button",tabIndex:0,cursor:"pointer",px:4,py:4,"aria-pressed":s,borderLeftWidth:"3px",borderLeftColor:s?o.primaryAction.default:"transparent",onClick:()=>n(e.id),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),n(e.id))},_focusVisible:{outline:`2px solid ${o.primaryAction.default}`,outlineOffset:"-2px"},children:[t.jsxs(C,{align:"center",justify:"space-between",gap:2,mb:1,children:[t.jsx(Fe,{status:e.status}),t.jsxs(C,{align:"center",gap:1.5,children:[p?t.jsx(mt,{bg:o.accentColors.errorStrong,color:"white",borderRadius:"full",px:2,children:e.unread_for_admin_count}):null,t.jsx(c,{fontSize:"11px",color:o.text.placeholder,children:Ne(e.last_message_at)})]})]}),t.jsx(Pe,{conversation:e,fontWeight:p?"700":"600"}),t.jsx(c,{fontSize:"12px",color:o.text.label,noOfLines:1,mt:.5,children:e.last_message_preview_english||e.last_message_preview||a("admin.support.threads.no_messages_parenthetical","(no messages)")}),t.jsxs(C,{align:"center",gap:1.5,mt:1,minW:0,pr:e.is_starred?6:0,children:[t.jsx(c,{fontSize:"11px",color:o.text.body,fontWeight:"600",noOfLines:1,minW:0,children:d}),u?t.jsxs(t.Fragment,{children:[t.jsx(c,{as:"span","aria-hidden":!0,
1color:o.text.placeholder,fontSize:"10px",children:"â¢"}),t.jsx(c,{fontSize:"11px",color:o.text.label,noOfLines:1,minW:0,children:u})]}):null,t.jsx(_t,{customerProfile:r,showLeadingSeparator:!0})]}),e.is_starred?t.jsx(T,{position:"absolute",bottom:4,right:4,color:o.tertiaryAction.hover,boxSize:"18px",bg:"currentColor",sx:{mask:`url("${rt}") center / contain no-repeat`,WebkitMask:`url("${rt}") center / contain no-repeat`},role:"img","aria-label":a("admin.support.filter.starred","Starred")}):null]})})});ft.displayName="AdminSupportThreadListItem";function Y(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function ot(e){if(e instanceof Date)return Number.isFinite(e.getTime())?e.toISOString():null;if(typeof e=="string"){const a=Date.parse(e);return Number.isFinite(a)?new Date(a).toISOString():null}const r=e&&typeof e=="object"&&!Array.isArray(e)?e:{};if(typeof r.toDate=="function")try{const a=r.toDate();return a instanceof Date&&Number.isFinite(a.getTime())?a.toISOString():null}catch{return null}const s=Number(r.seconds??r._seconds),n=Number(r.nanoseconds??r._nanoseconds??0);return!Number.isFinite(s)||!Number.isFinite(n)?null:new Date(s*1e3+n/1e6).toISOString()}function Ur(e){var r,s;return{userType:Y(e.user_type),studentType:Y(e.student_type),countryCode:((r=Y(e.country_code))==null?void 0:r.toUpperCase())??null,subscriptionPlan:Y(e.subscription_plan),subscriptionStatus:((s=Y(e.subscription_status))==null?void 0:s.toLowerCase())??null,subscriptionPeriod:e.subscription_period==="annual"||e.subscription_period==="monthly"?e.subscription_period:null,firstSubscriptionActivatedAt:ot(e.first_subscription_activated_at),scheduledCancellationAt:ot(e.scheduled_cancellation_at),willCancelAtPeriodEnd:e.will_cancel_at_period_end===!0,resubscriptionCount:Number.isInteger(e.resubscription_count)&&Number(e.resubscription_count)>=0?Number(e.resubscription_count):null}}function Hr(e){var p;const r=e.customer_profile_snapshot;if(!r)return null;const s=Y(r.user_type),n=Y(r.student_type),a=Y(r.subscription_plan),d=((p=Y(r.subscription_status))==null?void 0:p.toLowerCase())??null;return!s&&!n&&!a&&!d?null:{userType:s,studentType:n,countryCode:null,subscriptionPlan:a,subscriptionStatus:d,subscriptionPeriod:null,firstSubscriptionActivatedAt:null,scheduledCancellationAt:null,willCancelAtPeriodEnd:!1,resubscriptionCount:null}}function $r(e){const s=i.useMemo(()=>Array.from(new Set(e.map(d=>Y(d.user_id)).filter(d=>!!d))).sort(),[e]).join("\0"),[n,a]=i.useState({});return i.useEffect(()=>{if(!s){a({});return}let d=!1;const p=s.split("\0");return Zt({userIds:p}).then(u=>{if(d)return;const l={};for(const x of u){const f=Y(x==null?void 0:x.user_id);f&&(l[f]=Ur(x))}a(l)}).catch(u=>{ne(u,{scope:"admin-support-customer-profiles",level:"warning",extra:{requestedProfileCount:p.length}})}),()=>{d=!0}},[s]),i.useMemo(()=>{const d={};for(const p of e){const u=Y(p.user_id);if(!u||d[u])continue;const l=Hr(p);l&&(d[u]=l)}for(const[p,u]of Object.entries(n)){const l=d[p];d[p]={...u,userType:u.userType??(l==null?void 0:l.userType)??null,studentType:u.studentType??(l==null?void 0:l.studentType)??null}}return d},[e,n])}const Ee=i.memo(({activeFilter:e,searchQuery:r="",activeType:s=null,onChangeType:n,onSearchQueryChange:a,onRetrySearch:d,conversations:p,isLoadingInitialSnapshot:u,errorMessage:l,canLoadMoreConversations:x,selectedConversationId:f,onChangeFilter:y,onLoadMoreConversations:g,onSelectConversation:m,shouldFillAvailableWidth:v=!1})=>{const{t:S}=N(),A=$r(p),E=p.filter(h=>h.status==="pending_to_check").length,L=x?t.jsx(G,{m:3,minH:"44px",variant:"outline",onClick:g,isLoading:u,children:S("admin.support.threads.load_more","Load more threads")}):null,R=[{id:"open",label:S("admin.support.threads.filter.open","Open threads"),activeColorScheme:"teal"},{id:"pending_to_check",label:S("admin.support.threads.filter.needs_review","Needs review"),activeColorScheme:"orange"},{id:"starred",label:S("admin.support.filter.starred","Starred"),activeColorScheme:"yellow"},{id:"all",label:S("admin.support.threads.filter.all","All threads"),activeColorScheme:"green"},{id:"closed",label:S("admin.support.threads.filter.closed","Closed"),activeColorScheme:"gray"},{id:"my",label:S("admin.support.threads.filter.my","My threads"),activeColorScheme:"green"}];return t.jsxs(T,{w:v?"100%":"300px",minW:0,flexShrink:0,h:"100%",borderRightWidth:v?0:"1px",borderColor:o.surface.border,display:"flex",flexDirection:"column",bg:o.surface.white,children:[t.jsxs(T,{px:4,py:5,borderBottomWidth:"1px",borderColor:o.surface.border,children:[t.jsx(c,{fontSize:"20px",fontWeight:"800",color:o.text.header,mb:4,children:S("admin_support.threads_support_admin_threads_adminsupportthreadssidebar.support_threads_f3096f80","Support threads")}),t.jsx(cr,{spacing:2,children:R.map(h=>{const b=e===h.id,j=h.id==="pending_to_check"&&E>0&&b;return t.jsx(pr,{children:t.jsxs(G,{size:"xs",borderRadius:"full",minH:v?"44px":void 0,variant:b?"solid":"ghost",colorScheme:b?h.activeColorScheme:void 0,onClick:()=>y(h.id),children:[h.label,j?` (${E})`:""]})},h.id)})}),n?t.jsx(Br,{value:s,onChange:n}):null,t.jsxs(Mt,{mt:3,size:"sm",children:[t.jsx(Dt,{h:"40px",pointerEvents:"none",children:t.jsx(ct,{width:16,height:16,color:o.text.label})}),t.jsx(pt,{type:"search",maxLength:256,"aria-label":S("admin.support.threads.search_placeholder","Search all threadsâ¦"),placeholder:S("admin.support.threads.search_placeholder","Search all threadsâ¦"),value:r,onChange:h=>a==null?void 0:a(h.target.value),h:"40px",borderRadius:"12px",bg:o.surface.background,borderColor:o.surface.border,_focusVisible:{borderColor:o.primaryAction.default,boxShadow:`0 0 0 1px ${o.primaryAction.default}`}})]})]}),t.jsxs(T,{flex:"1",overflowY:"auto",children:[l?t.jsxs(T,{px:3,py:3,children:[t.jsxs(c,{fontSize:"13px",color:o.accentColors.errorStrong,children:[S("admin_support.threads_support_admin_threads_adminsupportthreadssidebar.failed_to_load_threads_73e974ec","Failed to load threads:")," ",l]}),r.trim()&&d?t.jsx(G,{mt:2,size:"sm",variant:"outline",onClick:d,children:S("try_again","try again")}):null]}):null,u&&p.length===0?t.jsx(T,{textAlign:"center",py:6,children:t.jsx(me,{size:"sm",color:o.primaryAction.default})}):l&&p.length===0?null:p.length===0?t.jsxs(C,{direction:"column",px:3,py:4,children:[t.jsx(c,{fontSize:"13px",color:o.text.placeholder,textAlign:"center",children:r.trim()||s?S("admin.support.threads.search_empty","No matching threads."):S("admin_support.threads_support_admin_threads_adminsupportthreadssidebar.no_threads_in_this_view_yet_790744e4","No threads in this view yet.")}),L]}):t.jsxs(dt,{spacing:0,align:"stretch",children:[p.map(h=>t.jsx(ft,{conversation:h,customerProfile:A[h.user_id]??null,isSelected:h.id===f,onSelectConversation:m},h.id)),L]})]})]})});
1Ee.displayName="AdminSupportThreadsSidebar";const qr="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20id='mdi-arrow-up'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M13,20H11V8L5.5,13.5L4.08,12.08L12,4.16L19.92,12.08L18.5,13.5L13,8V20Z'%20/%3e%3c/svg%3e";function Vr({color:e}){return t.jsx(T,{as:"span","aria-hidden":"true",boxSize:"18px",color:e,bg:"currentColor",sx:{mask:`url("${qr}") center / contain no-repeat`}})}const gt=i.memo(({conversationId:e,isSubmittingReply:r,onSubmitReply:s})=>{const{t:n}=N(),[a,d]=i.useState(""),[p,u]=i.useState(!1),[l,x]=i.useState(null),f=i.useRef(0),y=i.useRef(!1),g=i.useRef(e);g.current=e,i.useEffect(()=>(f.current+=1,y.current=!1,d(""),x(null),u(!1),()=>{f.current+=1}),[e]);const m=async()=>{var b;const A=a.trim();if(!e||!A||y.current||r)return;const E=e,L=++f.current,R=()=>f.current===L&&g.current===E;y.current=!0,u(!0),x(null);let h="translation";try{const j=await Xt({conversationId:e,content:A});if(!R())return;if(!((b=j.translated_reply)!=null&&b.trim()))throw new Error("empty_translation");h="send";const k=j.translated_reply!==A?ur({original_text:A,target_language_code:j.target_language_code,target_language_name:j.target_language_name}):null;k?await s(j.translated_reply,k):await s(j.translated_reply),R()&&d("")}catch{ne(new Error("support_admin_reply_failed"),{scope:"support-admin-reply",tags:{stage:h}}),R()&&x(n("admin.support.threads.reply_failed","Couldnât send your reply. Your draft is saved here â try again."))}finally{R()&&(y.current=!1,u(!1))}},v=p||r,S=n("admin_support.threads_support_admin_threads_adminsupportreplycomposer.reply_to_the_customer_2e0bf708","Reply to the customerâ¦");return t.jsxs(T,{p:{base:3,md:5},bg:o.surface.white,borderTopWidth:"1px",borderColor:o.surface.border,flexShrink:0,children:[t.jsxs(C,{align:"flex-end",gap:2,p:2,borderWidth:"1px",borderColor:o.surface.border,borderRadius:"30px",bg:o.surface.background,transition:"border-color 150ms, box-shadow 150ms",_focusWithin:{borderColor:o.primaryAction.default,boxShadow:`0 0 0 3px ${o.primaryAction.light}`},children:[t.jsx(xr,{"aria-label":S,value:a,onChange:A=>d(A.target.value),placeholder:S,as:gr,minH:"40px",maxLength:8e3,minRows:1,maxRows:5,flex:1,minW:0,fontSize:"14px",lineHeight:"22px",resize:"none",border:"none",bg:"transparent",px:2,py:"9px",_focusVisible:{boxShadow:"none"},isDisabled:!e||v,onKeyDown:A=>{A.key==="Enter"&&!A.shiftKey&&!A.nativeEvent.isComposing&&(A.preventDefault(),A.stopPropagation(),m())}}),t.jsx(Oe,{"aria-label":n("admin_support.threads_support_admin_threads_adminsupportreplycomposer.send_reply_7f7e603a","Send reply"),title:"",LeftIcon:Vr,buttonPrimaryOrSecondaryType:"primary",iconSpacing:"0px",p:0,w:"40px",h:"40px",minW:"40px",borderRadius:"full",flexShrink:0,_focusVisible:{outline:"2px solid",outlineColor:o.primaryAction.default,outlineOffset:"2px"},isLoading:v,disabled:!e||v||!a.trim(),onClick:()=>void m()})]}),l?t.jsx(c,{role:"alert",fontSize:"12px",color:o.accentColors.errorStrong,mt:2,children:l}):null]})});gt.displayName="AdminSupportReplyComposer";const xt=i.memo(({currentStatus:e,isUpdatingStatus:r,onChangeStatus:s})=>{const{t:n}=N(),a=[{statusKey:"open",labelText:"Open",colorScheme:"yellow"},{statusKey:"waiting_for_customer",labelText:"Waiting",colorScheme:"blue"},{statusKey:"pending_to_check",labelText:"Needs review",colorScheme:"orange"},{statusKey:"done",labelText:"Done",colorScheme:"green"}];return t.jsxs(C,{align:"center",gap:2,flexWrap:"wrap",children:[t.jsx(c,{fontSize:"12px",color:o.text.label,fontWeight:"700",children:n("admin_support.threads_support_admin_threads_adminsupportthreadstatecontrols.status_11dc9e19","Status:")}),t.jsx(br,{"aria-label":n("admin_support.threads_support_admin_threads_adminsupportthreadstatecontrols.status_11dc9e19","Status:"),display:{base:"block",md:"none"},value:e==="ignored"?"done":e,onChange:d=>s(d.target.value),isDisabled:r,size:"sm",h:"44px",w:"auto",minW:"160px",borderRadius:"12px",borderColor:o.surface.border,bg:o.surface.background,children:a.map(({statusKey:d,labelText:p})=>t.jsx("option",{value:d,children:p},d))}),t.jsx(yr,{display:{base:"none",md:"inline-flex"},size:"xs",isAttached:!0,variant:"outline",children:a.map(d=>{const p=(e==="ignored"?"done":e)===d.statusKey;return t.jsx(G,{"aria-pressed":p,colorScheme:p?d.colorScheme:void 0,variant:p?"solid":"outline",isDisabled:r,onClick:()=>s(d.statusKey),children:d.labelText},d.statusKey)})})]})});xt.displayName="AdminSupportThreadStateControls";const Gr=Bt,Yr=Ot,Kr=zt,Le=i.memo(({conversationId:e,conversation:r,messages:s,isLoadingInitialSnapshot:n,errorMessage:a,onStatusChanged:d,onArchiveConversation:p,isArchiving:u,onToggleConversationStar:l,isStarring:x})=>{var k;const{t:f}=N(),y=We(),g=ze(D=>D.currentUser),[m,v]=i.useState(!1),[S,A]=i.useState(!1),E=(r==null?void 0:r.status)!=="done"&&(r==null?void 0:r.status)!=="ignored",L=(r==null?void 0:r.is_starred)===!0,R=f("admin.support.archive","Archive"),h=L?f("admin.support.unstar","Remove from starred"):f("admin.support.star","Add to starred");i.useEffect(()=>{!e||!r||(r.unread_for_admin_count??0)<=0||er({conversationId:e,side:"admin"}).catch(D=>{console.error("Failed to mark conversation as read for admin",D)})},[e,r==null?void 0:r.unread_for_admin_count,r]);const b=i.useCallback(async D=>{if(e){v(!0);try{await ht({conversationId:e,newStatus:D}),d(e,D)}catch(I){y({title:"Failed to update status",description:I instanceof Error?I.message:String(I),status:"error",duration:3e3})}finally{v(!1)}}},[e,d,y]),j=i.useCallback(async(D,I)=>{var _;if(!e||!(g!=null&&g.id))throw new Error("admin_reply_auth_not_ready");A(!0);
1const q=((_=g.name)==null?void 0:_.trim())||[g.first_name,g.last_name].filter(Boolean).join(" ").trim();try{await tr({conversationId:e,adminUserId:g.id,adminUserName:q.length>0?q:null,content:D,adminReplyTranslation:I})}catch(B){throw y({title:"Failed to send reply",description:B instanceof Error?B.message:String(B),status:"error",duration:3e3}),B}finally{A(!1)}},[e,g,y]);return e?a?t.jsx(C,{flex:"1",align:"center",justify:"center",bg:o.surface.background,px:6,children:t.jsxs(c,{fontSize:"14px",color:o.accentColors.errorStrong,children:[f("admin_support.threads_support_admin_threads_adminsupportthreaddetailpanel.failed_to_load_thread_bc1bb3f5","Failed to load thread:")," ",a]})}):t.jsxs(C,{direction:"column",flex:"1",minW:0,minH:0,bg:o.surface.background,children:[t.jsxs(T,{px:{base:4,md:6},py:4,flexShrink:0,bg:o.surface.white,borderBottomWidth:"1px",borderColor:o.surface.border,children:[t.jsxs(C,{align:"center",justify:"space-between",gap:3,mb:2,children:[t.jsxs(T,{minW:0,flex:"1",children:[r?t.jsx(Pe,{conversation:r,fontSize:"17px",fontWeight:"800",noOfLines:2}):null,t.jsxs(C,{align:"center",gap:2,mt:.5,flexWrap:"wrap",children:[r?t.jsx(c,{fontSize:"12px",color:o.text.body,fontWeight:"700",noOfLines:1,children:((k=r.user_name)==null?void 0:k.trim())||f("admin.support.threads.anonymous_user","Anonymous user")}):null,r!=null&&r.user_email?t.jsx(c,{as:"span","aria-hidden":!0,fontSize:"10px",color:o.text.placeholder,children:"â¢"}):null,r!=null&&r.user_email?t.jsx(c,{fontSize:"12px",color:o.text.placeholder,noOfLines:1,children:r.user_email}):null]})]}),r?t.jsxs(C,{align:"center",gap:1,flexShrink:0,children:[E?t.jsx(je,{"aria-label":R,title:R,icon:t.jsx(Gr,{size:20}),minW:"36px",w:"36px",h:"36px",borderRadius:"8px",variant:"ghost",color:o.secondaryAction.default,_hover:{color:o.secondaryAction.hover,bg:o.surface.hover},_active:{bg:o.surface.background},_focusVisible:{outline:`2px solid ${o.primaryAction.default}`,outlineOffset:"2px"},isLoading:u,isDisabled:u,onClick:()=>p(r.id)}):null,t.jsx(je,{"aria-label":h,title:h,"aria-pressed":L,icon:L?t.jsx(Yr,{size:21}):t.jsx(Kr,{size:21}),minW:"36px",w:"36px",h:"36px",borderRadius:"8px",variant:"ghost",color:L?o.tertiaryAction.hover:o.secondaryAction.default,_hover:{color:o.tertiaryAction.hover,bg:o.surface.hover},_active:{color:o.tertiaryAction.pressed,bg:o.surface.background},_focusVisible:{outline:`2px solid ${o.primaryAction.default}`,outlineOffset:"2px"},isLoading:x,isDisabled:x,onClick:()=>l(r.id,!L)})]}):null]}),r?t.jsx(xt,{currentStatus:r.status,isUpdatingStatus:m,onChangeStatus:D=>void b(D)}):null,r!=null&&r.investigation_id&&r.investigation_title?t.jsxs(C,{mt:3,p:3,gap:2.5,align:"flex-start",borderRadius:"8px",bg:o.surface.background,borderWidth:"1px",borderColor:o.surface.border,children:[t.jsx(T,{mt:"2px",flexShrink:0,children:t.jsx(ct,{width:16,height:16,color:o.secondaryAction.default})}),t.jsxs(T,{minW:0,children:[t.jsx(c,{fontSize:"12px",fontWeight:"700",color:o.text.header,children:r.investigation_title}),t.jsx(c,{as:Tt,to:`/admin/support/investigations?investigationId=${encodeURIComponent(r.investigation_id)}`,target:"_blank",rel:"noopener noreferrer",display:"inline-block",mt:1,fontSize:"12px",fontWeight:"700",color:o.secondaryAction.default,_hover:{color:o.secondaryAction.hover,textDecoration:"underline"},children:f("admin.support.threads.view_investigation","View investigation")})]})]}):null]}),t.jsx(mr,{conversationId:e,customerName:r==null?void 0:r.user_name,messages:s,isLoadingInitialSnapshot:n}),t.jsx(gt,{conversationId:e,isSubmittingReply:S,onSubmitReply:j},e)]}):t.jsx(C,{flex:"1",align:"center",justify:"center",bg:o.surface.background,children:t.jsx(c,{fontSize:"14px",color:o.text.placeholder,children:f("admin_support.threads_support_admin_threads_adminsupportthreaddetailpanel.select_a_thread_on_the_left_to_view_it_77fb89c7","Select a thread on the left to view it.")})})});Le.displayName="AdminSupportThreadDetailPanel";function ve(e){return Date.parse(e.responder_updated_at||"")||0}function Jr({conversation:e}){const{t:r}=N(),[s,n]=i.useState(e.responder_enabled!==!1),[a,d]=i.useState(!1),[p,u]=i.useState(!1),l=i.useRef(ve(e));i.useEffect(()=>{const f=ve(e);f<l.current||(f>l.current&&u(!1),l.current=f,n(e.responder_enabled!==!1))},[e.responder_enabled,e.responder_updated_at]);async function x(){if(a)return;const f=l.current;d(!0),u(!1);try{const y=await rr(e.id,!s),g=ve(y);g>=l.current&&(l.current=g,n(y.responder_enabled!==!1))}catch{u(l.current===f)}finally{d(!1)}}
1return t.jsxs(C,{direction:"column",align:"start",gap:2,borderWidth:"1px",borderColor:o.surface.border,borderRadius:"8px",bg:o.surface.offWhite,p:3,children:[t.jsxs(C,{align:"center",justify:"space-between",gap:3,w:"100%",children:[t.jsx(c,{fontSize:"13px",color:o.text.body,children:r("admin.support.responder.description","AI replies automatically to new messages")}),t.jsx(jr,{"aria-label":r("admin.support.responder.label","AI support agent"),"aria-busy":a,isChecked:s,isDisabled:a,onChange:x,flexShrink:0,sx:{"& .chakra-switch__track[data-checked]":{backgroundColor:o.primaryAction.default},"& .chakra-switch__track:not([data-checked])":{backgroundColor:o.secondaryAction.inactive}}})]}),p?t.jsx(c,{fontSize:"12px",color:o.accentColors.errorStrong,role:"alert",children:r("admin.support.responder.error","Couldn't update the AI support agent. Please try again.")}):null]})}function Qr({conversation:e}){const{t:r}=N(),[s]=Ce("(hover: hover) and (pointer: fine)"),n=e.started_client_environment,a=(n==null?void 0:n.platform)||e.started_on_client_platform,d={desktop:r("admin.support.device.desktop","Desktop · Web"),"mobile-web":r("admin.support.device.mobile_web","Phone · Web"),"tablet-web":r("admin.support.device.tablet_web","Tablet · Web"),"mobile-ios-app":r("admin.support.device.ios_app","Phone · iOS app"),"tablet-ios-app":r("admin.support.device.ipad_app","Tablet · iOS app"),"mobile-android-app":r("admin.support.device.android_app","Phone · Android app"),"tablet-android-app":r("admin.support.device.android_tablet","Tablet · Android app"),"mobile-app":r("admin.support.device.mobile_app","Mobile app")};d["web-desktop"]=d.desktop,d["web-mobile"]=d["mobile-web"],d["web-tablet"]=d["tablet-web"];const p={ios:r("admin.support.device.name.ios","iOS"),android:r("admin.support.device.name.android","Android"),macos:r("admin.support.device.name.macos","macOS"),windows:r("admin.support.device.name.windows","Windows"),linux:r("admin.support.device.name.linux","Linux"),chrome_os:r("admin.support.device.name.chrome_os","ChromeOS"),chrome:r("admin.support.device.name.chrome","Chrome"),safari:r("admin.support.device.name.safari","Safari"),firefox:r("admin.support.device.name.firefox","Firefox"),edge:r("admin.support.device.name.edge","Edge"),samsung:r("admin.support.device.name.samsung","Samsung Internet")},u=n==null?void 0:n.operating_system,l=n==null?void 0:n.browser,x=[u?[p[u]||u,n==null?void 0:n.operating_system_version].filter(Boolean).join(" "):null,l?[p[l]||l,n==null?void 0:n.browser_version].filter(Boolean).join(" "):null].filter(Boolean).join(" · "),y=!!(x||n!=null&&n.app_version)&&(!pe&&!ue||s);return t.jsx(oe,{placement:"left",openDelay:200,isDisabled:!y,label:t.jsxs(T,{children:[x?t.jsx(c,{fontSize:"12px",children:x}):null,n!=null&&n.app_version?t.jsx(c,{fontSize:"12px",children:r("admin.support.device.app_version","App {version}",{version:n.app_version})}):null]}),children:t.jsx(c,{as:"span",display:"inline-block",fontSize:"13px",fontWeight:"600",color:o.text.body,tabIndex:y?0:void 0,cursor:y?"help":void 0,children:a&&d[a]||r("admin.support.device.unknown","Not recorded")})})}let $={status:"idle"};function Zr(e,r){const s=ce(e).toLowerCase(),n=ce(r).toLowerCase();return s===n?0:s<n?-1:1}async function Xr(){try{const r=[...await sr()].sort(Zr);return $={status:"loaded",admins:r},r}catch(e){throw $={status:"error",errorMessage:e instanceof Error?e.message:String(e)},e}}function es(){const[e,r]=i.useState(()=>$.status==="loaded"?$.admins:[]),[s,n]=i.useState(()=>$.status==="idle"||$.status==="loading"),[a,d]=i.useState(()=>$.status==="error"?$.errorMessage:null);return i.useEffect(()=>{let p=!0;return $.status==="loaded"?(r($.admins),n(!1),d(null),()=>{p=!1}):(n(!0),d(null),($.status==="loading"?$.pendingPromise:(()=>{const l=Xr();return $={status:"loading",pendingPromise:l},l})()).then(l=>{p&&(r(l),n(!1))}).catch(l=>{p&&(d(l instanceof Error?l.message:String(l)),n(!1))}),()=>{p=!1})},[]),{admins:e,isLoading:s,errorMessage:a}}const bt=i.memo(({conversation:e})=>{const{t:r}=N(),s=We(),n=ze(h=>h.currentUser),{admins:a,isLoading:d,errorMessage:p}=es(),[u,l]=i.useState(!1),[x,f]=i.useState(!1),[y,g]=i.useState(""),m=i.useMemo(()=>{const h=y.trim().toLowerCase();return h?a.filter(b=>[ce(b),b.email_communication??"",b.email_auth??""].join(" ").toLowerCase().includes(h)):a},[a,y]),v=i.useCallback(async(h,b)=>{if(!u){l(!0);try{await nr({conversationId:e.id,assignedAdminUserId:h,assignedAdminUserName:b}),f(!1),g("")}catch(j){s({title:"Couldn't update assignee",description:j instanceof Error?j.message:String(j),status:"error",duration:3e3})}finally{l(!1)}}},[e.id,u,s]),S=i.useCallback(h=>{const b=ce(h);v(h.id,b)},[v]),A=i.useCallback(()=>{v(null,null)},[v]),E=i.useCallback(()=>{var b,j,k;if(!(n!=null&&n.id))return;const h=((b=n.name)==null?void 0:b.trim())||[n.first_name,n.last_name].filter(
1Boolean).join(" ").trim()||((j=n.email_communication)==null?void 0:j.trim())||((k=n.email_auth)==null?void 0:k.trim())||"Admin";v(n.id,h)},[n,v]),L=!!(n!=null&&n.id)&&e.assigned_admin_user_id===(n==null?void 0:n.id),R=e.assigned_admin_user_name?e.assigned_admin_user_name:"No assignee";return t.jsxs(wr,{isOpen:x,onClose:()=>{f(!1),g("")},placement:"bottom-start",children:[t.jsx(Ar,{children:t.jsx(G,{size:"xs",variant:"outline",justifyContent:"flex-start",width:"100%",onClick:()=>f(h=>!h),children:R})}),t.jsxs(vr,{maxW:"320px",children:[t.jsx(Tr,{}),t.jsxs(kr,{p:2,children:[t.jsx(pt,{size:"sm",placeholder:r("admin_support.threads_support_admin_threads_adminsupportthreadassigneecontrol.search_admins_2a96463f","Search adminsâ¦"),value:y,onChange:h=>g(h.target.value),mb:2}),n!=null&&n.id&&!L?t.jsxs(t.Fragment,{children:[t.jsx(T,{px:2,py:2,borderRadius:"6px",cursor:"pointer",_hover:{bg:o.surface.hover},onClick:E,children:t.jsx(c,{fontSize:"13px",fontWeight:"700",color:o.primaryAction.default,children:r("admin_support.threads_support_admin_threads_adminsupportthreadassigneecontrol.assign_to_me_ac507212","Assign to me")})}),t.jsx(Ze,{my:2})]}):null,d?t.jsx(C,{align:"center",justify:"center",py:3,children:t.jsx(me,{size:"sm"})}):p?t.jsx(T,{px:2,py:2,children:t.jsxs(c,{fontSize:"13px",color:o.accentColors.errorStrong,children:[r("admin_support.threads_support_admin_threads_adminsupportthreadassigneecontrol.couldnt_load_admins_a8623e08","Couldn't load admins:")," ",p]})}):t.jsxs(t.Fragment,{children:[t.jsx(c,{fontSize:"11px",fontWeight:"700",color:o.text.label,textTransform:"uppercase",px:2,pb:1,children:r("admin_support.threads_support_admin_threads_adminsupportthreadassigneecontrol.assign_to_admin_89f74e52","Assign to admin")}),m.length===0?t.jsx(T,{px:2,py:2,children:t.jsx(c,{fontSize:"13px",color:o.text.placeholder,children:y.trim()?r("admin.support.threads.no_matching_admins","No admins match that search."):r("admin.support.threads.no_admin_users","No admin users found.")})}):t.jsx(T,{maxH:"240px",overflowY:"auto",children:m.map(h=>{var D,I;const b=h.id===e.assigned_admin_user_id,j=ce(h),k=((D=h.email_communication)==null?void 0:D.trim())||((I=h.email_auth)==null?void 0:I.trim())||"";return t.jsxs(C,{px:2,py:2,borderRadius:"6px",align:"center",justify:"space-between",cursor:"pointer",bg:b?o.primaryAction.light:"transparent",_hover:{bg:b?o.primaryAction.light:o.surface.hover},onClick:()=>S(h),children:[t.jsxs(T,{minW:0,flex:"1",children:[t.jsx(c,{fontSize:"13px",fontWeight:b?"700":"500",noOfLines:1,children:j}),k?t.jsx(c,{fontSize:"11px",color:o.text.placeholder,noOfLines:1,children:k}):null]}),u&&b?t.jsx(me,{size:"xs"}):null]},h.id)})}),e.assigned_admin_user_id?t.jsxs(t.Fragment,{children:[t.jsx(Ze,{my:2}),t.jsx(T,{px:2,py:2,borderRadius:"6px",cursor:"pointer",_hover:{bg:o.surface.hover},onClick:A,children:t.jsx(c,{fontSize:"13px",color:o.text.body,children:r("admin_support.threads_support_admin_threads_adminsupportthreadassigneecontrol.clear_assignee_d409d913","Clear assignee")})})]}):null]})]})]})]})});bt.displayName="AdminSupportThreadAssigneeControl";const ts="#1e1e1e",ae="#333333",P="#e8e8e8",W="#9aa0a6",Ie="#f28b82",yt="#fdd663",Re="#3c4043",Ue="#2d2d2d",Se={size:"sm",variant:"outline",borderColor:"#5f6368",color:P,bg:"transparent",fontWeight:"500",_hover:{bg:Ue,borderColor:"#8ab4f8",color:P},_active:{bg:Re},_disabled:{opacity:.45,cursor:"not-allowed",color:W}};function rs(e){return e===null?W:e>=500?Ie:e>=400?yt:"#81c995"}function ss(e){return{size:"xs",variant:"solid",bg:e?Re:"transparent",color:e?P:W,borderWidth:"1px",borderColor:e?"#8ab4f8":ae,fontWeight:e?"600":"400",_hover:{bg:e?Re:Ue,color:P}}}const St=i.memo(({conversationId:e,isOpen:r,onClose:s,inlineDebugContextRecord:n})=>{const{t:a}=N(),d=We(),[p,u]=i.useState(!1),[l,x]=i.useState(null),[f,y]=i.useState(null),[g,m]=i.useState(n),[v,S]=i.useState("all"),[A,E]=i.useState(null),[L,R]=i.useState(0),h=i.useCallback(()=>{u(!0),x(null),y(null),or(e).then(_=>{var Z;x(_.payload),m(_.bug_investigation_debug_context);const B=((Z=_.payload.network_entries[0])==null?void 0:Z.id)??null;E(B)}).catch(_=>{const B=_ instanceof Error?_.message:String(_);y(B),d({title:"Could not load browser debug logs",description:B,status:"error",duration:4e3,isClosable:!0})}).finally(()=>{u(!1)})},[e,d]);i.useEffect(()=>{r&&h()},[r,h,L]);const b=i.useMemo(()=>l?v==="all"?l.console_entries:v==="log"?l.console_entries.filter(_=>_.level==="log"||_.level==="info"||_.level==="debug"):l.console_entries.filter(_=>_.level===v):[],[v,l]),j=i.useMemo(()=>!l||!A?null:l.network_entries.find(_=>_.id===A)??null,[l,A]),k=g??n,D=i.useCallback(async()=>
1{if(l)try{await navigator.clipboard.writeText(JSON.stringify(l,null,2)),d({title:"Copied debug JSON",status:"success",duration:2e3})}catch{d({title:"Copy failed",status:"error",duration:3e3})}},[l,d]),I=i.useCallback(()=>{const _=(g==null?void 0:g.presigned_get_url)??(n==null?void 0:n.presigned_get_url);_&&window.open(_,"_blank","noopener,noreferrer")},[n==null?void 0:n.presigned_get_url,g==null?void 0:g.presigned_get_url]),q=i.useCallback(()=>{R(_=>_+1)},[]);return t.jsxs(Nt,{isOpen:r,onClose:s,size:"6xl",scrollBehavior:"inside",children:[t.jsx(Wt,{bg:"blackAlpha.700"}),t.jsxs(Ft,{bg:ts,color:P,maxH:"90vh",children:[t.jsx(Pt,{borderBottomWidth:"1px",borderColor:ae,py:3,children:t.jsxs(C,{align:"center",justify:"space-between",pr:8,children:[t.jsx(c,{fontSize:"14px",fontWeight:"600",color:P,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.browser_debug_logs_010e8c35","Browser debug logs")}),t.jsxs(C,{gap:2,children:[t.jsx(G,{...Se,onClick:D,isDisabled:!l,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.copy_all_json_77c23299","Copy all JSON")}),t.jsx(G,{...Se,onClick:I,isDisabled:!(k!=null&&k.presigned_get_url),children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.open_in_new_tab_71bf47a7","Open in new tab")})]})]})}),t.jsx(Er,{color:P,_hover:{bg:Ue}}),t.jsx(Ut,{p:0,children:p?t.jsxs(C,{align:"center",justify:"center",minH:"320px",direction:"column",gap:3,children:[t.jsx(me,{color:W}),t.jsx(c,{fontSize:"13px",color:W,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.loading_console_and_network_capture_9e623a4a","Loading console and network captureâ¦")})]}):f&&!l?t.jsxs(C,{align:"center",justify:"center",minH:"320px",px:6,direction:"column",gap:4,textAlign:"center",children:[t.jsx(c,{fontSize:"14px",fontWeight:"600",color:Ie,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.could_not_load_debug_logs_5c1b99e3","Could not load debug logs")}),t.jsx(c,{fontSize:"13px",color:W,maxW:"480px",children:f}),k?t.jsxs(c,{fontSize:"13px",color:P,children:[a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.summary_on_file_cfc77697","Summary on file:")," ",Ct(k,a)]}):null,t.jsxs(C,{gap:2,children:[t.jsx(G,{...Se,onClick:q,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.retry_9f5cd8a2","Retry")}),t.jsx(G,{...Se,onClick:I,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.open_raw_json_af824f85","Open raw JSON")})]})]}):l?t.jsxs(Lr,{variant:"unstyled",display:"flex",flexDirection:"column",minH:"480px",children:[t.jsxs(Ir,{borderBottomWidth:"1px",borderColor:ae,px:3,gap:1,children:[t.jsx(et,{fontSize:"12px",px:3,py:2,color:W,_selected:{color:P,borderBottom:"2px solid #8ab4f8"},children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.console_9f3341d3","Console")}),t.jsx(et,{fontSize:"12px",px:3,py:2,color:W,_selected:{color:P,borderBottom:"2px solid #8ab4f8"},children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.network_53ebc572","Network")})]}),t.jsxs(Rr,{flex:"1",minH:0,children:[t.jsxs(tt,{p:0,display:"flex",flexDirection:"column",minH:"420px",children:[t.jsx(C,{px:3,py:2,gap:2,borderBottomWidth:"1px",borderColor:ae,children:["all","error","warn","log"].map(_=>t.jsx(G,{...ss(v===_),onClick:()=>S(_),children:_==="all"?a("admin.support.debug.all","All"):_==="error"?a("admin.support.debug.errors","Errors"):_==="warn"?a("admin.support.debug.warnings","Warnings"):a("admin.support.debug.logs","Logs")},_))}),t.jsx(T,{flex:"1",overflowY:"auto",px:3,py:2,fontFamily:"mono",fontSize:"12px",children:b.length===0?t.jsx(c,{color:W,children:l.summary.console_capture_status==="captured"?a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.no_console_entries_for_this_filter_e95b07f6","No console entries for this filter."):a("admin.support.debug.console_not_captured","Console history was not captured for this report. A zero count is unknown, not a clean console.")}):b.map(_=>t.jsxs(T,{mb:3,pb:2,borderBottomWidth:"1px",borderColor:ae,children:[t.jsxs(c,{color:W,fontSize:"11px",mb:1,children:[_.t
1imestamp," · ",_.level]}),t.jsx(c,{color:_.level==="error"?Ie:_.level==="warn"?yt:P,whiteSpace:"pre-wrap",wordBreak:"break-word",children:_.message}),_.stack?t.jsx(c,{mt:1,color:W,whiteSpace:"pre-wrap",fontSize:"11px",children:_.stack}):null]},_.id))})]}),t.jsxs(tt,{p:0,display:"flex",flexDirection:"column",minH:"420px",children:[t.jsxs(T,{flex:"1",overflowY:"auto",borderBottomWidth:"1px",borderColor:ae,children:[l.network_entries.length===0?t.jsx(c,{px:3,py:2,fontFamily:"mono",fontSize:"12px",color:W,children:a("admin.support.debug.network_not_captured","No network history was available for this report. A zero count does not prove requests succeeded.")}):null,l.network_entries.map(_=>{const B=_.id===A;return t.jsxs(C,{px:3,py:2,fontSize:"12px",fontFamily:"mono",cursor:"pointer",bg:B?"#2d2d2d":"transparent",_hover:{bg:"#2a2a2a"},onClick:()=>E(_.id),borderBottomWidth:"1px",borderColor:ae,gap:3,align:"center",children:[t.jsx(c,{minW:"48px",color:W,children:_.method}),t.jsx(c,{minW:"40px",color:rs(_.status),children:_.status??"â"}),t.jsx(c,{flex:"1",noOfLines:1,color:P,children:_.url}),t.jsx(c,{minW:"56px",textAlign:"right",color:W,children:_.duration_ms!==null?`${_.duration_ms}ms`:"â"})]},_.id)})]}),j?t.jsxs(T,{p:3,fontFamily:"mono",fontSize:"11px",maxH:"220px",overflowY:"auto",children:[t.jsx(c,{color:W,mb:2,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.request_4aed03ca","Request")}),t.jsxs(c,{color:P,whiteSpace:"pre-wrap",wordBreak:"break-word",mb:3,children:[JSON.stringify(j.request_headers,null,2),` 2 3`,j.request_body??a("admin.support.debug.empty_body","(empty body)")]}),t.jsx(c,{color:W,mb:2,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.response_6e617e4f","Response")}),t.jsxs(c,{color:P,whiteSpace:"pre-wrap",wordBreak:"break-word",children:[j.error_message?j.error_message:JSON.stringify(j.response_headers,null,2),` 4 5`,j.response_body??a("admin.support.debug.response_body_unavailable","(response body not available â may be blocked by CORS)")]})]}):null]})]})]}):t.jsx(C,{align:"center",justify:"center",minH:"320px",px:6,children:t.jsx(c,{fontSize:"13px",color:W,children:a("admin_support.threads_support_admin_threads_adminsupportthreadbugdebugcontextmodal.no_debug_context_available_for_this_thread_027cb4a3","No debug context available for this thread.")})})})]})]})});St.displayName="AdminSupportThreadBugDebugContextModal";function Ct(e,r){const s=e.summary,n=s.console_capture_status==="captured"?r?r("admin.support.debug.console_error_summary","{count, plural, one {# console error} other {# console errors}}",{count:s.console_error_count}):s.console_error_count===1?"1 console error":`${s.console_error_count} console errors`:r?r("admin.support.debug.console_not_captured_short","console not captured"):"console not captured",a=s.network_capture_status==="instrumented"||s.network_capture_status==="resource_timing"?r?r("admin.support.debug.resource_timing_summary","{failedCount} known failed · {totalCount} resources · {statusCount} statuses",{failedCount:s.network_failed_count,totalCount:s.network_total_count,statusCount:s.network_status_coverage_count??0}):`${s.network_failed_count} known failed · ${s.network_total_count} resources · ${s.network_status_coverage_count??0} statuses`:r?r("admin.support.debug.network_not_captured_short","network not captured"):"network not captured";return`${n} · ${a}`}function ns(e){const r=e.feedback_type_tag==="Bug",s=(e.applied_label_title??"").trim().toLowerCase()==="bug";return(r||s)&&!!e.bug_investigation_debug_context}const jt=i.memo(({conversationId:e})=>{const{t:r}=N(),[s,n]=i.useState(!1),{traceEvents:a,isTraceWindowFull:d,isLoadingInitialSnapshot:p,errorMessage:u}=hr(e),l=i.useMemo(()=>{const x=new Map,f=[];for(const y of a){const g=y.trace_id||"ungrouped",m=x.get(g);if(m){m.events.push(y);continue}const v={traceId:g,turnNumber:f.length+1,events:[y]};x.set(g,v),f.push(v)}return f},[a]);return t.jsxs(T,{mb:4,children:[t.jsxs(C,{as:"button",type:"button",align:"center",gap:1.5,onClick:()=>n(x=>!x),w:"100%",textAlign:"left",children:[s?t.jsx(Ht,{width:10,height:10,color:o.text.label}):t.jsx($t,{width:10,height:10,color:o.text.label}),t.jsx(c,{fontSize:"11px",fontWeight:"700",color:o.text.label,textTransform:"uppercase",children:r("admin_support.threads_support_admin_threads_adminsupporttracetimeline.agent_trace_6c091883","Agent trace")}),a.length>0?t.jsx(c,{fontSize:"11px",color:o.text.placeholder,children:l.length===1?`1 turn, ${a.length} steps`:`${l.length} turns, ${a.length} steps`}):null]}),s?t.jsx(T,{mt:2,children:p&&a.length===0?t.jsxs(C,{align:"center",gap:2,py:2,children:[t.jsx(me,{size:"xs",color:o.primaryAction.default}),t.jsx(c,{fontSize:"12px",color:o.text.label,children:r("admin_support.threads_support_admin_threads_adminsupporttracetimeline.loading_the_agent_trace_2913a74e","Loading the agent traceâ¦")})]}):u?t.jsxs(c,{fontSize:"12px",color:o.accentColors.errorStrong,children:[r("admin_support.threads_support_admin_threads_adminsupporttracetimeline.couldnt_load_the_trace_b338a8a0","Couldn't load the trace:")," ",u]}):l.length===0?t.jsx(c,{fontSize:"12px",color:o.text.placeholder,children:r("admin_support.threads_support_admin_threads_adminsupporttracetimeline.no_agent_steps_recorded_for_this_thread_yet_81ca80cc","no agent steps recorded for this thread yet.")}):t.jsxs(t.Fragment,{children:[d?t.jsx(c,{fontSize:"10.5px",color:o.text.placeholder,mb:2,children:r("admin_support.threads_support_admin_threads_adminsupporttracetimeline.showing_the_most_recent_200_steps_so_turn_1_below_may_not_be_the_first_t_4e442d50","showing the most recent 200 steps, so turn 1 below may not be the first turn.")}):null,l.map(x=>t.jsx(os,{traceEventGroup:x},x.traceId))]})}):null]})});jt.displayName="AdminSupportTraceTimeline";function os({traceEventGroup:e}){const{t:r}=N(),s=e.events[0];return t.jsxs(T,{mb:3,children:[t.jsxs(C,{align:"baseline",justify:"space-between",gap:2,children:[t.jsxs(c,{fontSize:"11px",fontWeight:"700",color:o.text.body,children:[r("admin_support.threads_support_admin_threads_adminsupporttracetimeline.turn_368e8081","Turn")," ",e.turnNumber]}
5),t.jsx(c,{fontSize:"10.5px",color:o.text.placeholder,children:Ne(s==null?void 0:s.created_at)})]}),t.jsx(c,{fontSize:"10px",fontFamily:"mono",color:o.text.placeholder,noOfLines:1,children:e.traceId}),t.jsx(T,{mt:1,children:e.events.map(n=>t.jsx(_r,{traceEvent:n},n.id))})]})}function as(e){return`https://console.firebase.google.com/u/0/project/wisdolia/firestore/databases/-default-/data/~2Fusers~2F${encodeURIComponent(e)}`}function Te(e){return`https://app.jungleai.com/admin/users?userId=${encodeURIComponent(e)}`}const at=280,Me=i.memo(({conversation:e,shouldFillAvailableWidth:r=!1})=>{const{t:s}=N(),[n,a]=i.useState(!1);return e?t.jsx(T,{w:r?"100%":`${at}px`,minW:0,flexShrink:0,h:"100%",borderLeftWidth:r?0:"1px",borderColor:o.surface.border,bg:o.surface.white,overflowY:"auto",children:t.jsxs(T,{px:4,py:4,children:[t.jsx(c,{fontSize:"11px",fontWeight:"700",color:o.text.label,textTransform:"uppercase",mb:3,children:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.thread_details_a619125e","Thread details")}),t.jsx(Q,{label:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.status_bae7d5be","Status"),children:t.jsx(Fe,{status:e.status})}),t.jsx(Q,{label:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.assignee_049e3ce5","Assignee"),children:t.jsx(bt,{conversation:e})}),t.jsx(Q,{label:s("admin.support.responder.label","AI support agent"),children:t.jsx(Jr,{conversation:e},e.id)}),t.jsx(Q,{label:s("admin.support.device.label","Device when thread started"),children:t.jsx(Qr,{conversation:e})}),t.jsx(Q,{label:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.started_at_2b491232","Started at"),children:t.jsx(is,{startedAtPageUrl:e.started_at_page_url})}),t.jsx(Q,{label:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.created_accf40c8","Created"),children:t.jsx(oe,{label:new Date(e.created_at).toLocaleString(),placement:"top",openDelay:200,children:t.jsx(c,{fontSize:"13px",color:o.text.body,children:Ne(e.created_at)||"â"})})}),t.jsx(Q,{label:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.email_84add5b2","Email"),children:t.jsx(c,{fontSize:"13px",color:o.text.body,wordBreak:"break-all",children:e.user_email||"â"})}),t.jsx(Q,{label:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.user_id_23bf49da","User ID"),children:t.jsx(it,{href:as(e.user_id),displayText:e.user_id,textToCopy:e.user_id,linkTooltipLabel:"Open this user's Firestore document in the Firebase console",copyTooltipLabel:"Copy user ID",copyAriaLabel:"Copy user ID to clipboard"})}),t.jsx(T,{mb:4,children:t.jsx(fr,{userId:e.user_id,userEmail:e.user_email,compact:!0})}),ns(e)&&e.bug_investigation_debug_context?t.jsxs(Q,{label:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.browser_debug_04d2e64a","Browser debug"),children:[t.jsx(c,{fontSize:"13px",color:o.text.body,mb:2,children:Ct(e.bug_investigation_debug_context,s)}),t.jsx(Oe,{title:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.view_browser_debug_logs_f83a16b0","View browser debug logs"),onClick:()=>a(!0),buttonPrimaryOrSecondaryType:"secondary",buttonStyleType:"outline",size:"small"}),t.jsx(St,{conversationId:e.id,isOpen:n,onClose:()=>a(!1),inlineDebugContextRecord:e.bug_investigation_debug_context})]}):null,t.jsx(jt,{conversationId:e.id}),t.jsx(Q,{label:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.admin_4e7afebc","Admin"),children:t.jsx(it,{href:Te(e.user_id),displayText:Te(e.user_id),textToCopy:Te(e.user_id),linkTooltipLabel:"Open this user in the Jungle admin panel",copyTooltipLabel:"Copy admin panel URL",copyAriaLabel:"Copy admin panel URL to clipboard"})})]})}):t.jsx(T,{w:r?"100%":`${at}px`,minW:0,flexShrink:0,h:"100%",borderLeftWidth:r?0:"1px",borderColor:o.surface.border,bg:o.surface.white,display:"flex",alignItems:"center",justifyContent:"center",px:4,children:t.jsx(c,{fontSize:"13px",color:o.text.placeholder,textAlign:"center",children:s("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.select_a_thread_to_see_details_08415da8","Select a thread to see details.")})})});Me.displayName="AdminSupportThreadRightSidebar";function Q({label:e,children:r}){return t.jsxs(C,{direction:"column",gap:1.5,mb:4,children:[t.jsx(c,{fontSize:"11px",fontWeight:"700",color:o.text.label,textTransform:"uppercase",children:e}),t.jsx(T,{children:r})]})}function is({startedAtPageUrl:e}){const{t:r}=N(),s=i.useMemo(()=>
5{if(!e)return null;try{const a=new URL(e);return a.protocol==="http:"||a.protocol==="https:"?a.toString():null}catch{return null}},[e]),n=i.useMemo(()=>{if(!e)return null;if(!s)return e;const a=new URL(s),d=a.pathname==="/"?"":a.pathname;return`${a.host}${d}`},[e,s]);return e&&!s?t.jsx(oe,{label:e,placement:"top",openDelay:200,children:t.jsx(c,{fontSize:"13px",color:o.text.label,wordBreak:"break-all",children:n})}):!e||!n||!s?t.jsx(c,{fontSize:"13px",color:o.text.placeholder,children:r("admin_support.threads_support_admin_threads_adminsupportthreadrightsidebar.unknown_bc7819b3","Unknown")}):t.jsx(oe,{label:e,placement:"top",openDelay:200,children:t.jsx(ut,{href:s,isExternal:!0,rel:"noopener noreferrer",fontSize:"13px",color:o.primaryAction.default,wordBreak:"break-all",children:n})})}function it({href:e,displayText:r,textToCopy:s,linkTooltipLabel:n,copyTooltipLabel:a,copyAriaLabel:d}){const{t:p}=N(),[u,l]=i.useState(!1),x=i.useCallback(async()=>{try{await navigator.clipboard.writeText(s),l(!0),window.setTimeout(()=>l(!1),1500)}catch(f){console.warn("Failed to copy text to clipboard:",f)}},[s]);return t.jsxs(C,{align:"center",gap:2,children:[t.jsx(oe,{label:n,placement:"top",openDelay:300,children:t.jsx(ut,{href:e,isExternal:!0,rel:"noopener noreferrer",fontSize:"11px",color:o.primaryAction.default,fontFamily:"mono",wordBreak:"break-all",children:r})}),t.jsx(oe,{label:u?p("admin.support.copied","Copied!"):a,placement:"top",openDelay:300,closeOnClick:!1,children:t.jsx(je,{"aria-label":d,icon:u?t.jsx(Sr,{width:12,height:12,color:o.primaryAction.default}):t.jsx(Cr,{width:12,height:14,color:o.text.placeholder}),onClick:x,variant:"ghost",size:"xs",minW:"22px",h:"22px",flexShrink:0})})]})}const ls=Vt(e=>({activeFilter:"open",selectedConversationId:null,setActiveFilter:r=>e({activeFilter:r,selectedConversationId:null}),setSelectedConversationId:r=>e({selectedConversationId:r})})),ds=()=>ls(e=>({activeFilter:e.activeFilter,selectedConversationId:e.selectedConversationId,setActiveFilter:e.setActiveFilter,setSelectedConversationId:e.setSelectedConversationId}),qt),ke=200,cs=750,ps=6e4,us=5*6e4,ms=1e3;function lt(e,r){const s=e.last_message_at??e.created_at??"",n=r.last_message_at??r.created_at??"";return s===n?e.id.localeCompare(r.id):s<n?1:-1}const hs=["done","ignored"],De=["open","waiting_for_customer","pending_to_check"],Be=["done","ignored"];function wt(e){return e?!hs.includes(e):!0}function At(e){const{conversation:r,statusFilter:s,currentAdminUserId:n}=e;switch(s){case"my":return r.assigned_admin_user_id===n&&wt(r.status);case"open":return De.includes(r.status);case"pending_to_check":return r.status==="pending_to_check";case"closed":return Be.includes(r.status);case"starred":return r.is_starred===!0;case"all":return!0}}function _s(e,r){const[s,n]=i.useState([]),[a,d]=i.useState(!0),[p,u]=i.useState(null),[l,x]=i.useState(ke),[f,y]=i.useState(!1);i.useEffect(()=>{x(ke),y(!1)},[r,e]);const g=i.useCallback(()=>{x(m=>m+ke)},[]);return i.useEffect(()=>{if(d(!0),u(null),e==="my"&&!r){n([]);return}if(kt){let M=!1;const F=async()=>{try{const X=await ar({statusFilter:e==="pending_to_check"?e:"all",starredOnly:e==="starred"});if(M)return;const K=X.filter(O=>At({conversation:O,statusFilter:e,currentAdminUserId:r}));K.sort(lt),n(K),y(!1),u(null)}catch(U){if(M)return;u(U instanceof Error?U.message:String(U))}finally{M||d(!1)}};F();const V=window.setInterval(()=>void F(),1500);return()=>{M=!0,window.clearInterval(V)}}const m=Gt(Yt,Et),v=(()=>{switch(e){case"my":return J(m,se("assigned_admin_user_id","==",r),te(l));case"starred":return J(m,se("is_starred","==",!0));case"open":return J(m,se("status","in",De),re("last_message_at","desc"),te(l));case"pending_to_check":return J(m,se("status","==","pending_to_check"),re("last_message_at","desc"),te(l));case"closed":return J(m,se("status","in",Be),re("last_message_at","desc"),te(l));case"all":default:return J(m,re("last_message_at","desc"),te(l))}})(),S=(()=>{switch(e){case"open":return J(m,se("status","in",De),re("created_at","desc"),te(l));case"pending_to_check":return J(m,se("status","==","pending_to_check"),re("created_at","desc"),te(l));case"closed":return J(m,se("status","in",Be),re("created_at","desc"),te(l));case"all":return J(m,re("created_at","desc"),te(l));case"my":case"starred":return null}})();let A=null,E=S?null:{docs:[]},L=!1,R=!1,h=!1,b=null,j=null,k=!1,D=new Set,I=[];const q=()=>{j!==null&&(window.clearTimeout(j),j=null)};function _(){L||I.length===0||j!==null||(j=window.setTimeout(()=>{j=null,B()},us))}function B(M=cs){if(!L){if(R){h=!0;return}b===null&&(b=window.setTimeout(async()=>{b=null;const F=[...I];if(F.length===0)return;R=!0,h=!1;let V=!1;try{await ir({conversationIds:F})}catch(U){V=!0,ne(U,{scope:"admin-support-conversation-summary-translation-backfill",level:"warning"})}finally{R=!1,V?B(ps):h?B():_()}},M))}}const Z=()=>
5{if(!A||!E)return;const M=new Map;for(const O of[A,E])for(const le of O.docs){const _e=le.data();M.set(le.id,{..._e,id:le.id})}const F=Array.from(M.values()),V=e==="my"?F.filter(O=>wt(O.status)):F;V.sort(lt);const U=V.slice(0,l);n(U),y(e==="starred"?V.length>l:A.docs.length===l||E.docs.length===l),d(!1);const X=new Set(U.filter(O=>O.admin_english_translation_checked_at&&O.admin_english_messages_checked_at).map(O=>O.id)),K=Array.from(X).some(O=>!D.has(O));D=X,I=U.filter(O=>!O.admin_english_translation_checked_at||!O.admin_english_messages_checked_at).map(O=>O.id).slice(0,ms),(K||I.length===0)&&q(),I.length>0&&(!k||K)&&(k=!0,B())},he=Xe(v,M=>{A=M,Z()},M=>{console.error("[useAdminSupportConversationsListener] Firestore listener failed:",M),ne(M,{scope:"support-admin-conversations-listener",fingerprint:["support-firestore-listener-failed","admin-conversations"]}),u(M.message),d(!1)}),ie=S?Xe(S,M=>{E=M,Z()},M=>{console.error("[useAdminSupportConversationsListener] Firestore compatibility listener failed:",M),ne(M,{scope:"support-admin-conversations-listener",fingerprint:["support-firestore-listener-failed","admin-conversations-compatibility"]}),E={docs:[]},Z()}):null;return()=>{L=!0,b!==null&&window.clearTimeout(b),q(),he(),ie==null||ie()}},[e,r,l]),{conversations:s,isLoadingInitialSnapshot:a,errorMessage:p,canLoadMoreConversations:f,loadMoreConversations:g}}function fs(e){const r=e.trim(),[s,n]=i.useState(0),[a,d]=i.useState(),[p,u]=i.useState(!1),l=i.useRef(!1),[x,f]=i.useState(null),y=i.useCallback(()=>{f(null),d(void 0),n(S=>S+1)},[]);i.useEffect(()=>{d(void 0),f(null)},[r]),i.useEffect(()=>{if(!r)return;const S=new AbortController;l.current=!!a,u(!!a);const A=window.setTimeout(()=>{lr(r,S.signal,a).then(E=>{S.signal.aborted||(f(L=>({query:r,conversations:a&&(L==null?void 0:L.query)===r?Array.from(new Map([...L.conversations,...E.conversations].map(R=>[R.id,R])).values()):E.conversations,nextCursor:E.next_cursor,error:!1})),l.current=!1,u(!1))},()=>{S.signal.aborted||(ne(new Error("support_admin_thread_search_failed"),{scope:"support-admin-search"}),f(E=>({query:r,conversations:(E==null?void 0:E.query)===r?E.conversations:[],nextCursor:a??null,error:!0})),l.current=!1,u(!1))})},a?0:250);return()=>{window.clearTimeout(A),S.abort()}},[r,s,a]);const g=i.useCallback(()=>{a?n(S=>S+1):y()},[a,y]),m=(x==null?void 0:x.query)===r?x:null,v=i.useCallback(()=>{!(m!=null&&m.nextCursor)||l.current||(l.current=!0,u(!0),d(m.nextCursor))},[m]);return{isSearching:!!r&&!m,conversations:(m==null?void 0:m.conversations)??[],hasError:(m==null?void 0:m.error)??!1,canLoadMore:!!(m!=null&&m.nextCursor)&&!p&&!(m!=null&&m.error),loadMore:v,refresh:y,retry:g}}function hn(){var Ye;const{t:e}=N(),[r]=Ce("(max-width: 768px)"),[s,n]=Lt(),[a]=Ce("(max-width: 64em)",{ssr:!1}),[d]=Ce("(max-width: 47.99em)",{ssr:!1}),[p,u]=i.useState("conversation"),[l,x]=i.useState(null),[f,y]=i.useState(""),g=fs(f),m=!!f.trim(),v=i.useRef(m);v.current=m;const S=g.refresh,[A,E]=i.useState(null),[L,R]=i.useState(null),{activeFilter:h,selectedConversationId:b,setActiveFilter:j,setSelectedConversationId:k}=ds(),D=i.useRef(h),I=i.useRef(b);i.useEffect(()=>{D.current=h},[h]),i.useEffect(()=>{I.current=b},[b]);const q=((Ye=s.get("conversation_id")??s.get("conversationId"))==null?void 0:Ye.trim())||null;i.useEffect(()=>{q&&(I.current=q,k(q))},[q,k]);const _=ze(w=>{var z;return((z=w.currentUser)==null?void 0:z.id)??null}),{conversations:B,isLoadingInitialSnapshot:Z,errorMessage:he,canLoadMoreConversations:ie,loadMoreConversations:M}=_s(h,_),F=i.useMemo(()=>l?B.filter(w=>w.feedback_type_tag===l):B,[B,l]),V=i.useRef(F),U=i.useRef(_),X=i.useRef(new Map);i.useEffect(()=>{V.current=F,F.forEach((w,z)=>{var H;X.current.set(w.id,{conversation:w,followingConversationId:((H=F[z+1])==null?void 0:H.id)??null})})},[F]),i.useEffect(()=>{U.current=_},[_]);const{conversation:K,messages:O,isLoadingInitialSnapshot:le,errorMessage:_e}=Mr(b,!0),He=i.useCallback(w=>{I.current=w,k(w),u("conversation")},[k]),$e=i.useCallback(w=>{D.current=w,I.current=null,j(w)},[j]),qe=i.useCallback(w=>{y(""),x(w),I.current=null,k(null),w!==l&&X.current.clear()},[l,k]),fe=i.useCallback(()=>
5{if(!s.has("conversation_id")&&!s.has("conversationId"))return;const w=new URLSearchParams(s);w.delete("conversation_id"),w.delete("conversationId"),n(w,{replace:!0})},[s,n]),ge=i.useCallback((w,z)=>{var Qe;if(v.current||I.current!==w)return;const H=V.current,de=H.findIndex(Ae=>Ae.id===w),ee=X.current.get(w),ye=H[de]??(ee==null?void 0:ee.conversation);if(!ye||At({conversation:{...ye,...z},statusFilter:D.current,currentAdminUserId:U.current}))return;const Ke=de>=0?((Qe=H[de+1])==null?void 0:Qe.id)??null:(ee==null?void 0:ee.followingConversationId)??null,Je=H.some(Ae=>Ae.id===Ke)?Ke:null;I.current=Je,k(Je),u("conversation"),fe()},[fe,k]),xe=i.useCallback((w,z)=>{v.current&&S(),!(z!=="done"&&z!=="ignored")&&ge(w,{status:z})},[ge,S]),be=i.useCallback(w=>{var ee;const z=V.current,H=z.findIndex(ye=>ye.id===w),de=z[H];de&&X.current.set(w,{conversation:de,followingConversationId:((ee=z[H+1])==null?void 0:ee.id)??null})},[]),Ve=i.useCallback(async w=>{if(!A){be(w),E(w);try{await ht({conversationId:w,newStatus:"done"}),xe(w,"done")}catch(z){console.error("Failed to archive support conversation",z),ne(z,{scope:"support-admin-thread-archive",fingerprint:["support-admin-thread-archive-failed"]})}finally{E(null)}}},[A,be,xe]),Ge=i.useCallback(async(w,z)=>{if(!L){be(w),R(w);try{await dr({conversationId:w,isStarred:z}),v.current&&S(),ge(w,{is_starred:z})}catch(H){console.error("Failed to update support conversation star",H),ne(H,{scope:"support-admin-thread-star",fingerprint:["support-admin-thread-star-failed"]})}finally{R(null)}}},[ge,be,L,S]),vt=i.useCallback(()=>{I.current=null,k(null),u("conversation"),fe()},[fe,k]),we=`calc(100dvh - ${Number.parseInt(r?It:Rt,10)+(d?76:32)}px)`;return a?b?t.jsxs(C,{"data-testid":"admin-support-threads-page",borderRadius:"16px",overflow:"hidden",borderWidth:"1px",borderColor:o.surface.border,direction:"column",h:we,w:"100%",minW:0,children:[t.jsxs(C,{minH:"56px",px:2,align:"center",justify:"space-between",gap:2,bg:o.surface.white,borderBottomWidth:"1px",borderColor:o.surface.border,children:[t.jsx(je,{"aria-label":e("customer_support.header.aria_back","Back"),icon:t.jsx(Dr,{width:20,height:20}),onClick:vt,minW:"44px",h:"44px",variant:"ghost",borderRadius:"full"}),t.jsxs(C,{gap:1,p:1,bg:o.surface.background,borderRadius:"full",children:[t.jsx(G,{minH:"44px",borderRadius:"full",size:"sm",variant:p==="conversation"?"solid":"ghost",colorScheme:p==="conversation"?"green":void 0,onClick:()=>u("conversation"),children:e("admin.support.threads.mobile.conversation","Conversation")}),t.jsx(G,{minH:"44px",borderRadius:"full",size:"sm",variant:p==="details"?"solid":"ghost",colorScheme:p==="details"?"green":void 0,onClick:()=>u("details"),children:e("admin.support.threads.mobile.details","Details")})]})]}),t.jsx(C,{flex:"1",minH:0,minW:0,sx:{"& button":{minWidth:"44px",minHeight:"44px"},"& a":{minHeight:"44px",display:"inline-flex",alignItems:"center"}},children:p==="conversation"?t.jsx(Le,{conversationId:b,conversation:K,messages:O,isLoadingInitialSnapshot:le,errorMessage:_e,onStatusChanged:xe,onArchiveConversation:Ve,isArchiving:A===b,onToggleConversationStar:Ge,isStarring:L===b}):t.jsx(Me,{conversation:K,shouldFillAvailableWidth:!0})})]}):t.jsx(C,{"data-testid":"admin-support-threads-page",borderRadius:"16px",overflow:"hidden",borderWidth:"1px",borderColor:o.surface.border,h:we,w:"100%",minW:0,children:t.jsx(Ee,{searchQuery:f,activeType:m?null:l,onChangeType:qe,onSearchQueryChange:y,onRetrySearch:g.retry,activeFilter:h,conversations:m?g.conversations:F,isLoadingInitialSnapshot:m?g.isSearching:Z,errorMessage:m?g.hasError?e("admin.support.threads.search_failed","Search is unavailable. Please try again."):null:he,canLoadMoreConversations:m?g.canLoadMore:ie,selectedConversationId:b,onChangeFilter:$e,onLoadMoreConversations:m?g.loadMore:M,onSelectConversation:
5He,shouldFillAvailableWidth:!0})}):t.jsxs(C,{"data-testid":"admin-support-threads-page",borderRadius:"16px",overflow:"hidden",borderWidth:"1px",borderColor:o.surface.border,h:we,w:"100%",children:[t.jsx(Ee,{searchQuery:f,activeType:m?null:l,onChangeType:qe,onSearchQueryChange:y,onRetrySearch:g.retry,activeFilter:h,conversations:m?g.conversations:F,isLoadingInitialSnapshot:m?g.isSearching:Z,errorMessage:m?g.hasError?e("admin.support.threads.search_failed","Search is unavailable. Please try again."):null:he,canLoadMoreConversations:m?g.canLoadMore:ie,selectedConversationId:b,onChangeFilter:$e,onLoadMoreConversations:m?g.loadMore:M,onSelectConversation:He}),t.jsx(Le,{conversationId:b,conversation:K,messages:O,isLoadingInitialSnapshot:le,errorMessage:_e,onStatusChanged:xe,onArchiveConversation:Ve,isArchiving:A===b,onToggleConversationStar:Ge,isStarring:L===b}),t.jsx(Me,{conversation:K})]})}export{hn as default}; 6//# sourceMappingURL=AdminSupportThreadsPage-CHnAdzzO.js.map
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.