@linktr.ee/messaging-react 4.2.0-rc-1787325521 → 4.2.0-rc-1787599724

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/{Card-BYJyA83X.js → Card-D7UPq5-g.js} +2 -2
  2. package/dist/{Card-BYJyA83X.js.map → Card-D7UPq5-g.js.map} +1 -1
  3. package/dist/{Card-BplJtZao.cjs → Card-DcBZqMBt.cjs} +2 -2
  4. package/dist/{Card-BplJtZao.cjs.map → Card-DcBZqMBt.cjs.map} +1 -1
  5. package/dist/assets/index.css +1 -1
  6. package/dist/{index-BUC9vqhJ.js → index-CSkr_CO5.js} +2089 -1952
  7. package/dist/index-CSkr_CO5.js.map +1 -0
  8. package/dist/index-CwkY7QwT.cjs +3 -0
  9. package/dist/index-CwkY7QwT.cjs.map +1 -0
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.d.ts +59 -78
  12. package/dist/index.js +26 -30
  13. package/dist/testing.cjs +1 -1
  14. package/dist/testing.cjs.map +1 -1
  15. package/dist/testing.js +2 -2
  16. package/dist/testing.js.map +1 -1
  17. package/package.json +13 -11
  18. package/src/components/AttachmentCard/utils/icons.ts +7 -6
  19. package/src/components/Avatar/Avatar.test.tsx +0 -126
  20. package/src/components/Avatar/getAvatarEmoji.test.ts +0 -39
  21. package/src/components/ChannelList/CustomChannelPreview.test.tsx +3 -410
  22. package/src/components/ChannelList/index.test.tsx +1 -132
  23. package/src/components/ChannelView.stories.tsx +0 -4
  24. package/src/components/ChannelView.test.tsx +3 -9
  25. package/src/components/CustomMessage/CustomMessage.stories.tsx +314 -6
  26. package/src/components/CustomMessage/CustomMessage.test.tsx +2 -56
  27. package/src/components/CustomMessage/MessageTag.stories.tsx +53 -17
  28. package/src/components/CustomMessage/MessageTag.test.tsx +40 -7
  29. package/src/components/CustomMessage/MessageTag.tsx +39 -7
  30. package/src/components/CustomMessage/SentMessageDeliveryStatus.test.tsx +7 -8
  31. package/src/components/CustomMessage/SentMessageDeliveryStatus.tsx +1 -2
  32. package/src/components/CustomMessage/StreamAttachmentMessage.test.tsx +33 -0
  33. package/src/components/CustomMessage/StreamAttachmentMessage.tsx +12 -5
  34. package/src/components/CustomMessage/index.tsx +19 -22
  35. package/src/components/CustomMessageInput/index.tsx +1 -1
  36. package/src/components/CustomSystemMessage/index.tsx +2 -3
  37. package/src/components/LinkAttachment/LinkAttachment.test.tsx +0 -327
  38. package/src/components/MessageAttachment/Audio/AudioAttachment.stories.tsx +165 -58
  39. package/src/components/MessageAttachment/Audio/WaveformAudioRow.test.tsx +153 -0
  40. package/src/components/MessageAttachment/Audio/WaveformAudioRow.tsx +450 -0
  41. package/src/components/MessageAttachment/Audio/audioRowRequester.test.ts +24 -0
  42. package/src/components/MessageAttachment/Audio/audioRowRequester.ts +16 -0
  43. package/src/components/MessageAttachment/Audio/index.tsx +83 -77
  44. package/src/components/MessageAttachment/MessageAttachment.test.tsx +176 -74
  45. package/src/components/MessageAttachment/_shared/fileMeta.test.ts +0 -44
  46. package/src/components/MessageAttachment/_shared/useIsClient.ts +23 -0
  47. package/src/components/MessageAttachment/index.tsx +25 -9
  48. package/src/components/MessageAttachment/types.ts +19 -9
  49. package/src/components/MessagingShell/MessagingShell.test.tsx +0 -20
  50. package/src/components/MessagingShell/index.tsx +0 -2
  51. package/src/components/RichCard/RichCard.test.tsx +1 -3
  52. package/src/index.ts +0 -4
  53. package/src/providers/MessagingProvider.test.tsx +2 -130
  54. package/src/providers/MessagingProvider.tsx +15 -26
  55. package/src/styles.css +210 -57
  56. package/src/testing/createMockMessagingClient.ts +2 -2
  57. package/src/types.ts +0 -9
  58. package/dist/index-BUC9vqhJ.js.map +0 -1
  59. package/dist/index-BkqyKPJP.cjs +0 -3
  60. package/dist/index-BkqyKPJP.cjs.map +0 -1
  61. package/src/components/AttachmentCard/MediaPlayer.test.tsx +0 -346
  62. package/src/components/AttachmentCard/Thumbnail.test.tsx +0 -215
  63. package/src/components/AttachmentCard/index.test.tsx +0 -160
  64. package/src/components/ChannelList/ChannelListContext.test.tsx +0 -87
  65. package/src/components/CustomMessage/Locked.stories.tsx +0 -108
  66. package/src/components/CustomMessage/PaidMessage.stories.tsx +0 -42
  67. package/src/components/CustomMessage/Tip.stories.tsx +0 -48
  68. package/src/components/CustomMessage/TipMessage/TipMessage.stories.tsx +0 -51
  69. package/src/components/CustomMessage/TipMessage/TipMessage.test.tsx +0 -65
  70. package/src/components/CustomMessage/TipMessage/index.tsx +0 -27
  71. package/src/components/FaqList/FaqList.test.tsx +0 -204
  72. package/src/components/LinkAttachment/components/_shared/BubbleTail.test.tsx +0 -76
  73. package/src/components/LinkAttachment/components/_shared/CardBody.test.tsx +0 -248
  74. package/src/components/LinkAttachment/components/_shared/CardCta.test.tsx +0 -123
  75. package/src/components/LinkAttachment/components/_shared/CardShell.test.tsx +0 -193
  76. package/src/components/LinkAttachment/components/_shared/CardThumbnail.test.tsx +0 -242
  77. package/src/components/LinkAttachment/components/_shared/hex.test.ts +0 -37
  78. package/src/components/LinkAttachment/components/_shared/normalizeExternalHref.test.ts +0 -72
  79. package/src/components/LinkAttachment/components/_shared/useChinPalette.test.ts +0 -162
  80. package/src/components/MessageAttachment/MessageAttachment.behavior.test.tsx +0 -182
  81. package/src/components/MessageAttachment/_shared/Bubble.test.tsx +0 -111
  82. package/src/components/MessageAttachment/_shared/CarouselNav.test.tsx +0 -36
  83. package/src/components/MessageAttachment/_shared/CompactDocumentRow.test.tsx +0 -114
  84. package/src/components/MessageAttachment/_shared/DismissButton.test.tsx +0 -42
  85. package/src/components/MessageAttachment/_shared/DownloadAction.test.tsx +0 -168
  86. package/src/components/MessageAttachment/_shared/ImageViewer.test.tsx +0 -52
  87. package/src/components/MessageAttachment/_shared/MediaStackGrid.test.tsx +0 -69
  88. package/src/components/MessageAttachment/_shared/PdfViewer.test.tsx +0 -45
  89. package/src/components/MessageAttachment/_shared/VideoViewer.test.tsx +0 -55
  90. package/src/components/MessageAttachment/_shared/ViewerShell.test.tsx +0 -246
  91. package/src/components/MessageAttachment/_shared/triggerDownload.test.ts +0 -113
  92. package/src/components/MessageAttachment/_shared/useCarousel.test.tsx +0 -68
  93. package/src/components/MessageAttachment/_shared/viewerChromeClasses.test.ts +0 -16
  94. package/src/logging/index.test.tsx +0 -136
  95. package/src/logging/index.tsx +0 -48
  96. package/src/stories/customMessageStoryTemplate.tsx +0 -202
@@ -0,0 +1,3 @@
1
+ "use strict";const t=require("react/jsx-runtime"),h=require("react"),Gs=require("@linktr.ee/messaging-core"),ke=require("stream-chat"),w=require("stream-chat-react"),Y=require("@linktr.ee/messaging-taxonomy"),N=require("classnames"),C=require("@phosphor-icons/react"),Ye=require("stream-chat-react/experimental"),Jt=h.createContext({service:null,client:null,isConnected:!1,isLoading:!1,error:null,capabilities:{},refreshConnection:async()=>{},debug:!1}),We=()=>h.useContext(Jt),Ys=({children:e,user:s,serviceConfig:n,apiKey:a,capabilities:r={},debug:i=!1,client:l})=>{var E,k;const o=h.useCallback((A,...O)=>{i&&console.log(`🔥 [MessagingProvider] ${A}`,...O)},[i]);o("🔄 RENDER START",{userId:s==null?void 0:s.id,apiKey:(a==null?void 0:a.substring(0,8))+"...",serviceConfig:!!n,capabilities:Object.keys(r)});const[d,u]=h.useState(null),[f,m]=h.useState(null),[x,c]=h.useState(!1),[v,j]=h.useState(!1),[p,g]=h.useState(null),b=h.useRef(!1),y=h.useRef(null),_=h.useRef(n);_.current=n;const R=h.useRef(i);R.current=i;const L=h.useRef({userId:s==null?void 0:s.id,apiKey:a,serviceConfig:n,capabilities:r}),I=h.useRef(0);I.current++,o("📊 RENDER INFO",{renderCount:I.current,currentProps:{userId:s==null?void 0:s.id,apiKey:(a==null?void 0:a.substring(0,8))+"..."},propChanges:{userChanged:L.current.userId!==(s==null?void 0:s.id),apiKeyChanged:L.current.apiKey!==a,serviceConfigChanged:L.current.serviceConfig!==n,capabilitiesChanged:L.current.capabilities!==r}}),L.current={userId:s==null?void 0:s.id,apiKey:a,serviceConfig:n,capabilities:r};const z=h.useRef(null);!l&&a&&((E=z.current)==null?void 0:E.apiKey)!==a&&(z.current={apiKey:a,client:new ke.StreamChat(a)});const F=l||(a?((k=z.current)==null?void 0:k.client)??null:null);h.useEffect(()=>{const A=I.current,O=_.current;if(l){y.current=null,u(null),m(null),c(!1),g(null),j(!1);return}if(!a||!F||!O){o("⚠️ SERVICE INIT SKIPPED",{renderCount:A,reason:"Missing apiKey, client, or serviceConfig"});return}o("🚀 CREATING SERVICE",{renderCount:A,apiKey:(a==null?void 0:a.substring(0,8))+"..."});const B=new Gs.StreamChatService({...O,apiKey:a,debug:R.current,client:F});y.current=B,u(B),o("✅ SERVICE SET",{renderCount:A,serviceInstance:!!B})},[a,F,l]);const M=h.useRef(null);h.useEffect(()=>{var O,B;if(o("🔗 USER CONNECTION EFFECT TRIGGERED",{hasService:!!d,hasUser:!!s,userId:s==null?void 0:s.id,isConnecting:b.current,isConnected:x,dependencies:{service:!!d,userId:s==null?void 0:s.id}}),l)return;if(!d||!s){o("⚠️ USER CONNECTION SKIPPED","Missing service or user");return}if(b.current){o("⚠️ USER CONNECTION SKIPPED","Already connecting");return}if(((O=M.current)==null?void 0:O.serviceId)===d&&((B=M.current)==null?void 0:B.userId)===s.id){o("⚠️ USER CONNECTION SKIPPED","Already connected this user with this service");return}(async()=>{o("🚀 STARTING USER CONNECTION",{userId:s.id}),b.current=!0,j(!0),g(null);try{o("📞 CALLING SERVICE.CONNECTUSER",{userId:s.id});const H=await d.connectUser(s);m(H),c(!0),M.current={serviceId:d,userId:s.id},o("✅ USER CONNECTION SUCCESS",{userId:s.id,clientId:H.userID})}catch(H){const Z=H instanceof Error?H.message:"Connection failed";g(Z),o("❌ USER CONNECTION ERROR",{userId:s.id,error:Z})}finally{j(!1),b.current=!1,o("🔄 USER CONNECTION FINISHED",{userId:s.id,isConnected:x})}})()},[d,s,o,x,l]),h.useEffect(()=>{const A=F;return()=>{var O;A&&(M.current=null,(O=y.current)==null||O.disconnectUser().catch(console.error))}},[F]);const T=h.useCallback(async()=>{if(o("🔄 REFRESH CONNECTION CALLED",{hasService:!!d,hasUser:!!s}),!l){if(!d||!s){o("⚠️ REFRESH CONNECTION SKIPPED","Missing service or user");return}o("🚀 STARTING CONNECTION REFRESH",{userId:s.id}),j(!0);try{o("🔌 DISCONNECTING FOR REFRESH"),await d.disconnectUser(),o("📞 RECONNECTING FOR REFRESH");const A=await d.connectUser(s);m(A),c(!0),g(null),o("✅ CONNECTION REFRESH SUCCESS",{userId:s.id})}catch(A){const O=A instanceof Error?A.message:"Refresh failed";g(O),o("❌ CONNECTION REFRESH ERROR",{userId:s.id,error:O})}finally{j(!1),o("🔄 CONNECTION REFRESH FINISHED",{userId:s.id})}}},[d,s,o,l]),D=h.useMemo(()=>(o("💫 CONTEXT VALUE MEMOIZATION",{hasService:!!d,hasClient:!!f,isConnected:x,isLoading:v,hasError:!!p,capabilitiesKeys:Object.keys(r)}),{service:l?null:d,client:l??f,isConnected:l?!0:x,isLoading:l?!1:v,error:l?null:p,capabilities:r,refreshConnection:T,debug:i}),[d,f,l,x,v,p,r,T,i,o]);return o("🔄 RENDER END",{renderCount:I.current,willRenderChat:!!F,contextValueReady:!!D}),t.jsx(Jt.Provider,{value:D,children:F?t.jsx(w.Chat,{client:F,customClasses:{channelList:"str-chat__channel-list str-chat__channel-list-react bg-transparent lg:border-r-2 border-r-0 border-[#0000000A]"},children:e}):e})},Qt=()=>We(),es=e=>{var a,r;const[s,n]=h.useState(!!((r=(a=e==null?void 0:e.state)==null?void 0:a.membership)!=null&&r.pinned_at));return h.useEffect(()=>{var l;if(!e){n(!1);return}n(!!((l=e.state.membership)!=null&&l.pinned_at));const i=o=>{var d;n(o!=null&&o.member?!!o.member.pinned_at:!!((d=e.state.membership)!=null&&d.pinned_at))};return e.on("member.updated",i),()=>{e.off("member.updated",i)}},[e]),s};function qe(e,s,n){const a=Object.values(e||{});if(Y.isOfficialChannel(n)){const r=a.find(i=>{var l;return((l=i.user)==null?void 0:l.id)===Y.OFFICIAL_SENDER_USER_ID});if(r)return r}return a.find(r=>{var i;return((i=r.user)==null?void 0:i.id)&&r.user.id!==s})}const Ws=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function ts(e){return Ws.test(e.trim())}function Lt(e,s){const n=e==null?void 0:e.trim();return!n||s&&n===s||s&&n===`Follower ${s}`?!1:!ts(n)}function Xe(e){return Lt(e==null?void 0:e.name,e==null?void 0:e.id)?e.name.trim():Lt(e==null?void 0:e.username,e==null?void 0:e.id)?e.username.trim():"Unknown member"}const Dt=[{emoji:"🍎",bgColor:"#FFD1DD"},{emoji:"🍌",bgColor:"#FFF1C9"},{emoji:"🍇",bgColor:"#E6D9FF"},{emoji:"🍊",bgColor:"#D6F4FF"},{emoji:"🍓",bgColor:"#FFE0AE"},{emoji:"🥥",bgColor:"#F7E7D8"},{emoji:"🍒",bgColor:"#DFF4D8"},{emoji:"🥭",bgColor:"#FFD8C2"},{emoji:"🍉",bgColor:"#D6EBFF"},{emoji:"🍋",bgColor:"#CAEEB5"},{emoji:"🥝",bgColor:"#FFE7C7"},{emoji:"🫒",bgColor:"#F6E3B4"},{emoji:"🍈",bgColor:"#D9F7E1"}];function qs(e){let s=0;for(let n=0;n<e.length;n++){const a=e.charCodeAt(n);s=(s<<5)-s+a,s=s&s}return Math.abs(s)}function ss(e){return Dt[qs(e)%Dt.length]}function Xs(e){return ss(e).emoji}function Ks(e){return ss(e).bgColor}const de=({id:e,image:s,size:n=40,className:a,starred:r=!1,shape:i="squircle",dmAgentEnabled:l=!1})=>{const o=Xs(e),d=Ks(e),u=.45,m=n<32?Math.round(n*u):n<56?14:n<120?18:36,x=n>=40?2:1,c=i==="circle"?{borderRadius:"50%"}:{borderRadius:"1rem"},v=t.jsx("div",{className:"h-full w-full overflow-hidden",style:c,children:s?t.jsx("img",{src:s,alt:"",className:"h-full w-full object-cover"}):t.jsx("div",{"aria-hidden":"true",className:N("avatar-fallback flex h-full w-full items-center justify-center font-semibold select-none transition-colors"),style:{fontSize:m,lineHeight:1},children:o})});return t.jsxs("div",{className:N("relative flex-shrink-0",a),style:{"--str-chat__avatar-size":`${n}px`,width:`${n}px`,height:`${n}px`,backgroundColor:s?void 0:d,...c},children:[r&&t.jsx("div",{"aria-hidden":"true",className:"absolute -left-1.5 -top-1.5 z-10 flex size-5 items-center justify-center rounded-full bg-white shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]",children:t.jsx(C.StarIcon,{className:"size-3 text-yellow-600",weight:"duotone"})}),t.jsx("div",{"data-testid":"avatar-ring",className:N("h-full w-full","bg-transparent"),style:{...c,...l&&{borderWidth:`${x}px`,borderStyle:"solid",borderColor:"var(--AI-Gradient, #7F22FE)",boxShadow:"inset 0 1px 2px 0 rgba(255, 255, 255, 0.5)"}},children:v})]})},Zs="https://linktr.ee/s/about/trust-center/report",Js=({channel:e,participant:s,showBlockParticipant:n=!0,enabled:a=!0,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:l,onBlockParticipantClick:o,onReportParticipantClick:d,onActionComplete:u,logLabel:f="useChannelModerationActions"})=>{var D;const{service:m,debug:x}=We(),c=(D=s==null?void 0:s.user)==null?void 0:D.id,v=!!(a&&n&&m&&c),[j,p]=h.useState(!1),[g,b]=h.useState(null),[y,_]=h.useState(!1),[R,L]=h.useState(!1),I=v&&((g==null?void 0:g.participantId)!==c||(g==null?void 0:g.service)!==m);return h.useEffect(()=>{if(!v||!m||!c){p(!1),b(null);return}let E=!1;return(async()=>{try{const k=await m.getBlockedUsers();if(E)return;p(k.some(A=>A.blocked_user_id===c))}catch(k){E||console.error(`[${f}] Failed to check blocked status:`,k)}finally{E||b({participantId:c,service:m})}})(),()=>{E=!0}},[v,m,c,f]),{isParticipantBlocked:j,isCheckingBlockedStatus:I,isLeaving:y,isUpdatingBlockStatus:R,handleLeaveConversation:async()=>{var E;if(!y){l==null||l(),x&&console.log(`[${f}] Leave conversation`,e.cid),_(!0);try{const k=((E=e._client)==null?void 0:E.userID)??null;await e.hide(k,!1),r&&await r(e),u==null||u()}catch(k){console.error(`[${f}] Failed to leave conversation`,k)}finally{_(!1)}}},handleBlockUser:async()=>{var E,k,A;if(!(R||!m)){o==null||o(),x&&console.log(`[${f}] Block member`,(E=s==null?void 0:s.user)==null?void 0:E.id),L(!0);try{await m.blockUser((k=s==null?void 0:s.user)==null?void 0:k.id),i&&await i((A=s==null?void 0:s.user)==null?void 0:A.id),u==null||u()}catch(O){console.error(`[${f}] Failed to block member`,O)}finally{L(!1)}}},handleUnblockUser:async()=>{var E,k,A;if(!(R||!m)){o==null||o(),x&&console.log(`[${f}] Unblock member`,(E=s==null?void 0:s.user)==null?void 0:E.id),L(!0);try{await m.unBlockUser((k=s==null?void 0:s.user)==null?void 0:k.id),i&&await i((A=s==null?void 0:s.user)==null?void 0:A.id),u==null||u()}catch(O){console.error(`[${f}] Failed to unblock member`,O)}finally{L(!1)}}},handleReportUser:()=>{d==null||d(),u==null||u(),window.open(Zs,"_blank","noopener,noreferrer")}}},he=({variant:e="default",className:s,children:n,...a})=>{const r=e==="danger";return t.jsx("button",{type:"button",className:N("flex w-full items-center gap-3 rounded-lg px-4 py-3 text-left text-sm transition-colors focus-ring disabled:cursor-not-allowed disabled:opacity-60",r?"text-danger hover:bg-danger/50":"text-charcoal hover:bg-sand",s),...a,children:n})},Qs=({channel:e,participant:s,showDeleteConversation:n=!0,showBlockParticipant:a=!0,showReportParticipant:r=!0,onLeaveConversation:i,onBlockParticipant:l,onDeleteConversationClick:o,onBlockParticipantClick:d,onReportParticipantClick:u,customChannelActions:f,triggerClassName:m})=>{const[x,c]=h.useState(!1),v=h.useRef(null),j=h.useId(),p=h.useCallback(()=>c(!1),[]),{isParticipantBlocked:g,isCheckingBlockedStatus:b,isLeaving:y,isUpdatingBlockStatus:_,handleLeaveConversation:R,handleBlockUser:L,handleUnblockUser:I,handleReportUser:z}=Js({channel:e,participant:s,showBlockParticipant:a,enabled:x,onLeaveConversation:i,onBlockParticipant:l,onDeleteConversationClick:o,onBlockParticipantClick:d,onReportParticipantClick:u,onActionComplete:p,logLabel:"ChannelActionsMenu"});return h.useEffect(()=>{if(!x)return;const M=D=>{v.current&&!v.current.contains(D.target)&&c(!1)},T=D=>{D.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",M),document.addEventListener("keydown",T),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",T)}},[x]),!s||!(n||a||r||!!f)?null:t.jsxs("div",{ref:v,className:"relative",children:[t.jsxs("button",{className:m,type:"button","aria-haspopup":"true","aria-expanded":x,"aria-controls":x?j:void 0,onClick:()=>c(M=>!M),children:[t.jsx(C.DotsThreeIcon,{className:"size-5 text-black/90"}),t.jsx("span",{className:"sr-only",children:"More options"})]}),x&&t.jsx("div",{id:j,"aria-label":"Conversation options",className:N("absolute right-0 top-full z-50 mt-2 w-56 overflow-hidden","rounded-lg border border-sand bg-white p-1 shadow-max-elevation-light"),children:t.jsxs("ul",{className:"flex flex-col gap-1",children:[n&&t.jsx("li",{children:t.jsxs(he,{onClick:R,disabled:y,"aria-busy":y,children:[y?t.jsx(C.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(C.SignOutIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Delete Conversation"})]})}),a&&t.jsx("li",{children:b?t.jsxs(he,{disabled:!0,"aria-busy":!0,children:[t.jsx(C.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}),t.jsx("span",{children:"Block"})]}):g?t.jsxs(he,{onClick:I,disabled:_,"aria-busy":_,children:[_?t.jsx(C.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(C.ProhibitInsetIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Unblock"})]}):t.jsxs(he,{onClick:L,disabled:_,"aria-busy":_,children:[_?t.jsx(C.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(C.ProhibitInsetIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Block"})]})}),r&&t.jsx("li",{children:t.jsxs(he,{variant:"danger",onClick:z,children:[t.jsx(C.FlagIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Report"})]})}),f]})})]})},ze="flex size-10 flex-shrink-0 items-center justify-center rounded-full bg-white/65 shadow-[0px_4px_8px_0px_rgba(0,0,0,0.06),0px_0px_0px_1px_rgba(0,0,0,0.04)] backdrop-blur-[40px] transition-filter duration-150 hover:brightness-95 aria-expanded:brightness-95 focus-ring",en="CUSTOMER_PAID",tn=e=>typeof e=="string"&&e.trim().replace(/[\s-]+/g,"_").toUpperCase()===en,sn=({className:e,onBack:s,showBackButton:n,showStarButton:a=!1,onLeaveConversation:r,onBlockParticipant:i,showDeleteConversation:l=!0,showBlockParticipant:o=!0,showReportParticipant:d=!0,onDeleteConversationClick:u,onBlockParticipantClick:f,onReportParticipantClick:m,customChannelActions:x,renderChannelActions:c,showChannelInfo:v=!0,onParticipantNameClick:j})=>{var T,D,E,k;const{channel:p}=w.useChannelStateContext(),{client:g}=w.useChatContext(),b=h.useMemo(()=>{var A;return qe((A=p.state)==null?void 0:A.members,g==null?void 0:g.userID,p.type)},[(T=p.state)==null?void 0:T.members,g==null?void 0:g.userID,p.type]),y=Xe(b==null?void 0:b.user),_=(D=b==null?void 0:b.user)==null?void 0:D.image,R=es(p),L=tn((E=p.data)==null?void 0:E.customer_tag)&&(b==null?void 0:b.is_follower)===!0,I=a&&R,z=L||I||!!j,F=async()=>{try{R?await p.unpin():await p.pin()}catch(A){console.error("[ChannelHeaderRedesign] Failed to update pinned status:",A)}},M=t.jsxs(t.Fragment,{children:[t.jsx(de,{id:((k=b==null?void 0:b.user)==null?void 0:k.id)||p.id||"unknown",name:y,image:_,shape:"circle",size:48,className:"-mb-2"}),t.jsx("span",{className:N("relative z-10 flex max-w-full flex-col items-center justify-center rounded-full border border-white/10 bg-white/65 py-1.5 shadow-[0px_0px_0px_0px_rgba(0,0,0,0.04),0px_1px_2px_0px_rgba(0,0,0,0.04),0px_8px_32px_0px_rgba(0,0,0,0.1)] backdrop-blur-[2px] transition-filter duration-150 group-hover:brightness-95",z?"pl-3 pr-2":"px-3"),children:t.jsxs("span",{className:"flex max-w-full items-center justify-center",children:[t.jsx("span",{className:"min-w-0 truncate text-sm font-bold leading-[1.43] tracking-[0.28px] text-black/90",children:y}),z&&t.jsxs("span",{className:"ml-2 flex gap-1",children:[L&&t.jsx("span",{"aria-label":"Paid customer",className:"flex size-4 shrink-0 items-center justify-center rounded-full bg-[#34C759] text-white",children:t.jsx(C.CurrencyDollarIcon,{className:"size-2.5",weight:"bold"})}),I&&t.jsx("span",{className:"messaging-header-star-badge flex overflow-hidden",children:t.jsx("span",{"aria-label":"Starred conversation",className:"flex size-4 shrink-0 items-center justify-center rounded-full bg-[#FFD60A] text-white",children:t.jsx(C.StarIcon,{className:"size-2.5",weight:"fill"})})}),j&&t.jsx(C.CaretRightIcon,{"aria-hidden":"true",className:"size-4 shrink-0 text-black/65",weight:"bold"})]})]})})]});return t.jsx("div",{className:N("@container bg-[linear-gradient(180deg,#FBFAF9_0%,rgba(251,250,249,0.92)_58%,rgba(251,250,249,0)_100%)]",e),children:t.jsxs("div",{className:"grid min-h-[100px] grid-cols-[minmax(40px,1fr)_auto_minmax(40px,1fr)] items-start pb-2 pt-5 @lg:min-h-[104px] @lg:pt-6",children:[t.jsx("div",{className:"flex items-start",children:n&&t.jsx("button",{className:N(ze,"messaging-channel-view-back-button-mobile messaging-channel-view-back-button-desktop"),onClick:s||(()=>{}),type:"button","aria-label":"Back to conversations",children:t.jsx(C.ArrowLeftIcon,{className:"size-5 text-black/90"})})}),t.jsx("div",{className:"flex min-w-0 justify-center","data-dd-privacy":"mask",children:j?t.jsx("button",{type:"button",onClick:j,"aria-label":`View details for ${y}`,className:"group flex min-w-0 max-w-full appearance-none flex-col items-center border-0 bg-transparent px-2 focus-ring focus-visible:outline-none",children:M}):t.jsx("div",{className:"flex min-w-0 max-w-full flex-col items-center px-2",children:M})}),t.jsxs("div",{className:"flex items-start justify-end gap-2",children:[a&&t.jsx("button",{className:ze,onClick:F,type:"button","aria-pressed":R,"aria-label":R?"Unstar conversation":"Star conversation",children:t.jsx(C.StarIcon,{className:N("size-5",{"text-[#FFD60A]":R,"text-black/90":!R}),weight:R?"fill":"regular"})}),v&&(c!==void 0?c:t.jsx(Qs,{channel:p,participant:b,showDeleteConversation:l,showBlockParticipant:o,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:u,onBlockParticipantClick:f,onReportParticipantClick:m,customChannelActions:x,triggerClassName:ze}))]})]})})},nn=e=>t.jsx(w.DateSeparator,{...e,position:"center"});function ns(e){return(e==null?void 0:e.trim().toLowerCase().split(/[-_]/)[0])||void 0}function Ke({message:e,viewerLanguage:s}){var r;const n=e==null?void 0:e.text,a=ns(s);return a?((r=e==null?void 0:e.i18n)==null?void 0:r[`${a}_text`])??n:n}const an=["linktr.ee"],Pt="messaging-attachment-v1_0";function rn(e){try{return new URL(e).hostname.toLowerCase()}catch{return null}}function on(e){return an.some(s=>e===s||e.endsWith(`.${s}`))}function se(e){const s=e==null?void 0:e.trim();if(!s)return;const n=rn(s);if(!n||!on(n))return s;const a=new URL(s);return a.searchParams.get("io")==="true"&&a.searchParams.get("size")===Pt?s:(a.searchParams.set("io","true"),a.searchParams.set("size",Pt),a.toString())}const ln=[[/pdf/,"pdf"],[/wordprocessingml|msword|\.doc/,"doc"],[/spreadsheetml|ms-excel|\.xls/,"xls"],[/csv/,"csv"],[/presentationml|ms-powerpoint|\.ppt/,"ppt"],[/zip|x-rar|x-7z|x-tar|x-gzip/,"zip"],[/plain|rtf/,"text"],[/markdown/,"markdown"]];function ae(e){return e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":e.startsWith("image/")?"image":"document"}function as(e){const s=ln.find(([n])=>n.test(e));return s?s[1]:"generic"}const cn={video:C.VideoCameraIcon,audio:C.SpeakerHighIcon,image:C.ImageIcon,document:C.FileIcon},dn={pdf:C.FilePdfIcon,doc:C.FileDocIcon,xls:C.FileXlsIcon,csv:C.FileCsvIcon,ppt:C.FilePptIcon,zip:C.FileZipIcon,text:C.FileTextIcon,markdown:C.FileMdIcon,generic:C.FileIcon};function un(e){const s=ae(e);return s!=="document"?cn[s]:dn[as(e)]}function ce(e,s){return h.createElement(un(e),s)}const mn=e=>{var s,n;return"touches"in e?((s=e.touches[0])==null?void 0:s.clientX)??((n=e.changedTouches[0])==null?void 0:n.clientX)??0:e.clientX},hn=({source:e,mimeType:s,poster:n,autoPlay:a=!1,playing:r,loop:i=!1,controls:l=!0,showProgress:o=!1,muted:d=!1,onContainerClick:u})=>{const f=ae(s),m=h.useRef(null),x=h.useRef(null),c=h.useRef(null),v=h.useRef(r),[j,p]=h.useState(a),[g,b]=h.useState(0),[y,_]=h.useState(!1),[R,L]=h.useState(!1),[I,z]=h.useState(!1),[F,M]=h.useState(!1),[T,D]=h.useState(!0),[E,k]=h.useState(null),A=h.useCallback(()=>{z(!1),p(!0)},[]),O=h.useCallback(S=>{const P=x.current;if(!P)return 0;const G=P.getBoundingClientRect();return Math.max(0,Math.min(1,(mn(S)-G.left)/G.width))},[]),B=h.useCallback(S=>{const P=m.current;P&&P.duration&&(P.currentTime=S*P.duration)},[]),H=S=>{S.stopPropagation(),_(!0);const P=O(S);b(P),B(P)},Z=h.useCallback(S=>{S.key==="ArrowRight"&&B(Math.min(1,g+.05)),S.key==="ArrowLeft"&&B(Math.max(0,g-.05))},[B,g]);h.useEffect(()=>{r!==void 0&&r!==v.current&&(v.current=r,p(r))},[r]),h.useEffect(()=>{if(!j){c.current!==null&&(cancelAnimationFrame(c.current),c.current=null);return}const S=()=>{const P=m.current;P&&P.duration&&!y&&b(P.currentTime/P.duration),c.current=requestAnimationFrame(S)};return c.current=requestAnimationFrame(S),()=>{c.current!==null&&cancelAnimationFrame(c.current)}},[j,y]),h.useEffect(()=>{const S=m.current;S&&(j?S.play().catch(P=>{p(!1),z(!0)}):S.pause())},[j]),h.useEffect(()=>{if(!y)return;const S=G=>b(O(G)),P=G=>{_(!1),B(O(G))};return window.addEventListener("mousemove",S),window.addEventListener("mouseup",P),window.addEventListener("touchmove",S,{passive:!0}),window.addEventListener("touchend",P),()=>{window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",P),window.removeEventListener("touchmove",S),window.removeEventListener("touchend",P)}},[y,O,B]);const q=E?{aspectRatio:String(E)}:void 0,X=E?"":" aspect-video",U=Math.round(g*100);return t.jsxs("div",{role:"button",tabIndex:0,className:`relative cursor-pointer overflow-hidden bg-black ${X}`,style:q,onClick:S=>{if(u){u(S);return}I||l&&p(P=>!P)},onKeyDown:S=>{if(!(S.key!=="Enter"&&S.key!==" ")){if(S.preventDefault(),u){u(S);return}I||l&&p(P=>!P)}},children:[n&&(f==="audio"||T)&&t.jsx("img",{src:n,alt:"",className:"absolute inset-0 h-full w-full object-cover"}),!n&&(f==="audio"||T)&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:ce(s,{className:"size-12 text-black/20",weight:"regular"})}),t.jsx("div",{className:"absolute inset-0",children:f==="audio"?t.jsx("audio",{ref:m,src:e,loop:i,muted:d,style:{width:"100%",height:"100%"},onLoadStart:()=>M(!0),onCanPlay:()=>{M(!1),D(!1)},onWaiting:()=>M(!0),onPlay:()=>z(!1),onEnded:()=>{i||(p(!1),b(0))},children:t.jsx("track",{kind:"captions"})}):t.jsx("video",{ref:m,src:e,loop:i,muted:d,playsInline:!0,style:{width:"100%",height:"100%"},onLoadStart:()=>M(!0),onCanPlay:()=>{M(!1),D(!1)},onWaiting:()=>M(!0),onPlay:()=>z(!1),onLoadedMetadata:()=>{const S=m.current;S instanceof HTMLVideoElement&&S.videoWidth&&S.videoHeight&&k(S.videoWidth/S.videoHeight)},onEnded:()=>{i||(p(!1),b(0))},children:t.jsx("track",{kind:"captions"})})}),F&&!I&&t.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center",children:t.jsx(C.CircleNotchIcon,{className:"size-8 animate-spin text-white/80",weight:"bold"})}),I&&!l&&t.jsx("div",{className:"absolute inset-0 z-30 flex cursor-pointer items-center justify-center bg-black/35",role:"button",tabIndex:0,"aria-label":"Play preview",onClick:S=>{S.stopPropagation(),A()},onKeyDown:S=>{S.key!=="Enter"&&S.key!==" "||(S.preventDefault(),S.stopPropagation(),A())},children:t.jsx("span",{className:"flex size-16 items-center justify-center rounded-full bg-white/20 text-white backdrop-blur-sm",children:t.jsx(C.PlayIcon,{className:"size-9 translate-x-0.5",weight:"fill"})})}),o&&!l&&t.jsx("div",{className:"absolute inset-x-0 bottom-0 px-3 pb-2.5 pt-6 bg-gradient-to-t from-black/40 to-transparent",children:t.jsx("div",{role:"slider","aria-label":"Playback position","aria-valuenow":U,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,ref:x,className:"relative flex h-4 w-full cursor-pointer items-center",onMouseDown:H,onTouchStart:H,onClick:S=>S.stopPropagation(),onKeyDown:Z,children:t.jsx("div",{className:"w-full overflow-hidden rounded-full bg-white/30 h-1",children:t.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${U}%`}})})})}),l&&t.jsxs("div",{className:"absolute inset-x-0 bottom-0 flex items-center gap-2 bg-gradient-to-t from-black/60 to-transparent px-3 pb-2.5 pt-6 transition-all duration-200",children:[t.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),p(P=>!P)},className:"shrink-0 text-white","aria-label":j?"Pause":"Play",children:j?t.jsx(C.PauseIcon,{className:"size-5",weight:"fill"}):t.jsx(C.PlayIcon,{className:"size-5 translate-x-px",weight:"fill"})}),t.jsxs("div",{role:"slider","aria-label":"Playback position","aria-valuenow":U,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,ref:x,className:"relative flex h-4 w-full cursor-pointer items-center",onMouseDown:H,onTouchStart:H,onClick:S=>S.stopPropagation(),onMouseEnter:()=>L(!0),onMouseLeave:()=>L(!1),onKeyDown:Z,children:[t.jsx("div",{className:`w-full overflow-hidden rounded-full bg-white/30 transition-all duration-200 ${R||y?"h-1.5":"h-1"}`,children:t.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${U}%`}})}),t.jsx("div",{className:`absolute size-3 -translate-x-1/2 rounded-full bg-white shadow transition-[opacity,transform] duration-200 ${R||y?"scale-100 opacity-100":"scale-0 opacity-0"}`,style:{left:`${U}%`}})]})]})]})},Ot=e=>e==="dark"?"size-12 text-white/20":"size-12 text-black/20",fn=e=>e==="dark"?"aspect-video overflow-hidden bg-white/10":"aspect-video overflow-hidden bg-black/5",Ze=({mimeType:e,sourceUrl:s,thumbnailUrl:n,title:a,variant:r,mediaPlayerProps:i,containedImage:l=!1})=>{const o=ae(e),[d,u]=h.useState(!1),f=se(s),m=se(n);return s&&(o==="video"||o==="audio")?t.jsx(hn,{source:s,mimeType:e,poster:m,controls:!0,...i}):s&&o==="image"?l?t.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:t.jsx("img",{src:f??s,alt:a??"",className:`absolute inset-0 h-full w-full object-contain transition-opacity duration-300 ${d?"opacity-100":"opacity-0"}`,draggable:!1,onLoad:()=>u(!0)})}):t.jsx("img",{src:f??s,alt:a??"",className:"block w-full",draggable:!1}):s&&o==="document"?n?l?t.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:t.jsx("img",{src:m??n,alt:a??"",className:`absolute inset-0 h-full w-full object-contain transition-opacity duration-300 ${d?"opacity-100":"opacity-0"}`,draggable:!1,onLoad:()=>u(!0)})}):t.jsx("img",{src:m??n,alt:"",className:"block w-full",draggable:!1}):t.jsx("div",{className:`flex aspect-video w-full items-center justify-center ${r==="dark"?"bg-white/10":"bg-black/5"}`,children:ce(e,{className:Ot(r),weight:"regular"})}):n?t.jsx("div",{className:`relative ${fn(r)}`,children:t.jsx("img",{src:m??n,alt:a??"",draggable:!1,className:"absolute inset-0 h-full w-full object-cover"})}):t.jsx("div",{className:`flex aspect-video w-full items-center justify-center ${r==="dark"?"bg-white/10":"bg-black/5"}`,children:ce(e,{className:Ot(r),weight:"regular"})})},rs=({variant:e,thumbnail:s,title:n,placeholderTitle:a="Attachment title",mimeType:r,detail:i,statusBadge:l,action:o,topLeft:d,topRight:u,rootRef:f,"data-testid":m})=>{const x=e==="dark",c=x?n??a:n??"",v=x&&!n;return t.jsxs("div",{ref:f,"data-testid":m,className:N("relative w-[280px] select-none overflow-hidden rounded-[24px] shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]",x?"bg-[#1e2330]":"bg-white"),children:[d?t.jsx("div",{className:"pointer-events-auto absolute left-3 top-3 z-50",children:d}):null,u?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-50",children:u}):null,s,t.jsxs("div",{className:"px-4 pb-3 pt-3",children:[c.trim()!==""&&t.jsx("p",{className:N("mb-0.5 truncate text-base font-medium",{"text-black":!x,"text-white/30":x&&v,"text-white":x&&!v}),children:c}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[ce(r,{className:N("size-5 shrink-0",x?"text-white/55":"text-black/55"),weight:"regular"}),i!=null&&i!==""&&t.jsx("span",{className:N("text-xs font-medium",x?"text-white/55":"text-black/55"),children:i}),l]}),o]})]})};function is(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Je(e){return`w-[280px] select-none overflow-hidden rounded-[24px] ${e?"bg-[#1e2330]":"bg-[#F3F3F1]"} shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]`}function xn(e){return e?"bg-white/10":"bg-black/5"}function gn(e){return e?"text-white":"text-black"}function pn(e){return e?"text-white/55":"text-black/55"}function bn(e){return e?"text-white/40":"text-black/40"}function vn(e){return e?"text-white/20":"text-black/20"}const Qe=({attachment:e,isMyMessage:s})=>{const{title:n,text:a,image_url:r,og_scrape_url:i,title_link:l}=e,o=i??l,d=typeof o=="string"&&o.trim()!==""?o:void 0,u=t.jsxs(h.Fragment,{children:[t.jsx("div",{className:"p-2",children:r?t.jsx("img",{src:se(r)??r,alt:n??"",className:"aspect-video w-full rounded-[20px] object-cover"}):t.jsx("div",{className:`aspect-video w-full rounded-[20px] ${xn(s)} flex items-center justify-center`,children:t.jsx(C.LinkIcon,{className:`size-12 ${vn(s)}`})})}),t.jsxs("div",{className:"px-3 pb-3",children:[n&&t.jsx("p",{className:`truncate text-[14px] font-medium leading-5 ${gn(s)}`,children:n}),a&&t.jsx("p",{className:`truncate text-[12px] leading-4 ${pn(s)}`,children:a}),d&&t.jsx("p",{className:`mt-1 truncate text-[12px] leading-4 ${bn(s)}`,children:d})]})]});return d?t.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"block no-underline",children:u}):t.jsx("div",{className:"block",children:u})};function je(e){var s;return e.type==="link"||!!((s=e.og_scrape_url)!=null&&s.trim())&&!e.asset_url}function Me(e){var s;return(s=e.attachments)==null?void 0:s.find(je)}async function jn(e,s){let n;try{n=s??new URL(e).pathname.split("/").pop()??"download"}catch{n=s??"download"}const a=await fetch(e,{mode:"cors"});if(!a.ok)throw new Error(`HTTP ${a.status}`);const r=await a.blob(),i=URL.createObjectURL(r),l=document.createElement("a");l.href=i,l.download=n,l.style.display="none",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(i)}const wn=({url:e,filename:s})=>{const[n,a]=h.useState(!1),r=i=>{i.stopPropagation();const l=window.open("","_blank","noopener,noreferrer");a(!0),jn(e,s).then(()=>{l==null||l.close()}).catch(()=>{l&&(l.location.href=e)}).finally(()=>a(!1))};return t.jsx("button",{type:"button",onClick:r,disabled:n,className:"mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full bg-[#121110] px-4 text-sm font-medium leading-none text-white hover:bg-[#2a2928] disabled:opacity-70",children:n?t.jsx(C.CircleNotchIcon,{className:"size-4 animate-spin text-white",weight:"bold"}):t.jsxs(h.Fragment,{children:[t.jsx(C.DownloadSimpleIcon,{className:"size-4 text-white",weight:"bold"}),"Download"]})})};function Le(e){var m,x,c,v;const s=(m=e.attachments)==null?void 0:m.find(j=>j.type==="video"&&j.asset_url),n=(x=e.attachments)==null?void 0:x.find(j=>j.type==="image"&&j.image_url),a=(c=e.attachments)==null?void 0:c.find(j=>j.type==="audio"&&j.asset_url),r=(v=e.attachments)==null?void 0:v.find(j=>j.type==="file"&&j.asset_url),i=s??n??a??r,l=(s==null?void 0:s.asset_url)??(n==null?void 0:n.image_url)??(a==null?void 0:a.asset_url)??(r==null?void 0:r.asset_url);if(!l)return null;const o=(i==null?void 0:i.mime_type)??((i==null?void 0:i.type)==="image"?"image/jpeg":(i==null?void 0:i.type)==="video"?"video/mp4":(i==null?void 0:i.type)==="audio"?"audio/mpeg":"application/octet-stream"),d=i==null?void 0:i.title,u=i==null?void 0:i.file_size,f=s==null?void 0:s.thumb_url;return{resolvedUrl:l,resolvedType:o,title:d,fileSize:u,thumbnailUrl:f}}const os=({resolvedUrl:e,resolvedType:s,title:n,fileSize:a,thumbnailUrl:r})=>{const i=a!==void 0?is(a):void 0;return t.jsx(rs,{variant:"dark",title:n,placeholderTitle:"",mimeType:s,detail:i,thumbnail:t.jsx(Ze,{mimeType:s,sourceUrl:e,thumbnailUrl:r,title:n,variant:"dark"})})},ls=({resolvedUrl:e,resolvedType:s,title:n,fileSize:a,thumbnailUrl:r})=>{const i=ae(s),l=a!==void 0?is(a):void 0;return t.jsx(rs,{variant:"light",title:n,mimeType:s,detail:l,thumbnail:t.jsx(Ze,{mimeType:s,sourceUrl:e,thumbnailUrl:r,title:n,variant:"light",containedImage:i==="image"||i==="document"}),action:t.jsx(wn,{url:e,filename:n})})},_n=({message:e,isMyMessage:s=!1})=>{const n=Me(e),a=Le(e);if(!n&&!a)return null;const r=s?"str-chat__message str-chat__message-simple str-chat__message--me str-chat__message-simple--me":"str-chat__message str-chat__message-simple str-chat__message--other";return t.jsxs("div",{className:r,"data-dd-privacy":"mask",children:[!s&&e.user&&t.jsx(de,{className:"str-chat__avatar str-chat__message-sender-avatar",id:e.user.id,image:e.user.image,name:e.user.name??e.user.id}),t.jsx("div",{className:"str-chat__message-inner",style:{marginInlineEnd:0,marginInlineStart:0},children:t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsx("div",{className:"str-chat__message-bubble","data-attachment-bubble":"true",style:{padding:0,borderRadius:0,overflow:"visible",background:"transparent"},children:n?t.jsx("div",{className:Je(s),children:t.jsx(Qe,{attachment:n,isMyMessage:s})}):s?t.jsx(os,{...a}):t.jsx(ls,{...a})})})})]})},yn=({message:e})=>{const s=Me(e);if(s)return t.jsx("div",{className:Je(!0),"data-dd-privacy":"mask",children:t.jsx(Qe,{attachment:s,isMyMessage:!0})});const n=Le(e);return n?t.jsx("div",{style:{display:"contents"},"data-dd-privacy":"mask",children:t.jsx(os,{...n})}):null},Nn=({message:e})=>{const s=Me(e);if(s)return t.jsx("div",{className:Je(!1),"data-dd-privacy":"mask",children:t.jsx(Qe,{attachment:s,isMyMessage:!1})});const n=Le(e);return n?t.jsx("div",{style:{display:"contents"},"data-dd-privacy":"mask",children:t.jsx(ls,{...n})}):null},Cn=Object.assign(_n,{Creator:yn,Visitor:Nn}),Sn={isUnlocking:()=>!1},kn={LockedAttachment:Sn},cs=h.createContext({}),En=cs.Provider;function ds(e){return h.useContext(cs)[e]??kn[e]}const In=h.lazy(()=>Promise.resolve().then(()=>require("./Card-Be81K6su.cjs"))),Tn=h.lazy(()=>Promise.resolve().then(()=>require("./Card-DcBZqMBt.cjs"))),Rn=()=>t.jsx("div",{className:"w-[280px] min-h-[200px] animate-pulse rounded-md bg-black/[0.06] shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_1px_2px_rgba(0,0,0,0.04),0_8px_32px_rgba(0,0,0,0.1)]","aria-hidden":!0}),ge=e=>t.jsx(h.Suspense,{fallback:t.jsx(Rn,{}),children:e.contentType==="text"?t.jsx(In,{...e}):t.jsx(Tn,{...e})}),An=({size:e=15})=>t.jsx("svg",{width:e,height:e,viewBox:"0 0 15 15",fill:"none","aria-hidden":"true",children:t.jsx("path",{d:"M12.003 9a.985.985 0 0 1-.652.934l-3.223 1.191-1.188 3.226a.995.995 0 0 1-1.867 0l-1.195-3.226L.65 9.937a.995.995 0 0 1 0-1.867l3.227-1.195 1.187-3.226a.995.995 0 0 1 1.868 0l1.195 3.226 3.226 1.187a.99.99 0 0 1 .649.938m3-5.83a.52.52 0 0 1-.344.492l-1.702.63-.627 1.703a.525.525 0 0 1-.986 0l-.63-1.704-1.704-.627a.525.525 0 0 1 0-.986l1.703-.63.627-1.704a.526.526 0 0 1 .986 0l.631 1.703 1.704.627a.52.52 0 0 1 .342.495",fill:"currentColor",fillOpacity:.55})}),us=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)===Y.MESSAGE_CUSTOM_TYPE.TIP},ms=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)===Y.MESSAGE_CUSTOM_TYPE.PAID},Ee=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)===Y.MESSAGE_CUSTOM_TYPE.CHATBOT},et=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)===Y.MESSAGE_CUSTOM_TYPE.ATTACHMENT},Mn=e=>{var s;return et(e)&&((s=e.metadata)==null?void 0:s.attachment_content_type)==="text"},Ln=e=>{var s;return et(e)&&((s=e.metadata)==null?void 0:s.attachment_content_type)!=="text"},tt=e=>us(e)||ms(e),Dn=e=>{var s;return tt(e)&&!hs(e)&&!!((s=e.metadata)!=null&&s.amount_text)},hs=e=>{var s;return tt(e)&&!((s=e.text)!=null&&s.trim())},Be=({message:e,standalone:s=!1,isMyMessage:n=!1,hasAttachment:a=!1})=>{var x;const r=tt(e),i=Ee(e);if(!r&&!i)return null;if(r){const c=(x=e.metadata)==null?void 0:x.amount_text;if(!c)return null;const v=s?"message-tip-standalone inline-flex items-center gap-1.5 px-3.5 py-2.5 rounded-[18px] text-[14px] font-medium text-[#016e1a] bg-[#dbf0e0]":"message-tag--tip inline-flex items-center gap-1 text-[12px] leading-[2] font-medium text-[#016630]",j=ms(e)?"message":"tip",p=s?`${c} ${j}`:`Delivered with ${c} ${j}`;return t.jsxs("div",{className:v,children:[t.jsx(C.GiftIcon,{size:s?14:12}),t.jsx("span",{children:p})]})}const l=n&&a,o=l?"Sent with AI":"Sent by AI Assistant",d="inline-flex items-center text-[10px] font-normal leading-4 tracking-[0.2px]",u=l?"justify-end gap-2 text-black/30":n?"w-full justify-start gap-1.5 mt-3 px-4 text-white/55":"w-full justify-start gap-1.5 mt-3 px-4 text-black/30",f=t.jsx("span",{className:"text-left",children:o}),m=t.jsx("span",{className:"inline-flex items-center leading-none",children:t.jsx(An,{size:l?12:15})});return t.jsx("div",{className:`${d} ${u}`,"data-testid":"message-chatbot-indicator",children:n&&!l?t.jsxs(t.Fragment,{children:[f,m]}):t.jsxs(t.Fragment,{children:[m,f]})})},Ft=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='23' fill='none'%3E%3Cpath fill='black' d='M0 0H15C15 10.1934 15.859 15.2345 19.168 21.4893C19.527 22.168 19.039 22.9917 18.274 22.9178C5.176 21.6506 0.32 6.0737 0 0Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%`,Pn={me:"var(--str-chat__own-message-bubble-background-color, #1e2330)",other:"var(--str-chat__message-bubble-background-color, #f1f0ee)"},Ie=({side:e})=>t.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute bottom-0 z-[-1] h-[1.4375rem] w-5",style:{insetInlineEnd:e==="me"?"calc(-1 * 0.3125rem)":void 0,insetInlineStart:e==="other"?"calc(-1 * 0.3125rem)":void 0,transform:e==="other"?"scaleX(-1)":void 0,transformOrigin:"center",backgroundColor:Pn[e],WebkitMask:Ft,mask:Ft}}),fs=h.createContext(void 0),On=e=>{var n;const s=(n=e.metadata)==null?void 0:n.outbound_id;return typeof s=="string"?s:void 0},Fn=(e,s)=>{if(!s||!(e!=null&&e.length))return;const n=new Set;let a;for(const r of e){const i=On(r);if(!i||n.has(i))continue;n.add(i);const l=s(i);l&&(a??(a={}),a[i]={id:l.id,...l.name!==void 0?{name:l.name}:{}})}return a},zn=(e,s)=>{if(e===s)return!0;if(!e||!s)return!1;const n=Object.keys(e),a=Object.keys(s);return n.length!==a.length?!1:n.every(r=>{var i,l;return e[r].id===((i=s[r])==null?void 0:i.id)&&e[r].name===((l=s[r])==null?void 0:l.name)})},Bn=(e,s)=>{const n=Fn(e,s),[a,r]=h.useState(n);return zn(a,n)?a:(r(n),n)},st=()=>{const{message:e}=w.useMessageContext("SentMessageDeliveryStatus"),{messages:s}=w.useChannelStateContext("SentMessageDeliveryStatus"),n=(()=>{if(s)for(let a=s.length-1;a>=0;a-=1){const r=s[a];if(!(r.type==="system"||r.type==="ephemeral"||r.type==="deleted"))return r.id}})();return e.id===n},Se=()=>st()?t.jsxs(t.Fragment,{children:[t.jsx(C.ChecksIcon,{weight:"bold","aria-hidden":"true"}),t.jsx("span",{"data-testid":"sent-message-delivery-status",children:"Delivered"})]}):null,$n=()=>st()?t.jsxs(t.Fragment,{children:[t.jsx(C.CircleNotchIcon,{className:"sent-message-status__spinner animate-spin",weight:"bold","aria-hidden":"true"}),t.jsx("span",{"data-testid":"sent-message-sending-status",children:"Sending"})]}):null,Un=({outbound:e,onOutboundClick:s})=>{const n=e.name||"Broadcast",a=!!s,r=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"sent-message-outbound-badge","aria-hidden":"true",children:t.jsx(C.MegaphoneIcon,{weight:"fill"})}),t.jsx("span",{className:N("sent-message-outbound-name",{"underline [text-decoration-skip-ink:auto]":a}),"data-testid":"sent-message-outbound-status",children:n})]});return s?t.jsx("button",{type:"button",className:"inline-flex cursor-pointer items-center gap-1 border-0 bg-transparent p-0 text-inherit [font:inherit]","aria-label":`View broadcast ${n}`,onClick:()=>s(e),children:r}):r},Vn=()=>t.jsxs("span",{className:"str-chat__message-status sent-message-status--failed",children:[t.jsx(C.WarningCircleIcon,{weight:"bold","aria-hidden":"true"}),t.jsx("span",{"data-testid":"sent-message-failed-status",children:"Failed to send"})]}),Hn=({onOutboundClick:e,resolvedOutbound:s})=>{var f;const{isMyMessage:n,message:a,threadList:r}=w.useMessageContext("SentMessageDeliveryStatus"),i=n(),l=st();if(r)return null;if(a.status==="failed"&&i&&a.type!=="error")return t.jsx(Vn,{});if(!i)return null;const o=(f=a.metadata)==null?void 0:f.outbound_id,d=a.status!=="sending"&&a.status!=="failed"&&o&&s?t.jsx(Un,{outbound:s,onOutboundClick:e}):null,u=Dn(a)?null:t.jsx(w.MessageStatus,{MessageSentStatus:Se,MessageDeliveredStatus:Se,MessageReadStatus:Se,MessageSendingStatus:us(a)?Se:$n});return d?t.jsxs("span",{className:"sent-message-status-row",children:[u,u&&l&&t.jsx("span",{className:"sent-message-outbound-separator","aria-hidden":"true",children:"•"}),d]}):u},Gn=/^([a-z][a-z0-9+.-]*):/i,Yn=new Set(["http","https","mailto","tel","sms"]);function nt(e){if(typeof e!="string")return;const s=e.trim();if(s==="")return;const n=Gn.exec(s);if(n){const a=n[1].toLowerCase();return Yn.has(a)?s:void 0}return s.startsWith("//")||s.startsWith("/")?s:`https://${s}`}const Wn={dark:{primary:"bg-white text-[#121110] hover:bg-white/90",secondary:"bg-white/15 text-white hover:bg-white/25"},light:{primary:"bg-[#121110] text-white hover:bg-[#2a2928]",secondary:"bg-black/[0.06] text-[#121110] hover:bg-black/10"}},xs=({variant:e,cta:s,fullWidth:n=!0,standalone:a=!1})=>{const r=s.variant??"primary",i=N("inline-flex h-10 items-center justify-center rounded-full px-4 text-sm font-medium leading-none transition-colors",n?"w-full":"min-w-0",!a&&"mt-2",Wn[e][r]),l=n?s.label:t.jsx("span",{className:"min-w-0 truncate",children:s.label}),o=nt(s.href);return o?t.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",onClick:d=>{var u;d.stopPropagation(),(u=s.onClick)==null||u.call(s)},className:`${i} no-underline`,children:l}):t.jsx("button",{type:"button",onClick:d=>{var u;d.stopPropagation(),(u=s.onClick)==null||u.call(s)},className:i,children:l})},qn={dark:"text-white",light:"text-black/90"},Xn="text-white/30",zt={dark:"text-white/55",light:"text-black/55"},Kn={dark:"bg-white/25",light:"bg-black/15"},at=({variant:e,ctaSurface:s,chinTextColor:n,title:a,placeholderTitle:r,description:i,descriptionLines:l=1,url:o,appIcon:d,cta:u,trailingAction:f,isLoading:m=!1})=>{const x=e==="dark",c=a??(x?r:void 0)??"",v=c.trim()!=="",j=i!=null&&i.trim()!=="",p=typeof o=="string"?o.trim():"",g=p!=="",b=u!=null;if(!m&&!v&&!j&&!g&&!b)return null;const y=x&&!a,_=N("line-clamp-2 text-[14px] font-medium leading-5 tracking-[0.28px]",n==null&&(y?Xn:qn[e])),R=N("truncate text-[12px] leading-4 tracking-[0.24px]",n==null&&zt[e]),L=N("text-[12px] leading-4 tracking-[0.24px]",l<=1&&"truncate",n==null&&zt[e]);if(m){const F=N("animate-pulse rounded",Kn[e]);return t.jsx("div",{className:"shrink-0 px-4 py-3",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-[2px]",children:[t.jsx("div",{className:N("h-5 w-3/4",F),"aria-hidden":!0}),t.jsx("div",{className:N("h-4 w-1/2",F),"aria-hidden":!0})]})})}const I=n?{color:n}:void 0,z=l>1?{...I,display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:l,overflow:"hidden"}:I;return t.jsxs("div",{className:"shrink-0 px-4 py-3",children:[t.jsxs("div",{className:"flex items-end gap-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-[2px]",children:[v&&t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[d?t.jsx("span",{className:"shrink-0",children:d}):null,t.jsx("p",{className:N("min-w-0",_),style:I,children:c})]}),j&&t.jsx("p",{className:L,style:z,children:i}),!b&&g&&t.jsx("p",{className:R,style:I,"data-testid":"link-attachment-url",children:p})]}),f&&t.jsx("div",{className:"shrink-0",children:f})]}),u&&t.jsx(xs,{variant:s??e,cta:u})]})},Zn="Loading link preview",Jn=N("relative w-[var(--lt-msg-card-width,290px)] max-w-full select-none overflow-hidden","rounded-[20px]"),Qn="flex h-[250px] flex-col",be=({variant:e,children:s,href:n,onClick:a,ariaLabel:r,rootRef:i,topRight:l,bgClassName:o,accentHex:d,fixedHeight:u=!1,busy:f=!1,"data-testid":m})=>{const x=n!=null||a!=null,c=N("messaging-link-card",Jn,u?Qn:"block",o??(e==="dark"?"bg-[#1e2330]":"bg-[#f1f0ee]"),x?"cursor-pointer no-underline focus-ring":null),v=f?{role:"status","aria-busy":!0,"aria-label":Zn}:void 0,j=d?{"--accent":d}:void 0,p=l?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-10",children:l}):null;return n?t.jsxs("a",{ref:i,href:n,target:"_blank",rel:"noopener noreferrer",onClick:a,"data-testid":m,"data-variant":e,className:c,style:j,...v,children:[s,p]}):a?t.jsxs("button",{ref:i,type:"button",onClick:a,"aria-label":r,"data-testid":m,"data-variant":e,className:N(c,"text-left"),style:j,...v,children:[s,p]}):t.jsxs("div",{ref:i,"data-testid":m,"data-variant":e,className:c,style:j,...v,children:[s,p]})},Bt={dark:"bg-white/10",light:"bg-black/5"},ea={dark:"size-16 text-white/25",light:"size-16 text-black/25"},we=(e,s)=>!!s&&!!e&&ae(e)==="audio",rt=(e,s)=>{if(!s||!e)return!1;const n=ae(e);return n==="video"||n==="audio"},it="bg-[#F2F3F4]",ve=({variant:e,thumbnailUrl:s,sourceUrl:n,title:a,mimeType:r="image/*",topLeft:i,topRight:l,isLoading:o=!1,onImageError:d})=>{const u=ae(r),f=!!n&&u==="video",m=se(s);return!o&&we(r,n)?t.jsx("div",{className:"p-3",children:t.jsx("audio",{src:n,controls:!0,preload:"metadata",className:"block w-full",children:t.jsx("track",{kind:"captions"})})}):t.jsxs("div",{className:N("relative min-h-0 w-full flex-1 overflow-hidden",f&&"bg-black"),children:[o?t.jsx("div",{className:N("h-full w-full animate-pulse",Bt[e]),"aria-hidden":!0}):f?t.jsxs(t.Fragment,{children:[t.jsx("video",{src:n,poster:m,controls:!0,playsInline:!0,preload:"metadata",className:"absolute inset-0 h-full w-full object-contain",children:t.jsx("track",{kind:"captions"})}),m&&d?t.jsx("img",{src:m,alt:"","aria-hidden":!0,onError:d,className:"hidden"}):null]}):s?t.jsx("img",{src:m??s,alt:a??"",draggable:!1,loading:"lazy",decoding:"async",onError:d,className:"absolute inset-0 h-full w-full object-cover"}):t.jsx("div",{className:N("flex h-full w-full items-center justify-center",Bt[e]),children:ce(r,{className:ea[e],weight:"regular"})}),i?t.jsx("div",{className:"pointer-events-auto absolute left-3 top-3 z-10",children:i}):null,l?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-10",children:l}):null]})},ta=/^#?(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function sa(e){const s=e.trim();return s.startsWith("#")?s:`#${s}`}const na="#FFFFFF",gs="#040403",aa={dark:na,light:gs};function De({variant:e,accentColor:s,status:n="ready",layout:a="featured",thumbnailUrl:r,mimeType:i,sourceUrl:l}){const[o,d]=h.useState(!1);h.useEffect(()=>{d(!1)},[r]);const u=h.useCallback(()=>{d(!0)},[]),f=we(i,l),c=a==="featured"&&!!r&&!f&&!o&&n==="ready"&&s!=null&&ta.test(s.trim())?sa(s):void 0,v=f?gs:aa[e];return{thumbnailUrl:o?void 0:r,accentHex:c,chinTextColor:v,surface:f?"light":e,isLoading:n==="loading",onImageError:u}}const ra="flex size-6 items-center justify-center rounded-full bg-[#121110] text-white focus-ring",ia="relative before:absolute before:-inset-[10px] before:content-['']",oa=({title:e,placeholderTitle:s,description:n,descriptionLines:a,url:r,mimeType:i,thumbnailUrl:l,sourceUrl:o,layout:d="featured",appIcon:u,cta:f,accentColor:m,status:x="ready",onDismiss:c,onEditClick:v,dismissLabel:j="Dismiss attachment"})=>{const p=d==="classic",g=we(i,o),b=De({variant:"dark",accentColor:m,status:x,layout:d,thumbnailUrl:l,mimeType:i,sourceUrl:o}),y=c?t.jsx("button",{type:"button",onClick:c,"aria-label":j,className:N(ra,!g&&ia),children:t.jsx(C.XIcon,{className:"size-3",weight:"bold"})}):void 0,_=v?t.jsx("button",{type:"button",onClick:v,"aria-label":"Edit attachment",className:"flex size-10 items-center justify-center rounded-full bg-white/10 text-white hover:bg-white/15",children:t.jsx(C.PencilSimpleIcon,{className:"size-5",weight:"regular"})}):void 0;return g&&!b.isLoading?t.jsx(be,{variant:"dark",bgClassName:it,children:t.jsxs("div",{className:"flex items-center gap-2 pr-3",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(ve,{variant:"dark",sourceUrl:o,title:e,mimeType:i})}),y&&t.jsx("div",{className:"shrink-0",children:y})]})}):t.jsxs(be,{variant:"dark",fixedHeight:!p,accentHex:b.accentHex,busy:b.isLoading,topRight:p?y:void 0,children:[!p&&t.jsx(ve,{variant:"dark",thumbnailUrl:b.thumbnailUrl,sourceUrl:o,title:e,mimeType:i,topRight:y,isLoading:b.isLoading,onImageError:b.onImageError}),t.jsx(at,{chinTextColor:b.chinTextColor,variant:"dark",ctaSurface:b.surface,title:e,placeholderTitle:s,description:n,descriptionLines:a,url:r,appIcon:u,cta:f,trailingAction:_,isLoading:b.isLoading})]})},ot=({accentHex:e,side:s,visible:n,children:a})=>{if(!n)return t.jsx(t.Fragment,{children:a});const r=s==="sender"?"dark":"light",i=e?{"--accent":e}:void 0;return t.jsxs("div",{className:"relative isolate w-fit",children:[a,t.jsx("span",{"aria-hidden":!0,"data-testid":"link-card-tail","data-variant":r,style:i,className:N("messaging-link-card-tail",s==="receiver"&&"messaging-link-card-tail--received")})]})},la=({title:e,description:s,descriptionLines:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:l,layout:o="featured",appIcon:d,cta:u,accentColor:f,status:m="ready",onClick:x,groupPosition:c="single"})=>{const v=rt(r,l),j=nt(a),p=u==null&&j!=null&&!v?j:void 0,g=u==null&&!v?x:void 0,b=m!=="loading"&&we(r,l)?it:void 0,y=u&&x?{...u,onClick:()=>{var R;x(),(R=u.onClick)==null||R.call(u)}}:u,_=De({variant:"light",accentColor:f,status:m,layout:o,thumbnailUrl:i,mimeType:r,sourceUrl:l});return t.jsx(ot,{accentHex:_.accentHex,side:"receiver",visible:b==null&&(c==="single"||c==="end"),children:t.jsxs(be,{variant:"light",href:p,onClick:g,ariaLabel:e??"Open attachment preview",fixedHeight:o==="featured"&&b==null,accentHex:_.accentHex,busy:_.isLoading,bgClassName:b,"data-testid":"link-attachment",children:[o==="featured"&&t.jsx(ve,{variant:"light",thumbnailUrl:_.thumbnailUrl,sourceUrl:l,title:e,mimeType:r,isLoading:_.isLoading,onImageError:_.onImageError}),t.jsx(at,{chinTextColor:_.chinTextColor,variant:"light",ctaSurface:_.surface,title:e,description:s,descriptionLines:n,url:a,appIcon:d,cta:y,isLoading:_.isLoading})]})})},ca=({title:e,placeholderTitle:s,description:n,descriptionLines:a,url:r,mimeType:i,thumbnailUrl:l,sourceUrl:o,layout:d="featured",appIcon:u,cta:f,accentColor:m,status:x="ready",onClick:c,groupPosition:v="single"})=>{const j=rt(i,o),p=nt(r),g=f==null&&p!=null&&!j?p:void 0,b=f==null&&!j&&g!=null?c:void 0,y=x!=="loading"&&we(i,o),_=De({variant:"dark",accentColor:m,status:x,layout:d,thumbnailUrl:l,mimeType:i,sourceUrl:o});return t.jsx(ot,{accentHex:_.accentHex,side:"sender",visible:!y&&(v==="single"||v==="end"),children:t.jsxs(be,{variant:"dark",href:g,onClick:b,fixedHeight:d==="featured"&&!y,accentHex:_.accentHex,busy:_.isLoading,bgClassName:y?it:void 0,children:[d==="featured"&&t.jsx(ve,{variant:"dark",thumbnailUrl:_.thumbnailUrl,sourceUrl:o,title:e,mimeType:i,isLoading:_.isLoading,onImageError:_.onImageError}),t.jsx(at,{chinTextColor:_.chinTextColor,variant:"dark",ctaSurface:_.surface,title:e,placeholderTitle:s,description:n,descriptionLines:a,url:r,appIcon:u,cta:f,isLoading:_.isLoading})]})})},Te={Composer:oa,Sent:ca,Received:la},da={dark:"bg-[#1e2330]",light:"bg-[#f2f1ef]"},ua={dark:"text-white",light:"text-[#000000]"},ma={dark:"border-white/[0.08]",light:"border-black/[0.08]"},ha=e=>e==="dark"?"sender":"receiver",fa={sender:{single:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]",first:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[4px]",middle:"rounded-tl-[18px] rounded-tr-[4px] rounded-bl-[18px] rounded-br-[4px]",end:"rounded-tl-[18px] rounded-tr-[4px] rounded-bl-[18px] rounded-br-[18px]"},receiver:{single:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]",first:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[4px] rounded-br-[18px]",middle:"rounded-tl-[4px] rounded-tr-[18px] rounded-bl-[4px] rounded-br-[18px]",end:"rounded-tl-[4px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]"}},_e=({variant:e,text:s,bordered:n=!0,groupPosition:a="single",widthClassName:r="w-[280px]",paddingClassName:i="px-2 py-2",radiusClassName:l,className:o,children:d,"data-testid":u})=>{const f=s!=null&&s!=="",m=l??fa[ha(e)][a];return t.jsxs("div",{"data-testid":u,"data-group-position":a,className:N("relative",r,"overflow-hidden",i,f&&"pb-0",m,da[e],ua[e],n&&"border",n&&ma[e],o),children:[d,f?t.jsx("p",{className:N("whitespace-pre-wrap break-words leading-snug hyphens-manual","pb-2 pt-2","px-2"),children:s}):null]})},ye=e=>e==="received"?"light":"dark",xa=({firstOfGroup:e,endOfGroup:s,groupedByUser:n})=>!n||e&&s?"single":e?"first":s?"end":"middle",ga=(e,s)=>`${e}:${s}`;function ps(e){return!Number.isFinite(e)||e<0?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(2)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}const pa={pdf:"PDF",doc:"DOC",xls:"XLS",csv:"CSV",ppt:"PPT",zip:"ZIP",text:"TXT",markdown:"MD"};function bs(e,s){if(s){const r=s.lastIndexOf(".");if(r>0&&r<s.length-1){const i=s.slice(r+1);if(i&&i.length<=5)return i.toUpperCase()}}if(!e)return;if(ae(e)==="document"){const r=as(e),i=pa[r];if(i)return i;if(e==="application/octet-stream")return}const a=e.split("/")[1];if(!(!a||a==="*"))return a.toUpperCase()}function vs(e,s,n){const a=bs(e,s),r=typeof n=="number"&&n>0?ps(n):void 0;return[a,r].filter(Boolean).join(" · ")||void 0}function ne(e){try{const n=new URL(e).pathname.split("/").pop();return n&&n.length>0?decodeURIComponent(n):"download"}catch{return"download"}}async function lt(e,s){const n=s??ne(e);try{const a=await fetch(e,{mode:"cors"});if(!a.ok)throw new Error(`HTTP ${a.status}`);const r=await a.blob(),i=URL.createObjectURL(r),l=document.createElement("a");l.href=i,l.download=n,l.style.display="none",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(i)}catch{if(!window.open(e,"_blank","noopener,noreferrer")){const r=document.createElement("a");r.href=e,r.download=n,r.target="_blank",r.rel="noopener noreferrer",r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)}}}const ba=()=>()=>{},va=()=>!0,ja=()=>!1,wa=()=>h.useSyncExternalStore(ba,va,ja),Ge=35,_a=Object.freeze(new Array(Ge).fill(0)),ya="--:--",$e=e=>w.displayDuration(Math.floor(e)),Na=e=>({canPlayRecord:e.canPlayRecord,isPlaying:e.isPlaying,progressPercent:e.progressPercent,secondsElapsed:e.secondsElapsed}),$t="flex size-8 shrink-0 items-center justify-center rounded-full backdrop-blur-[20px]",Ca={dark:"bg-white text-black/90 disabled:bg-white/40",light:"bg-[#040403]/90 text-white disabled:bg-[#040403]/30"},Sa={dark:"bg-[#040403]/80 text-white hover:bg-[#040403]",light:"bg-black/10 text-black/90 hover:bg-black/20"},ka=(e,s)=>{const[n,a]=h.useState();return h.useEffect(()=>{if(s!=null||!e)return;const r=document.createElement("audio");r.preload="metadata";const i=()=>{Number.isFinite(r.duration)&&r.duration>0&&a(r.duration)};return r.addEventListener("loadedmetadata",i),r.src=e,()=>{r.removeEventListener("loadedmetadata",i),r.removeAttribute("src"),a(void 0)}},[e,s]),s??n},Ea=e=>wa()?t.jsx(Ta,{...e}):t.jsx(js,{...e,playback:Ia}),Ia={playable:!1,showPause:!1,isStarting:!1,progress:0,secondsElapsed:0},Ta=e=>{const{item:s,requester:n}=e,a=h.useRef(null),[r,i]=h.useState(!1),l=ka(s.src,s.durationSeconds),o=w.useAudioPlayer({durationSeconds:l,mimeType:s.mimeType,requester:n,src:s.src,title:s.filename}),{canPlayRecord:d=!1,isPlaying:u=!1,progressPercent:f=0,secondsElapsed:m=0}=w.useStateStore(o==null?void 0:o.state,Na)??{},x=()=>{!o||r||(i(!0),o.togglePlay().finally(()=>i(!1)))},c=v=>{const j=a.current;if(!o||!j)return;const p=Math.min(Math.max(Number(v.target.value)/100,0),1),g=j.getBoundingClientRect();o.seek({clientX:g.x+p*g.width,currentTarget:j})};return t.jsx(js,{...e,playback:{playable:!!o&&d,showPause:u,isStarting:r,progress:Math.min(Math.max(f,0),100),secondsElapsed:m,durationSeconds:l,trackRef:a,onTogglePlay:x,onSeek:c}})},js=({item:e,variant:s,trailingAction:n,playback:a})=>{const{isStarting:r,onSeek:i,onTogglePlay:l,playable:o,progress:d,secondsElapsed:u,showPause:f,trackRef:m}=a,x=h.useMemo(()=>{const g=e.waveformData;return!g||g.length===0?_a:g.length===Ge?g:w.resampleWaveformData(g,Ge)},[e.waveformData]),c=a.durationSeconds??e.durationSeconds,v=c==null?ya:$e(c),j=u>0?$e(u):v,p=e.filename?` — ${e.filename}`:"";return t.jsxs("div",{role:"group","aria-label":e.filename??"Audio attachment",className:"flex items-center","data-testid":"audio-attachment-row",children:[t.jsx("button",{type:"button",onClick:l,disabled:!o,"aria-busy":r||void 0,"aria-label":`${f?"Pause audio":"Play audio"}${p}`,className:N($t,Ca[s]),children:f?t.jsx(C.PauseIcon,{className:"size-3",weight:"fill","aria-hidden":!0}):t.jsx(C.PlayIcon,{className:"size-3",weight:"fill","aria-hidden":!0})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2.5 px-3",children:[t.jsxs("div",{className:N("mes-audio-wave",s==="light"&&"mes-audio-wave--light"),children:[t.jsx("div",{ref:m,className:"mes-audio-wave__track","aria-hidden":!0,children:x.map((g,b)=>t.jsx("span",{"data-testid":"amplitude-bar",className:N("mes-audio-wave__bar",d>b/x.length*100&&"mes-audio-wave__bar--played"),style:{"--mes-audio-wave-bar":`${Math.min(Math.max(g,0),1)*100}%`}},b))}),t.jsx("input",{type:"range",className:"mes-audio-wave__seek",min:0,max:100,step:.1,value:d,onChange:i,disabled:!o,"aria-label":`Seek audio${p}`,"aria-valuetext":`${$e(u)} of ${v}`})]}),t.jsx("span",{className:"shrink-0 text-xs leading-4 tracking-[0.24px] tabular-nums",children:j})]}),n?t.jsx("button",{type:"button",onClick:n.kind==="dismiss"?n.onDismiss:()=>{lt(e.src,e.filename)},"aria-label":n.kind==="dismiss"?"Remove attachment":`Download audio${p}`,className:N($t,Sa[s]),children:n.kind==="dismiss"?t.jsx(C.XIcon,{className:"size-3",weight:"bold","aria-hidden":!0}):t.jsx(C.DownloadSimpleIcon,{className:"size-3",weight:"bold","aria-hidden":!0})}):null]})},Ra="w-[299px]",Aa="py-5 pl-5 pr-3",Ma="rounded-[20px]",La=({src:e,mimeType:s,filename:n,durationSeconds:a,waveformData:r,items:i})=>i&&i.length>0?i:e?[{src:e,mimeType:s,filename:n,durationSeconds:a,waveformData:r}]:[],ct=({state:e,src:s,mimeType:n,filename:a,items:r,durationSeconds:i,waveformData:l,text:o,groupPosition:d,onDismiss:u})=>{const{message:f,threadList:m}=w.useMessageContext(),x=h.useId(),c=ye(e),v=La({src:s,mimeType:n,filename:a,durationSeconds:i,waveformData:l,items:r});if(v.length===0)return null;const j=f!=null&&f.id?`${m?f.parent_id??f.id:""}${f.id}`:x,p=e==="composer"?u?{kind:"dismiss",onDismiss:u}:void 0:{kind:"download"};return t.jsx(_e,{variant:c,text:o,groupPosition:d,bordered:!1,widthClassName:Ra,paddingClassName:Aa,radiusClassName:Ma,"data-testid":"audio-attachment",children:t.jsx("div",{className:"flex flex-col gap-2",children:v.map((g,b)=>t.jsx(Ea,{item:g,variant:c,requester:ga(j,b),trailingAction:p},`${g.src}-${b}`))})})},Da=e=>t.jsx(ct,{...e,state:"composer"}),Pa=e=>t.jsx(ct,{...e,state:"sent"}),Oa=e=>t.jsx(ct,{...e,state:"received"}),Fa={Composer:Da,Sent:Pa,Received:Oa},za={dark:"text-white/55",light:"text-black/65"},Ba={dark:"bg-white/10",light:"bg-black/5"},$a={dark:"text-white/85",light:"text-black/85"},ws=({variant:e,filename:s,title:n,mimeType:a="application/octet-stream",fileSize:r,onActivate:i,activateLabel:l,trailingAction:o})=>{const d=n??s??"File",u=vs(a,s,r),f=t.jsx("div",{className:N("flex size-10 shrink-0 items-center justify-center rounded-sm",Ba[e]),"aria-hidden":!0,children:ce(a,{className:N("size-6",$a[e]),weight:"regular"})}),m=t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col text-left",children:[t.jsx("p",{className:"truncate font-medium leading-snug",children:d}),u?t.jsx("p",{className:N("truncate text-xs leading-4",za[e]),children:u}):null]}),x=i?t.jsxs("button",{type:"button",onClick:i,"aria-label":l,className:N("flex min-w-0 flex-1 items-center gap-3 rounded-sm text-left transition-colors",e==="dark"?"hover:bg-white/[0.04]":"hover:bg-black/[0.04]"),children:[f,m]}):t.jsxs(t.Fragment,{children:[f,m]});return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[x,o?t.jsx("div",{className:"shrink-0",children:o}):null]})},Pe=({onClick:e,variant:s="overlay",ariaLabel:n="Dismiss attachment"})=>t.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),e()},"aria-label":n,className:N("flex size-6 items-center justify-center rounded-full text-white",s==="overlay"?"bg-[#121110]/85 backdrop-blur":"bg-white/15 hover:bg-white/25"),children:t.jsx(C.XIcon,{className:"size-3",weight:"bold"})}),Ua=({src:e,filename:s,fileSize:n,mimeType:a,title:r,items:i})=>i&&i.length>0?i:e?[{src:e,filename:s,fileSize:n,mimeType:a,title:r}]:[],Va=({variant:e,item:s,index:n,onActivate:a,trailingAction:r})=>{const i=s.filename??ne(s.src);return t.jsx(ws,{variant:e,filename:i,title:s.title,mimeType:s.mimeType??"application/octet-stream",fileSize:s.fileSize,onActivate:()=>a(n),activateLabel:`Download ${i}`,trailingAction:r})},dt=({state:e,src:s,filename:n,fileSize:a,mimeType:r,title:i,items:l,text:o,groupPosition:d,onClick:u,onDismiss:f})=>{const m=ye(e),x=e==="composer"&&!!f,c=Ua({src:s,filename:n,fileSize:a,mimeType:r,title:i,items:l}),v=p=>{if((u==null?void 0:u(p))===!1)return;const g=c[p];if(!g)return;const b=g.filename??ne(g.src);lt(g.src,b)};if(c.length===0)return null;const j=t.jsx("span",{className:N("flex size-8 items-center justify-center rounded-full",m==="dark"?"text-white/70":"text-black/70"),"aria-hidden":!0,children:t.jsx(C.DownloadSimpleIcon,{className:"size-5",weight:"bold"})});return t.jsx(_e,{variant:m,text:o,groupPosition:d,"data-testid":"file-attachment",children:t.jsx("div",{className:"flex flex-col gap-2",children:c.map((p,g)=>{const b=x&&g===0?t.jsx(Pe,{onClick:f,variant:"inline"}):j;return t.jsx(Va,{variant:m,item:p,index:g,onActivate:v,trailingAction:b},`${p.src}-${g}`)})})})},Ha=e=>t.jsx(dt,{...e,state:"composer"}),Ga=e=>t.jsx(dt,{...e,state:"sent"}),Ya=e=>t.jsx(dt,{...e,state:"received"}),Wa={Composer:Ha,Sent:Ga,Received:Ya},_s="inline-flex size-10 items-center justify-center rounded-full border-0 bg-white/[0.12] p-0 text-white transition-colors duration-150 ease-[ease] hover:bg-white/[0.22] focus-visible:bg-white/[0.22] focus-visible:outline-none disabled:cursor-default disabled:opacity-40",Ut="absolute top-1/2 z-[1] inline-flex size-12 -translate-y-1/2 items-center justify-center rounded-full border-0 bg-white/[0.12] p-0 text-white transition-colors duration-150 ease-[ease] hover:bg-white/[0.22] focus-visible:bg-white/[0.22] focus-visible:outline-none",ut=({onPrev:e,onNext:s,prevLabel:n="Previous",nextLabel:a="Next"})=>t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:e,"aria-label":n,className:`${Ut} left-4`,children:t.jsx(C.CaretLeftIcon,{size:20,weight:"bold","aria-hidden":!0})}),t.jsx("button",{type:"button",onClick:s,"aria-label":a,className:`${Ut} right-4`,children:t.jsx(C.CaretRightIcon,{size:20,weight:"bold","aria-hidden":!0})})]}),ys=({url:e,filename:s,variant:n="pill",label:a="Download",iconOnly:r,tone:i="dark",onTriggered:l})=>{const[o,d]=h.useState(!1),u=h.useCallback(c=>{c.stopPropagation(),!o&&(d(!0),lt(e,s).catch(()=>{}).finally(()=>{d(!1),l==null||l()}))},[o,e,s,l]),f=r??n!=="pill",x={className:N(n==="pill"?"size-4":"size-5","shrink-0"),weight:"bold"};if(n==="inline"){const c={dark:"text-white/70 hover:bg-white/[0.08] hover:text-white",light:"text-black/70 hover:bg-black/[0.08] hover:text-black"};return t.jsx("button",{type:"button",onClick:u,disabled:o,"aria-label":a,className:N("flex size-8 shrink-0 items-center justify-center rounded-full transition-colors disabled:opacity-70",c[i]),children:o?t.jsx(C.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):t.jsx(C.DownloadSimpleIcon,{className:"size-5 shrink-0",weight:"bold","aria-hidden":!0})})}return n==="viewer"?t.jsx("button",{type:"button",onClick:u,disabled:o,"aria-label":a,className:_s,children:o?t.jsx(C.CircleNotchIcon,{size:20,weight:"bold","aria-hidden":!0}):t.jsx(C.DownloadSimpleIcon,{size:20,weight:"bold","aria-hidden":!0})}):t.jsxs("button",{type:"button",onClick:u,disabled:o,"aria-label":f?a:void 0,className:N("mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full px-4 text-sm font-medium leading-none transition-colors disabled:opacity-70",i==="dark"?"bg-[#121110] text-white hover:bg-[#2a2928]":"bg-white text-[#121110] hover:bg-white/90"),children:[o?t.jsx(C.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):t.jsx(C.DownloadSimpleIcon,{...x,"aria-hidden":!0}),f?null:a]})},Ue=(e,s,n)=>Math.min(Math.max(e,s),n),mt=({length:e,initialIndex:s,open:n})=>{const a=Ue(s,0,Math.max(e-1,0)),[r,i]=h.useState(a);h.useEffect(()=>{n&&i(Ue(s,0,Math.max(e-1,0)))},[n,s,e]),h.useEffect(()=>{i(d=>Ue(d,0,Math.max(e-1,0)))},[e]);const l=h.useCallback(()=>{e<=1||i(d=>d<=0?e-1:d-1)},[e]),o=h.useCallback(()=>{e<=1||i(d=>d>=e-1?0:d+1)},[e]);return h.useEffect(()=>{if(!n||e<=1)return;const d=u=>{if(u.key!=="ArrowLeft"&&u.key!=="ArrowRight")return;const f=document.activeElement;f&&(f.tagName==="VIDEO"||f.tagName==="AUDIO")||(u.preventDefault(),u.key==="ArrowLeft"?l():o())};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n,e,l,o]),{index:r,prev:l,next:o}},ht=({open:e,onClose:s,ariaLabel:n,counter:a,actions:r,children:i,"data-testid":l})=>{const o=h.useRef(null),d=h.useRef(null);h.useEffect(()=>{var x;const m=o.current;if(m){if(e){if(!m.open)if(typeof m.showModal=="function")try{m.showModal()}catch{m.setAttribute("open","")}else m.setAttribute("open","");const c=typeof document<"u"?document.activeElement:null;return(x=d.current)==null||x.focus(),()=>{if(m.open)if(typeof m.close=="function")try{m.close()}catch{m.removeAttribute("open")}else m.removeAttribute("open");c&&document.body.contains(c)&&c.focus()}}if(m.open)if(typeof m.close=="function")try{m.close()}catch{m.removeAttribute("open")}else m.removeAttribute("open")}},[e]);const u=()=>{s()},f=m=>{m.target===o.current&&s()};return t.jsxs("dialog",{ref:o,className:"mes-media-viewer","aria-label":n??"Attachment viewer","data-testid":l,onClose:u,onClick:f,children:[t.jsxs("div",{className:"pointer-events-none absolute inset-x-3 top-3 z-[1] flex items-center justify-between gap-3",children:[a?t.jsx("span",{className:"pointer-events-auto inline-flex items-center rounded-full bg-white/[0.12] px-3 py-1.5 text-[13px] font-medium leading-none tabular-nums text-white",children:a}):null,t.jsxs("div",{className:"pointer-events-auto ml-auto inline-flex items-center gap-2",children:[r,t.jsx("button",{ref:d,type:"button",onClick:s,"aria-label":"Close viewer",className:_s,children:t.jsx(C.XIcon,{size:20,weight:"bold","aria-hidden":!0})})]})]}),t.jsx("div",{className:"box-border flex h-full w-full items-center justify-center px-6 py-16",children:i})]})},Ns=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=mt({length:s.length,initialIndex:n,open:e}),o=s[r],d=h.useMemo(()=>(o==null?void 0:o.filename)??(o?ne(o.src):"image"),[o]);return o?t.jsxs(ht,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,actions:t.jsx(ys,{url:o.src,filename:d,variant:"viewer",label:`Download ${d}`}),"data-testid":"image-viewer",children:[e?t.jsx("img",{src:o.src,alt:o.alt??d,draggable:!1,decoding:"async",className:"block h-auto max-h-[calc(100dvh-128px)] w-auto max-w-[min(96vw,1400px)] select-none object-contain"},`${r}:${o.src}`):null,s.length>1?t.jsx(ut,{onPrev:i,onNext:l,prevLabel:"Previous image",nextLabel:"Next image"}):null]}):null},qa="relative block size-full overflow-hidden bg-black/5 outline-none after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-white/80 focus-visible:after:ring-offset-2 focus-visible:after:ring-offset-black",Xa={1:["rounded-[18px]"],2:["rounded-l-[18px]","rounded-r-[18px]"],3:["rounded-l-[18px]","rounded-tr-[18px]","rounded-br-[18px]"],4:["rounded-tl-[18px]","rounded-tr-[18px]","rounded-bl-[18px]","rounded-br-[18px]"]},Ka="--mes-single-width-cap",Za="[--mes-single-width-cap:309px] sm:[--mes-single-width-cap:326px]",Ja=436,Cs=({tiles:e,onTileActivate:s,maxVisible:n=4,singleAspectRatio:a,className:r})=>{const i=e.length;if(i===0)return null;const l=e.slice(0,Math.min(i,n)),o=i-l.length,d=(f,m,x)=>{var v;const c=N(qa,"h-full w-full",(v=Xa[l.length])==null?void 0:v[m]);return s?t.jsxs("button",{type:"button",onClick:()=>s(m),"aria-label":f.ariaLabel??`Open media ${m+1}`,className:N(c,"cursor-zoom-in"),children:[f.content,x]},m):t.jsxs("div",{className:c,children:[f.content,x]},m)};let u;return a&&(u={aspectRatio:a,width:`min(var(${Ka}), ${Math.round(Ja*a*100)/100}px)`,maxWidth:"100%"}),l.length===1?t.jsx("div",{className:N(a?Za:"aspect-square w-full",r),style:u,children:d(l[0],0)}):l.length===2?t.jsx("div",{className:N("grid aspect-[16/9] w-full grid-cols-2 gap-0.5",r),children:l.map((f,m)=>d(f,m))}):l.length===3?t.jsxs("div",{className:N("grid aspect-[4/3] w-full grid-cols-2 grid-rows-2 gap-0.5",r),children:[t.jsx("div",{className:"row-span-2",children:d(l[0],0)}),d(l[1],1),d(l[2],2)]}):t.jsx("div",{className:N("grid aspect-[379/286] w-full grid-cols-2 grid-rows-2 gap-0.5",r),children:l.map((f,m)=>{const x=o>0&&m===l.length-1;return d(f,m,x?t.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-black/55 text-2xl font-semibold text-white",children:["+",o]}):null)})})},Ne=e=>{const[s,n]=h.useState(!1),[a,r]=h.useState(0),i=h.useCallback(o=>{(e==null?void 0:e(o))!==!1&&(r(o),n(!0))},[e]),l=h.useCallback(()=>n(!1),[]);return{viewerOpen:s,viewerIndex:a,handleActivate:i,closeViewer:l}},Qa=({item:e,index:s,totalCount:n,fallbackLoading:a,imgRef:r,onLoad:i})=>({ariaLabel:`Open image ${s+1} of ${n}`,content:t.jsx("img",{ref:r,src:se(e.src)??e.src,alt:e.alt??"",width:e.width,height:e.height,draggable:!1,loading:e.loading??a,decoding:"async",onLoad:i,className:"absolute inset-0 size-full object-cover"})}),er=({src:e,alt:s,items:n})=>n&&n.length>0?n:e?[{src:e,alt:s}]:[],Ss=(e,s)=>e.map((n,a)=>({src:n.src,alt:n.alt,filename:s&&e.length===1?s:s?`${s} (${a+1})`:void 0})),tr=({src:e,alt:s,filename:n,loading:a="lazy",onClick:r,onDismiss:i})=>{const{viewerOpen:l,viewerIndex:o,handleActivate:d,closeViewer:u}=Ne(r);return t.jsxs("div",{className:"relative w-fit",children:[t.jsx("button",{type:"button",onClick:()=>d(0),"aria-label":"Open image",className:"block size-[280px] cursor-zoom-in overflow-hidden rounded-md outline-none focus-visible:ring-2 focus-visible:ring-black/40",children:t.jsx("img",{src:se(e)??e,alt:s??"",draggable:!1,loading:a,decoding:"async",className:"size-full object-cover"})}),i?t.jsx("div",{className:"absolute right-2 top-2 z-10",children:t.jsx(Pe,{onClick:i})}):null,t.jsx(Ns,{open:l,items:Ss([{src:e,alt:s}],n),initialIndex:o,onClose:u})]})},sr=326/246,nr=e=>{const s=e==null?void 0:e.src,[n,a]=h.useState(),r=h.useCallback(d=>{if(!d||d.naturalWidth<=0||d.naturalHeight<=0||s===void 0)return;const u=d.naturalWidth/d.naturalHeight;a(f=>f&&f.src===s&&f.ratio===u?f:{src:s,ratio:u})},[s]),i=h.useCallback(d=>r(d.currentTarget),[r]),l=e!=null&&e.width&&(e!=null&&e.height)?e.width/e.height:void 0,o=n&&n.src===s?n.ratio:void 0;return{ratio:l??o??sr,imgRef:r,onLoad:i}},ks=({state:e,src:s,alt:n,filename:a,items:r,text:i,groupPosition:l,loading:o="lazy",onClick:d})=>{const u=er({src:s,alt:n,items:r}),f=ye(e),{viewerOpen:m,viewerIndex:x,handleActivate:c,closeViewer:v}=Ne(d),j=u.length===1,p=nr(j?u[0]:void 0);if(u.length===0)return null;const g=u.map((b,y)=>Qa({item:b,index:y,totalCount:u.length,fallbackLoading:o,imgRef:j?p.imgRef:void 0,onLoad:j?p.onLoad:void 0}));return t.jsxs(_e,{variant:f,text:i,groupPosition:l,bordered:!1,widthClassName:j?"w-fit max-w-[min(100%,313px)] sm:max-w-[min(100%,330px)]":"w-[383px] max-w-full",paddingClassName:"p-0.5",radiusClassName:"rounded-[20px]","data-testid":"image-attachment",children:[t.jsx("div",{className:"relative",children:t.jsx(Cs,{tiles:g,onTileActivate:c,singleAspectRatio:j?p.ratio:void 0})}),t.jsx(Ns,{open:m,items:Ss(u,a),initialIndex:x,onClose:v})]})},ar=e=>t.jsx(tr,{...e}),rr=e=>t.jsx(ks,{...e,state:"sent"}),ir=e=>t.jsx(ks,{...e,state:"received"}),or={Composer:ar,Sent:rr,Received:ir},lr=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=mt({length:s.length,initialIndex:n,open:e}),o=s[r],d=h.useMemo(()=>(o==null?void 0:o.filename)??(o?ne(o.src):"document"),[o]),u=h.useMemo(()=>o?cr(o.src):void 0,[o]);return!o||!u?null:t.jsxs(ht,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,"data-testid":"pdf-viewer",children:[t.jsx("iframe",{src:u,title:d,className:"block h-[calc(100dvh-128px)] w-[min(96vw,1400px)] border-0 bg-white",sandbox:"allow-scripts allow-forms allow-popups allow-downloads"},`${r}:${o.src}`),s.length>1?t.jsx(ut,{onPrev:i,onNext:l,prevLabel:"Previous document",nextLabel:"Next document"}):null]})},cr=e=>{const s=e.indexOf("#"),n=s===-1?e:e.slice(0,s),a=s===-1?"":e.slice(s+1),r=new URLSearchParams(a);return r.has("toolbar")||r.set("toolbar","0"),r.has("navpanes")||r.set("navpanes","0"),`${n}#${r.toString()}`},dr=({src:e,filename:s,fileSize:n,title:a,items:r})=>r&&r.length>0?r:e?[{src:e,filename:s,fileSize:n,title:a}]:[],ur=({variant:e,item:s,index:n,onActivate:a,trailingAction:r})=>{const i=s.filename??ne(s.src);return t.jsx(ws,{variant:e,filename:i,title:s.title,mimeType:"application/pdf",fileSize:s.fileSize,onActivate:()=>a(n),activateLabel:`Open ${i}`,trailingAction:r})},ft=({state:e,src:s,filename:n,fileSize:a,title:r,items:i,text:l,groupPosition:o,onClick:d,onDismiss:u})=>{const f=ye(e),m=dr({src:s,filename:n,fileSize:a,title:r,items:i}),{viewerOpen:x,viewerIndex:c,handleActivate:v,closeViewer:j}=Ne(d),p=e==="composer"&&!!u;if(m.length===0)return null;const g=m.map(b=>({src:b.src,filename:b.filename??ne(b.src)}));return t.jsxs(_e,{variant:f,text:l,groupPosition:o,"data-testid":"pdf-attachment",children:[t.jsx("div",{className:"flex flex-col gap-2",children:m.map((b,y)=>{const _=b.filename??ne(b.src),R=p&&y===0?t.jsx(Pe,{onClick:u,variant:"inline"}):e==="composer"?void 0:t.jsx(ys,{url:b.src,filename:_,variant:"inline",label:`Download ${_}`,tone:f});return t.jsx(ur,{variant:f,item:b,index:y,onActivate:v,trailingAction:R},`${b.src}-${y}`)})}),t.jsx(lr,{open:x,items:g,initialIndex:c,onClose:j})]})},mr=e=>t.jsx(ft,{...e,state:"composer"}),hr=e=>t.jsx(ft,{...e,state:"sent"}),fr=e=>t.jsx(ft,{...e,state:"received"}),xr={Composer:mr,Sent:hr,Received:fr},Es=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=mt({length:s.length,initialIndex:n,open:e}),o=s[r],d=h.useMemo(()=>(o==null?void 0:o.filename)??(o?ne(o.src):"video"),[o]);return o?t.jsxs(ht,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,"data-testid":"video-viewer",children:[t.jsx("video",{src:o.src,poster:o.poster,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,preload:o.preload??"metadata",className:"block h-auto max-h-[calc(100dvh-128px)] w-auto max-w-[min(96vw,1400px)] bg-black",children:o.mimeType?t.jsx("source",{src:o.src,type:o.mimeType}):null},`${r}:${o.src}`),s.length>1?t.jsx(ut,{onPrev:i,onNext:l,prevLabel:"Previous video",nextLabel:"Next video"}):null]}):null},gr=()=>t.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:t.jsx("span",{className:"flex size-12 items-center justify-center rounded-full bg-black/55 text-white backdrop-blur",children:t.jsx(C.PlayIcon,{className:"size-6",weight:"fill","aria-hidden":!0})})}),Is=({item:e,index:s})=>t.jsxs("div",{className:"absolute inset-0 size-full bg-[#0d0d0d]",children:[e.poster?t.jsx("img",{src:e.poster,alt:`Video ${s+1} thumbnail`,draggable:!1,loading:"lazy",decoding:"async",className:"absolute inset-0 size-full object-cover"}):t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:t.jsx(C.VideoCameraIcon,{className:"size-16 text-white/30",weight:"regular","aria-hidden":!0})}),t.jsx(gr,{})]}),pr=(e,s,n)=>({ariaLabel:`Play video ${s+1} of ${n}`,content:t.jsx(Is,{item:e,index:s})}),br=({src:e,poster:s,mimeType:n,preload:a,items:r})=>r&&r.length>0?a?r.map(i=>({...i,preload:i.preload??a})):r:e?[{src:e,poster:s,mimeType:n,preload:a}]:[],Ts=(e,s)=>e.map((n,a)=>({src:n.src,poster:n.poster,mimeType:n.mimeType,preload:n.preload,filename:s&&e.length===1?s:s?`${s} (${a+1})`:void 0})),vr=({src:e,poster:s,mimeType:n,filename:a,preload:r,onClick:i,onDismiss:l})=>{const{viewerOpen:o,viewerIndex:d,handleActivate:u,closeViewer:f}=Ne(i);return t.jsxs("div",{className:"relative w-fit",children:[t.jsx("button",{type:"button",onClick:()=>u(0),"aria-label":"Play video",className:"relative block size-[280px] cursor-pointer overflow-hidden rounded-md outline-none focus-visible:ring-2 focus-visible:ring-black/40",children:t.jsx(Is,{item:{src:e,poster:s,mimeType:n},index:0})}),l?t.jsx("div",{className:"absolute right-2 top-2 z-10",children:t.jsx(Pe,{onClick:l})}):null,t.jsx(Es,{open:o,items:Ts([{src:e,poster:s,mimeType:n,preload:r}],a),initialIndex:d,onClose:f})]})},Rs=({state:e,src:s,poster:n,mimeType:a,filename:r,items:i,text:l,groupPosition:o,preload:d,onClick:u})=>{const f=br({src:s,poster:n,mimeType:a,preload:d,items:i}),m=ye(e),{viewerOpen:x,viewerIndex:c,handleActivate:v,closeViewer:j}=Ne(u);if(f.length===0)return null;const p=f.map((g,b)=>pr(g,b,f.length));return t.jsxs(_e,{variant:m,text:l,groupPosition:o,"data-testid":"video-attachment",children:[t.jsx("div",{className:"relative",children:t.jsx(Cs,{tiles:p,onTileActivate:v})}),t.jsx(Es,{open:x,items:Ts(f,r),initialIndex:c,onClose:j})]})},jr=e=>t.jsx(vr,{...e}),wr=e=>t.jsx(Rs,{...e,state:"sent"}),_r=e=>t.jsx(Rs,{...e,state:"received"}),yr={Composer:jr,Sent:wr,Received:_r},fe={Image:or,Video:yr,Audio:Fa,Pdf:xr,File:Wa};function V(e){const s=e==null?void 0:e.trim();return s||void 0}function Vt(e){return e.trim().replace(/^https?:\/\//i,"").replace(/\/+$/,"").toLowerCase()}function Nr(e,s){if(!(e!=null&&e.trim())||!(s!=null&&s.trim()))return!1;const n=Vt(e),a=Vt(s);if(n===a)return!0;if(!n.includes(a))return!1;const r=n.split(a).join("");return!/[^\p{P}\p{Z}\p{C}]/u.test(r)}function Ht(e){const s=V(e.og_scrape_url)??V(e.title_link),n=V(e.image_url)??V(e.thumb_url),a=V(e.asset_url),r=V(e.mime_type);return{title:V(e.title),description:V(e.text),url:s,thumbnailUrl:se(n),sourceUrl:a,layout:n||rt(r,a)?"featured":"classic",mimeType:r,accentColor:V(e.accent_color),status:"ready"}}function Cr(e){var s;return je(e)?null:e.type==="image"?e.image_url||e.asset_url?"image":null:e.type==="video"&&e.asset_url?"video":e.type==="audio"&&e.asset_url?"audio":e.type==="file"&&e.asset_url?e.mime_type==="application/pdf"?"pdf":(s=e.mime_type)!=null&&s.startsWith("audio/")?"audio":"file":null}function As(e){if(!(e!=null&&e.length))return[];const s=[],n=(r,i)=>{const l=s[s.length-1];if((l==null?void 0:l.type)==="media"&&l.kind===r){l.attachments.push(i);return}s.push({type:"media",kind:r,attachments:[i]})},a=r=>{const i=s[s.length-1];if((i==null?void 0:i.type)==="link"){i.attachments.push(r);return}s.push({type:"link",attachments:[r]})};for(const r of e){if(je(r)){a(r);continue}const i=Cr(r);i&&n(i,r)}return s}function Sr(e){return e.filter(s=>s.type==="media").length}function kr(e,s,n){return s<=1?n:e===0?"first":e===s-1?"end":"middle"}function Er(e){return V(e.image_url)??V(e.asset_url)??""}function Ir(e){switch(e){case"image":return fe.Image;case"video":return fe.Video;case"audio":return fe.Audio;case"pdf":return fe.Pdf;default:return fe.File}}function Gt(e,s){switch(e){case"image":return{src:Er(s),alt:V(s.title)};case"video":return{src:V(s.asset_url)??"",poster:V(s.thumb_url),mimeType:V(s.mime_type)};case"audio":return{src:V(s.asset_url)??"",mimeType:V(s.mime_type)??"audio/mpeg",filename:V(s.title),durationSeconds:s.duration,waveformData:s.waveform_data};case"pdf":return{src:V(s.asset_url)??"",filename:V(s.title),fileSize:s.file_size};case"file":return{src:V(s.asset_url)??"",filename:V(s.title),fileSize:s.file_size,mimeType:V(s.mime_type)??"application/octet-stream"}}}function Tr(e,s){if(s.length>1)return{items:s.map(a=>Gt(e,a))};const n=s[0];return n?Gt(e,n):{}}function Rr({groupPosition:e,isMyMessage:s,segment:n}){const a=Ir(n.kind),r={...Tr(n.kind,n.attachments),groupPosition:e};return s?t.jsx(a.Sent,{...r}):t.jsx(a.Received,{...r})}const Ar=({groupPosition:e,isMyMessage:s,message:n,renderText:a})=>{var p;const r=As(n.attachments);if(r.length===0)return null;const i=Sr(r),l=(p=n.text)==null?void 0:p.trim(),o=r.find(g=>g.type==="link"),d=(o==null?void 0:o.type)==="link"?Ht(o.attachments[0]??{}).url:void 0,u=l&&Nr(l,d)?void 0:l;let f=0;const m=[],x=u?"middle":e,c=e==="single"||e==="end",v=(g,b,y)=>{const _=s?Te.Sent:Te.Received;m.push(t.jsx(_,{...Ht(g),groupPosition:y?x:"middle"},b))},j=(g,b)=>{const y=kr(f,i,e);f+=1,m.push(t.jsx(Rr,{groupPosition:y,isMyMessage:s,segment:g},b))};return r.forEach((g,b)=>{const y=b===r.length-1;if(g.type==="link"){g.attachments.forEach((_,R)=>{v(_,`link-${b}-${R}`,y&&R===g.attachments.length-1)});return}j(g,`media-${b}`)}),t.jsxs("div",{className:"str-chat__message-bubble-wrapper",children:[t.jsxs("div",{className:"str-chat__message-bubble","data-attachment-bubble":"true",style:{background:"transparent",borderRadius:0,overflow:"visible",padding:0},children:[m,!u&&t.jsx(w.MessageErrorIcon,{})]}),u?t.jsxs("div",{className:N("str-chat__message-bubble",{"relative isolate":c}),children:[t.jsx(w.MessageText,{message:n,renderText:a}),t.jsx(w.MessageErrorIcon,{}),c&&t.jsx(Ie,{side:s?"me":"other"})]}):null]})},Mr=e=>{var _t,yt,Nt,Ct,St,kt,Et,It,Tt,Rt;const{additionalMessageInputProps:s,editing:n,endOfGroup:a,firstOfGroup:r,groupStyles:i,groupedByUser:l,handleAction:o,handleOpenThread:d,handleRetry:u,highlighted:f,isMessageAIGenerated:m,isMyMessage:x,message:c,renderText:v,threadList:j,viewerLanguage:p,onOutboundClick:g,resolvedOutbound:b}=e,{client:y}=w.useChatContext("CustomMessage"),{channel:_}=w.useChannelStateContext("CustomMessage"),{isUnlocking:R,onUnlockClick:L,onFetchSource:I,onDownloadClick:z}=ds("LockedAttachment"),[F,M]=h.useState(!1),T=w.useMessageReminder(c.id),{Attachment:D=w.Attachment,EditMessageModal:E=w.EditMessageModal,MessageActions:k,MessageBlocked:A=w.MessageBlocked,MessageBouncePrompt:O=w.MessageBouncePrompt,MessageDeleted:B=w.MessageDeleted,MessageIsThreadReplyInChannelButtonIndicator:H=w.MessageIsThreadReplyInChannelButtonIndicator,MessageRepliesCountButton:Z=w.MessageRepliesCountButton,ReminderNotification:q=w.ReminderNotification,StreamedMessageText:X=w.StreamedMessageText,PinIndicator:U}=w.useComponentContext("CustomMessage"),S=w.messageHasAttachments(c),P=w.messageHasReactions(c),G=h.useMemo(()=>m==null?void 0:m(c),[m,c]),$=h.useMemo(()=>{const le=c.attachments??[],me=c.shared_location?[c.shared_location,...le]:le;if(!Ee(c))return me;const At=me.filter(Mt=>!("type"in Mt)||!je(Mt));return At.length===me.length?me:At},[c]),K=h.useMemo(()=>As($),[$]),W=h.useMemo(()=>{const le=Ke({message:c,viewerLanguage:p});return le===c.text?c:{...c,text:le}},[c,p]),Q=K.length>0,ie=K.reduce((le,me)=>le+me.attachments.length,0)===(($==null?void 0:$.length)??0),te=(i==null?void 0:i[0])??"",Ce=te==="top"?"first":te==="middle"?"middle":te==="bottom"?"end":"single",ee=te==="single"||te==="bottom";if(w.isDateSeparatorMessage(c))return null;if(c.deleted_at||c.type==="deleted")return t.jsx(B,{message:c});if(w.isMessageBlocked(c))return t.jsx(A,{});const oe=!j&&!!c.reply_count,re=!j&&c.show_in_channel&&c.parent_id,gt=c.status==="failed"&&((_t=c.error)==null?void 0:_t.status)!==403,pt=w.isMessageBounced(c);let ue;gt?ue=()=>u(c):pt&&(ue=()=>M(!0));const J=x(),Us=N("str-chat__message str-chat__message-simple",`str-chat__message--${c.type}`,`str-chat__message--${c.status}`,J?"str-chat__message--me str-chat__message-simple--me":"str-chat__message--other",c.text?"str-chat__message--has-text":"has-no-text",{"str-chat__message--has-attachment":S,"str-chat__message--highlighted":f,"str-chat__message--pinned pinned-message":c.pinned,"str-chat__message--with-reactions":P,"str-chat__message-send-can-be-retried":(c==null?void 0:c.status)==="failed"&&((yt=c==null?void 0:c.error)==null?void 0:yt.status)!==403,"str-chat__message-with-thread-link":oe||re,"str-chat__virtual-message__wrapper--end":a,"str-chat__virtual-message__wrapper--first":r,"str-chat__virtual-message__wrapper--group":l}),Oe=c.poll_id&&y.polls.fromState(c.poll_id),bt=hs(c),xe=Ee(c),Vs=et(c),Fe=!!($!=null&&$.length&&!c.quoted_message),vt=xe&&J&&Fe,Hs=Q&&ie&&!c.quoted_message&&!Oe&&!G&&!xe,jt={contentType:"text",amountText:(Nt=c.metadata)==null?void 0:Nt.amount_text,paymentStatus:(Ct=c.metadata)==null?void 0:Ct.payment_status,renderedText:c.text&&t.jsx(w.MessageText,{message:W,renderText:v})},wt={contentType:"media",title:(St=c.metadata)==null?void 0:St.attachment_title,mimeType:(kt=c.metadata)==null?void 0:kt.attachment_mime_type,thumbnailUrl:(Et=c.metadata)==null?void 0:Et.attachment_thumbnail,amountText:(It=c.metadata)==null?void 0:It.amount_text,detail:(Tt=c.metadata)==null?void 0:Tt.attachment_detail,paymentStatus:(Rt=c.metadata)==null?void 0:Rt.payment_status,onFetchSource:I?()=>I(c,_):void 0};return t.jsxs(t.Fragment,{children:[n&&t.jsx(E,{additionalMessageInputProps:s}),F&&t.jsx(w.MessageBounceModal,{MessageBouncePrompt:O,onClose:()=>M(!1),open:F}),t.jsxs("div",{className:Us,"data-message-id":c.id,"data-dd-privacy":"mask",children:[U&&t.jsx(U,{}),!!T&&t.jsx(q,{reminder:T}),c.user&&t.jsx(de,{className:"str-chat__avatar str-chat__message-sender-avatar",id:c.user.id,image:c.user.image,name:c.user.name||c.user.id,size:24,shape:"circle",dmAgentEnabled:xe}),t.jsx("div",{className:N("str-chat__message-inner",{"str-chat__simple-message--error-failed":gt||pt}),"data-testid":"message-inner",onClick:ue,onKeyDown:ue,role:ue?"button":void 0,tabIndex:ue?0:void 0,style:{marginInlineEnd:0,marginInlineStart:0},children:bt?t.jsx(Be,{message:c,standalone:!0}):Mn(c)?t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsxs("div",{className:"flex items-center gap-2",children:[J&&k&&t.jsx(k,{}),J?t.jsx(ge,{...jt,isMine:!0}):t.jsx(ge,{...jt,isMine:!1,isUnlocking:R(c.id),onUnlockClick:()=>L==null?void 0:L(c,_)}),!J&&k&&t.jsx(k,{})]})}):Ln(c)?t.jsxs("div",{className:"str-chat__message-bubble-wrapper",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[J&&k&&t.jsx(k,{}),J?t.jsx(ge,{...wt,isMine:!0,onPreviewClick:()=>L?L(c,_):void 0}):t.jsx(ge,{...wt,isMine:!1,isUnlocking:R(c.id),onUnlockClick:()=>L?L(c,_):void 0,onDownloadClick:()=>z?z(c,_):void 0}),!J&&k&&t.jsx(k,{})]}),c.text&&t.jsxs("div",{className:N("str-chat__message-bubble",{"relative isolate":ee}),children:[t.jsx(w.MessageText,{message:W,renderText:v}),ee&&t.jsx(Ie,{side:J?"me":"other"})]})]}):Hs?t.jsx(Ar,{groupPosition:Ce,isMyMessage:J,message:{...W,attachments:$,i18n:void 0},renderText:v}):t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsxs("div",{className:N("str-chat__message-bubble",{"relative isolate":ee}),children:[xe&&!vt&&t.jsx(Be,{message:c,hasAttachment:Fe,isMyMessage:J}),Oe&&t.jsx(w.Poll,{poll:Oe}),$!=null&&$.length&&!c.quoted_message?t.jsx(D,{actionHandler:o,attachments:$}):null,G?t.jsx(X,{message:W,renderText:v}):t.jsx(w.MessageText,{message:W,renderText:v}),t.jsx(w.MessageErrorIcon,{}),ee&&t.jsx(Ie,{side:J?"me":"other"})]})})}),!Vs&&!bt&&t.jsx("div",{className:"str-chat__message-footer",children:(!xe||vt)&&t.jsx(Be,{message:c,hasAttachment:Fe,isMyMessage:J})}),t.jsx(Hn,{onOutboundClick:g,resolvedOutbound:b}),oe&&t.jsx(Z,{onClick:d,reply_count:c.reply_count}),re&&t.jsx(H,{})]},c.id)]})},Lr=h.memo(Mr,(e,s)=>{var n,a,r,i;return e.viewerLanguage!==s.viewerLanguage||e.onOutboundClick!==s.onOutboundClick||((n=e.resolvedOutbound)==null?void 0:n.id)!==((a=s.resolvedOutbound)==null?void 0:a.id)||((r=e.resolvedOutbound)==null?void 0:r.name)!==((i=s.resolvedOutbound)==null?void 0:i.name)?!1:w.areMessageUIPropsEqual(e,s)}),Dr=e=>{var i;const s=w.useMessageContext("CustomMessage"),n=h.useContext(fs),a=(i=s.message.metadata)==null?void 0:i.outbound_id,r=typeof a=="string"?n==null?void 0:n[a]:void 0;return t.jsx(Lr,{...s,...e,resolvedOutbound:r})},Pr=()=>{var n;const{handleDelete:e,message:s}=w.useMessageContext("CustomMessageActions");return((n=s.metadata)==null?void 0:n.payment_status)==="paid"?null:t.jsx(Ye.DefaultDropdownActionButton,{onClick:e,"aria-label":"Delete",title:"Delete",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:t.jsx(C.TrashSimpleIcon,{size:16,weight:"light","aria-hidden":!0})})},Or=()=>{const{handleFlag:e}=w.useMessageContext("CustomMessageActions");return t.jsx(Ye.DefaultDropdownActionButton,{onClick:e,"aria-label":"Report",title:"Report",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:t.jsx(C.FlagIcon,{size:16,weight:"light","aria-hidden":!0})})},Fr=()=>{var s;const{message:e}=w.useMessageContext("CustomMessageActions");return((s=e.metadata)==null?void 0:s.custom_type)!==Y.MESSAGE_CUSTOM_TYPE.ATTACHMENT?null:t.jsx(Ye.MessageActions,{messageActionSet:[{Component:Pr,placement:"quick",type:"delete"},{Component:Or,placement:"quick",type:"flag"}]})},zr=e=>({linkPreviews:Array.from(e.previews.values()).filter(s=>ke.LinkPreviewsManager.previewIsLoaded(s)||ke.LinkPreviewsManager.previewIsLoading(s))}),Br=()=>{const{linkPreviewsManager:e}=w.useMessageComposer(),{linkPreviews:s}=w.useStateStore(e.state,zr),n=r=>{e.dismissPreview(r)};return s.length>0?t.jsx("div",{className:"messaging-link-preview-list flex flex-col items-stretch w-full gap-2",children:s.map(r=>{const i=ke.LinkPreviewsManager.previewIsLoading(r);return t.jsx(Te.Composer,{title:r.title,url:r.og_scrape_url,thumbnailUrl:r.image_url,layout:i||r.image_url?"featured":"classic",status:i?"loading":"ready",onDismiss:()=>n(r.og_scrape_url)},r.og_scrape_url)})}):null},Re=h.createContext(!1),$r=200,Ur=()=>h.useContext(Re),Vr=({sendMessage:e,disabled:s,...n})=>t.jsx("button",{...n,type:"button","aria-label":"Send",disabled:s,onPointerDown:a=>a.preventDefault(),onClick:e,children:t.jsx(C.ArrowUpIcon,{weight:"bold",className:"size-4"})}),Yt=()=>{const e=h.useContext(Re),{handleSubmit:s}=w.useMessageInputContext(),n=w.useMessageComposerHasSendableData(),a=e||!n,{SendButton:r=Vr,AttachmentPreviewList:i=w.AttachmentPreviewList}=w.useComponentContext("CustomMessageInput"),l=h.useRef(null);return h.useEffect(()=>{const o=l.current;if(!o||typeof ResizeObserver>"u")return;const d=new ResizeObserver(()=>{o.contains(document.activeElement)&&(o.scrollTop=o.scrollHeight)});return d.observe(o),()=>d.disconnect()},[]),h.useEffect(()=>{const o=l.current;if(!o)return;const d=u=>{var m;Array.from(((m=u.clipboardData)==null?void 0:m.items)??[]).some(x=>x.kind==="file")||u.stopPropagation()};return o.addEventListener("paste",d),()=>o.removeEventListener("paste",d)},[]),t.jsxs("div",{ref:l,className:"central-container flex flex-col min-w-0 w-full max-h-[calc(var(--messaging-surface-height,100dvh)*0.5)] overflow-y-auto overscroll-contain bg-white rounded-[1.5rem] shadow-[0_4px_16px_0_rgba(0,0,0,0.08),0_1px_2px_0_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.04)] [&>:not(.messaging-composer-previews):not(.messaging-composer-row)]:p-2","data-dd-privacy":"mask",children:[t.jsxs("div",{className:"messaging-composer-previews empty:hidden flex flex-col gap-2 px-2 pt-2",children:[t.jsx(w.QuotedMessagePreview,{}),t.jsx(Br,{}),t.jsx(i,{})]}),t.jsxs("div",{className:"messaging-composer-row flex items-start",children:[t.jsx(w.TextareaComposer,{"aria-disabled":e||void 0,containerClassName:"min-w-0 flex-1 leading-[0]",className:"w-full resize-none overflow-hidden bg-transparent py-3.5 pl-4 pr-4 outline-none leading-5 placeholder:text-black/30 text-sm",autoFocus:!e,enterKeyHint:"send",maxRows:1/0,readOnly:e,tabIndex:e?-1:void 0}),t.jsx("div",{className:"sticky bottom-2 mt-auto mb-2 mr-2 shrink-0 pt-2",children:t.jsx(r,{sendMessage:s,"aria-label":"Send",className:"str-chat__send-button relative flex justify-center items-center rounded-full size-8 bg-[#121110] disabled:bg-[#F1F0EE] disabled:text-black/20 text-white focus-ring before:absolute before:-inset-2 before:content-['']","data-testid":"send-button",disabled:a,type:"button"})})]})]})},Wt=()=>t.jsxs("div",{className:"messaging-composer-backdrop","aria-hidden":"true",children:[t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-gradient"})]}),qt=({renderActions:e,renderHeader:s,renderFooter:n,disabled:a=!1,disabledReason:r,composerInput:i})=>{var f;const{channel:l}=w.useChannelStateContext(),o=((f=l==null?void 0:l.data)==null?void 0:f.frozen)===!0,d=!!i,u=h.useRef(null);return h.useEffect(()=>{if(!d)return;const m=u.current,x=m==null?void 0:m.parentElement;if(!m||!x)return;let c=m.offsetHeight;const v=()=>{const p=m.offsetHeight,g=p>c;c=p;const b=Array.from(x.querySelectorAll(".str-chat__list")).find(_=>_.scrollHeight>_.clientHeight)??null,y=b?b.scrollHeight-b.scrollTop-b.clientHeight<$r:!1;x.style.setProperty("--messaging-composer-height",`${p}px`),g&&y&&b&&(b.scrollTop=b.scrollHeight)};if(v(),typeof ResizeObserver>"u")return;const j=new ResizeObserver(v);return j.observe(m),()=>{j.disconnect(),x.style.removeProperty("--messaging-composer-height")}},[d]),a?d?t.jsxs("div",{ref:u,className:"messaging-composer-chrome messaging-composer-chrome--floating",children:[t.jsx(Wt,{}),t.jsxs("div",{className:"relative z-10 flex flex-col",children:[s==null?void 0:s(),t.jsx("div",{className:"messaging-composer-locked-panel flex w-full flex-col items-center justify-center gap-3 px-6 py-4",children:r?t.jsx("p",{className:"max-w-[345px] text-center text-xs font-normal leading-[1.3] tracking-[0.12px] text-black/40",children:r}):null}),n==null?void 0:n()]})]}):t.jsxs(t.Fragment,{children:[s==null?void 0:s(),t.jsx("div",{className:"messaging-composer-locked-panel flex w-full flex-col items-center justify-center gap-3 px-6 py-4",children:r?t.jsx("p",{className:"max-w-[345px] text-center text-xs font-normal leading-[1.3] tracking-[0.12px] text-black/40",children:r}):null}),n==null?void 0:n()]}):d?t.jsxs("div",{ref:u,className:"messaging-composer-chrome messaging-composer-chrome--floating",children:[t.jsx(Wt,{}),t.jsxs("div",{className:"relative z-10 flex min-h-0 flex-col",children:[s==null?void 0:s(),t.jsxs("div",{className:"flex min-h-0 flex-col gap-4 p-4",children:[t.jsxs("div",{inert:o?"":void 0,"aria-disabled":o||void 0,className:"message-input flex min-h-0 items-end gap-4 aria-disabled:opacity-40",children:[e&&t.jsx("div",{className:"flex h-12 shrink-0 items-center justify-center",children:e()}),t.jsx(Re.Provider,{value:o,children:t.jsx(w.MessageInput,{Input:i??Yt})})]}),n==null?void 0:n()]})]})]}):t.jsxs("div",{className:"flex min-h-0 flex-col gap-4 p-4",children:[s==null?void 0:s(),t.jsxs("div",{inert:o?"":void 0,"aria-disabled":o||void 0,className:"message-input flex min-h-0 items-end gap-4 aria-disabled:opacity-40",children:[e&&t.jsx("div",{className:"flex h-12 shrink-0 items-center justify-center",children:e()}),t.jsx(Re.Provider,{value:o,children:t.jsx(w.MessageInput,{Input:Yt})})]}),n==null?void 0:n()]})},Hr={SYSTEM_DM_AGENT_PAUSED:"DM Agent has left the conversation",SYSTEM_DM_AGENT_RESUMED:"DM Agent has rejoined the conversation"},Gr=["SYSTEM_AGE_SAFETY_BLOCKED"],Yr={SYSTEM_AGE_SAFETY_BLOCKED:"This user isn’t able to reply because they don’t meet our age safety guidelines."},Ve="age safety guidelines.",Wr="https://linktr.ee/s/about/contact",qr=e=>Gr.includes(e),Xr=e=>{var s;return qr((s=e.metadata)==null?void 0:s.custom_type)},Kr=e=>{var a;const s=(a=e.metadata)==null?void 0:a.custom_type;if(Y.isDmAgentSystemType(s))return{kind:"dm-agent",type:s};if(Y.isAgeSafetySystemType(s))return{kind:"age-safety",type:s};const n=e.dm_agent_system_type;if(Y.isDmAgentSystemType(n))return{kind:"dm-agent",type:n}},Zr=e=>{const s=e.indexOf(Ve);if(s===-1)return e;const n=s+Ve.length;return t.jsxs(t.Fragment,{children:[e.slice(0,s),t.jsx("a",{href:Wr,target:"_blank",rel:"noopener noreferrer",className:"mes-age-safety-system-message__emphasis font-medium text-inherit underline",children:Ve}),e.slice(n)]})},Jr=e=>{var a,r;const s=!Xr(e.message),n=Kr(e.message);if((n==null?void 0:n.kind)==="dm-agent"){const i=((a=e.message.text)==null?void 0:a.trim())||Hr[n.type];return t.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[t.jsxs("div",{className:"mes-dm-agent-system-message mx-auto mb-2 inline-flex w-fit max-w-[min(100%,480px)] items-center justify-center gap-[10px] rounded-[12px] border border-[rgba(0,0,0,0.08)] p-3 text-[rgba(0,0,0,0.55)]","data-testid":"dm-agent-system-message","data-dm-agent-system-type":n.type,children:[t.jsx(C.SparkleIcon,{size:16,weight:"regular","aria-hidden":!0,className:"mes-dm-agent-system-message__sparkle shrink-0"}),t.jsx("p",{className:"mes-dm-agent-system-message__text m-0 text-center text-[14px] font-normal leading-5 tracking-[0.21px]",children:i})]}),!s&&t.jsx(w.MessageTimestamp,{message:e.message})]})}if((n==null?void 0:n.kind)==="age-safety"){const i=((r=e.message.text)==null?void 0:r.trim())||Yr[n.type];return t.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[t.jsxs("div",{className:"mes-age-safety-system-message box-border mx-auto mb-2 flex w-full max-w-[329px] items-start justify-center gap-3 rounded-[12px] border border-[var(--border-secondary,rgba(0,0,0,0.08))] bg-[var(--bg-warning-subtle,#fef3c6)] px-2 py-4 pl-5 text-[color:var(--text-warning-on-warning,#894b00)]","data-testid":"age-safety-system-message","data-age-safety-system-type":n.type,children:[t.jsx(C.ProhibitIcon,{size:24,weight:"duotone","aria-hidden":!0,className:"mes-age-safety-system-message__icon shrink-0 text-[color:var(--text-warning-on-warning,#894b00)]","data-testid":"age-safety-system-message-icon"}),t.jsx("div",{className:"mes-age-safety-system-message__content min-w-0 flex-[1_0_0]",children:t.jsx("p",{className:"m-0 text-balance text-left text-[12px] font-normal leading-4 tracking-[0.21px] text-[color:var(--text-warning-on-warning,#894b00)]",children:Zr(i)})})]}),!s&&t.jsx(w.MessageTimestamp,{message:e.message})]})}return t.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[t.jsxs("div",{className:"str-chat__message--system__text",children:[t.jsx("div",{className:"str-chat__message--system__line"}),t.jsx("p",{children:e.message.text}),t.jsx("div",{className:"str-chat__message--system__line"})]}),!s&&t.jsx(w.MessageTimestamp,{message:e.message})]})},Ms=h.createContext(!1),He=({cx:e,index:s})=>t.jsx("circle",{cx:e,cy:"6.15",r:"3.9",fill:"#A0A0A0",children:t.jsx("animateTransform",{attributeName:"transform",type:"translate",values:"0 0; 0 -2.25; 0 0;",dur:"900ms",begin:`${120*s}ms`,repeatCount:"indefinite"})}),Qr=new Set([w.AIStates.Thinking,w.AIStates.Generating,w.AIStates.ExternalSources]),ei=({threadList:e})=>{var v,j;const{channel:s,channelConfig:n,thread:a}=w.useChannelStateContext(),{client:r}=w.useChatContext(),{typing:i={}}=w.useTypingContext(),{aiState:l}=w.useAIState(s),o=h.useContext(Ms);if(!e&&o&&Qr.has(l)){const p=ti(s,(v=r.user)==null?void 0:v.id);return t.jsx(Xt,{avatarId:(p==null?void 0:p.id)??"ai-agent",avatarName:(p==null?void 0:p.name)??(p==null?void 0:p.id)??"Agent",avatarImage:p==null?void 0:p.image,testId:"typing-indicator-ai"})}if((n==null?void 0:n.typing_events)===!1)return null;const u=e?[]:Object.values(i).filter(({parent_id:p,user:g})=>{var b;return(g==null?void 0:g.id)!==((b=r.user)==null?void 0:b.id)&&!p}),f=e?Object.values(i).filter(({parent_id:p,user:g})=>{var b;return(g==null?void 0:g.id)!==((b=r.user)==null?void 0:b.id)&&p===(a==null?void 0:a.id)}):[],m=e?f:u;if(!m.length)return null;const x=(j=m[0])==null?void 0:j.user,c=x!=null&&x.id&&s.state.members[x.id]?s.state.members[x.id].user:void 0;return t.jsx(Xt,{avatarId:(x==null?void 0:x.id)??(c==null?void 0:c.id)??"typing-user",avatarName:(x==null?void 0:x.name)??(c==null?void 0:c.name)??(x==null?void 0:x.id)??"Typing user",avatarImage:(x==null?void 0:x.image)??(c==null?void 0:c.image),testId:"typing-indicator"})},Xt=({avatarId:e,avatarName:s,avatarImage:n,testId:a})=>t.jsx("div",{className:"str-chat__li str-chat__li--single str-chat__typing-indicator !static","data-testid":a,style:{marginBottom:"var(--messaging-channel-input-spacer-height, 80px)"},children:t.jsxs("div",{className:"str-chat__message str-chat__message-simple str-chat__message--regular str-chat__message--received str-chat__message--other str-chat__message--has-text",children:[t.jsx(de,{className:"str-chat__avatar str-chat__message-sender-avatar",id:e,name:s,image:n??void 0,size:24,shape:"circle"}),t.jsx("div",{className:"str-chat__message-inner mx-0",children:t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsxs("div",{className:"str-chat__message-bubble relative isolate",children:[t.jsx("div",{className:"str-chat__message-text min-h-11 flex items-center",children:t.jsx("div",{className:"str-chat__message-text-inner str-chat__message-simple-text-inner",children:t.jsxs("svg",{"aria-hidden":"true",className:"block overflow-visible",viewBox:"0 0 32 12.3",width:"32",height:"13",overflow:"visible",children:[t.jsx(He,{cx:"4",index:0}),t.jsx(He,{cx:"16",index:1}),t.jsx(He,{cx:"28",index:2})]})})}),t.jsx(Ie,{side:"other"})]})})})]})});function ti(e,s){var a;const n=((a=e==null?void 0:e.state)==null?void 0:a.members)??{};for(const r of Object.values(n)){const i=r==null?void 0:r.user;if(i&&i.id!==s)return i}}const Ls=()=>null,si=({className:e,message:s})=>t.jsxs("div",{className:N("flex items-center justify-center h-full",e),children:[t.jsxs("svg",{viewBox:"0 0 100 100",className:"size-8 fill-pebble",stroke:"none",children:[t.jsx("circle",{cx:"6",cy:"50",r:"6",children:t.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 15 ; 0 -15; 0 15",repeatCount:"indefinite",begin:"0.1"})}),t.jsx("circle",{cx:"30",cy:"50",r:"6",children:t.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 10 ; 0 -10; 0 10",repeatCount:"indefinite",begin:"0.2"})}),t.jsx("circle",{cx:"54",cy:"50",r:"6",children:t.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 5 ; 0 -5; 0 5",repeatCount:"indefinite",begin:"0.3"})})]}),s&&t.jsx("span",{className:"text-stone",children:s})]}),Ae=h.memo(()=>t.jsx("div",{className:"messaging-loading-state flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center",children:[t.jsx(si,{className:"w-6 h-6"}),t.jsx("span",{className:"text-sm text-stone",children:"Loading messages"})]})}));Ae.displayName="LoadingState";const ni=({onBack:e,showBackButton:s,renderMessageInputActions:n,renderMessageInputFooter:a,renderConversationFooter:r,onLeaveConversation:i,onBlockParticipant:l,showDeleteConversation:o=!0,onDeleteConversationClick:d,onBlockParticipantClick:u,onReportParticipantClick:f,showBlockParticipant:m=!0,showReportParticipant:x=!0,composerDisabled:c=!1,composerDisabledReason:v,showStarButton:j=!1,renderChannelBanner:p,customChannelActions:g,renderChannelActions:b,renderMessage:y,viewerLanguage:_,showChannelInfo:R=!0,onParticipantNameClick:L,onOutboundClick:I,resolveOutbound:z,composerInput:F})=>{const{channel:M,messages:T}=w.useChannelStateContext(),D=h.useRef(I);h.useEffect(()=>{D.current=I},[I]);const E=h.useCallback(q=>{var X;(X=D.current)==null||X.call(D,q)},[]),k=I?E:void 0,A=Bn(T,z),O=M.state.messages.some(q=>q.type!=="deleted"),B=p?t.jsx(h.Fragment,{children:p()},"lt-channel-banner"):null,H=t.jsx(sn,{className:"-mx-[var(--str-chat\\_\\_spacing-2)] px-[var(--str-chat\\_\\_spacing-2)] md:-mx-[min(var(--str-chat\\_\\_spacing-10),4%)] md:px-[min(var(--str-chat\\_\\_spacing-10),4%)]",onBack:e,showBackButton:s,showChannelInfo:R,showStarButton:j,onLeaveConversation:i,onBlockParticipant:l,showDeleteConversation:o,showBlockParticipant:m,showReportParticipant:x,onDeleteConversationClick:d,onBlockParticipantClick:u,onReportParticipantClick:f,customChannelActions:g,renderChannelActions:b,onParticipantNameClick:L}),Z=h.useCallback(q=>{const{message:X}=w.useMessageContext("ChannelView"),U=t.jsx(Dr,{...q,viewerLanguage:_,onOutboundClick:k});return!y||!X?U:y(U,X)},[k,y,_]);return t.jsx(fs.Provider,{value:A,children:t.jsx(w.WithComponents,{overrides:{Message:Z,MessageActions:Fr,UnreadMessagesNotification:()=>null,UnreadMessagesSeparator:()=>null},children:t.jsx(w.Window,{children:F?t.jsxs("div",{className:"messaging-channel-layout relative flex min-h-0 flex-1 flex-col",children:[t.jsxs("div",{className:"messaging-channel-message-list messaging-channel-message-list--floating relative min-h-0 flex-1 overflow-hidden",children:[!O&&t.jsx("div",{className:"str-chat__list",children:t.jsxs("div",{className:"str-chat__message-list-scroll",children:[H,B]})}),t.jsx(w.MessageList,{head:O?t.jsxs("div",{className:"sticky top-0 z-10",children:[H,B]}):void 0,hideDeletedMessages:!0,hideNewMessageSeparator:!1})]},"lt-channel-message-list"),t.jsx(qt,{...n&&{renderActions:()=>n==null?void 0:n(M)},...r&&{renderHeader:()=>r(M)},renderFooter:()=>a==null?void 0:a(M),disabled:c,disabledReason:v,composerInput:F},"lt-channel-message-input")]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[!O&&t.jsx("div",{className:"str-chat__list",children:t.jsxs("div",{className:"str-chat__message-list-scroll",children:[H,B]})}),t.jsx(w.MessageList,{head:O?t.jsxs("div",{className:"sticky top-0 z-10",children:[H,B]}):void 0,hideDeletedMessages:!0,hideNewMessageSeparator:!1})]},"lt-channel-message-list"),r?t.jsx(h.Fragment,{children:r(M)},"lt-channel-conversation-footer"):null,t.jsx(qt,{...n&&{renderActions:()=>n==null?void 0:n(M)},renderFooter:()=>a==null?void 0:a(M),disabled:c,disabledReason:v,composerInput:F},"lt-channel-message-input")]})})})})},xt=h.memo(({channel:e,onBack:s,showBackButton:n=!1,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:l,onBlockParticipant:o,className:d,CustomChannelEmptyState:u=Ls,showDeleteConversation:f=!0,onDeleteConversationClick:m,onBlockParticipantClick:x,onReportParticipantClick:c,showBlockParticipant:v=!0,showReportParticipant:j=!0,composerDisabled:p=!1,composerDisabledReason:g,dmAgentEnabled:b,messageMetadata:y,onMessageSent:_,showStarButton:R=!1,renderChannelBanner:L,customChannelActions:I,renderChannelActions:z,renderMessage:F,onMessageLinkClick:M,sendButton:T,attachmentPreviewList:D,viewerLanguage:E,showChannelInfo:k=!0,onParticipantNameClick:A,onOutboundClick:O,resolveOutbound:B,composerInput:H})=>{const Z=h.useCallback(async(U,S,P)=>{var ie;const G=((ie=e.data)==null?void 0:ie.chatbot_paused)===!0,$=b&&!G,K={...S,...$&&{silent:!0},...y&&{metadata:{...S.metadata??{},...y}}},W={...P,...$&&{skip_push:!0}},Q=await e.sendMessage(K,W);return _==null||_(Q),Q},[e,b,y,_]),q=h.useRef(null);h.useEffect(()=>{if(!M)return;const U=q.current;if(!U)return;const S=P=>{const G=P.target,$=G==null?void 0:G.closest("a[href]"),K=$==null?void 0:$.getAttribute("href");if(!K)return;const W=$==null?void 0:$.closest("[data-message-id]"),Q=W==null?void 0:W.getAttribute("data-message-id"),ie=Q?e.state.messages.find(te=>te.id===Q):void 0;M(K,ie)};return U.addEventListener("click",S),()=>U.removeEventListener("click",S)},[M,e]);const X=Y.isOfficialChannel(e.type)?{"--lt-msg-card-width":"368px"}:void 0;return t.jsx("div",{ref:q,className:N("messaging-channel-view h-full flex flex-col",d),style:X,children:t.jsx(Ms.Provider,{value:b??!1,children:t.jsx(w.Channel,{channel:e,MessageSystem:Jr,EmptyStateIndicator:u,LoadingIndicator:Ae,DateSeparator:nn,TypingIndicator:ei,doSendMessageRequest:Z,...T?{SendButton:T}:{},...D?{AttachmentPreviewList:D}:{},children:t.jsx(ni,{onBack:s,showBackButton:n,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:l,onBlockParticipant:o,CustomChannelEmptyState:u,showDeleteConversation:f,onDeleteConversationClick:m,onBlockParticipantClick:x,onReportParticipantClick:c,showBlockParticipant:v,showReportParticipant:j,composerDisabled:p,composerDisabledReason:g,showStarButton:R,renderChannelBanner:L,customChannelActions:I,renderChannelActions:z,renderMessage:F,viewerLanguage:E,showChannelInfo:k,onParticipantNameClick:A,onOutboundClick:O,resolveOutbound:B,composerInput:H})})})})});xt.displayName="ChannelView";const pe=h.memo(({message:e,onBack:s})=>t.jsx("div",{className:"messaging-error-state flex items-center justify-center h-full p-8",children:t.jsxs("div",{className:"text-center max-w-sm",children:[t.jsx("div",{className:"w-24 h-24 bg-danger-alt/20 rounded-full flex items-center justify-center mx-auto mb-6",children:t.jsx("span",{className:"text-4xl",children:"⚠️"})}),t.jsx("h2",{className:"font-semibold text-charcoal mb-2",children:"Oops!"}),t.jsx("p",{className:"text-stone text-sm mb-6",children:e}),s&&t.jsx("button",{type:"button",onClick:s,className:"inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-[#7f22fe] hover:bg-primary-alt rounded-lg transition-colors focus-ring",children:"Go Back"})]})}));pe.displayName="ErrorState";const ai=({capabilities:e={},renderMessageInputActions:s,renderConversationFooter:n,onChannelSelect:a,onExitConversation:r,initialParticipantFilter:i,initialParticipantData:l,CustomChannelEmptyState:o,onBlockParticipantClick:d,onReportParticipantClick:u,dmAgentEnabled:f,onMessageSent:m,viewerLanguage:x,renderChannelBanner:c,customChannelActions:v,renderChannelActions:j,onParticipantNameClick:p,onOutboundClick:g,resolveOutbound:b,renderMessage:y,onMessageLinkClick:_,showChannelInfo:R,composerInput:L})=>{const{client:I,isConnected:z,isLoading:F,error:M,refreshConnection:T,service:D,debug:E}=Qt(),[k,A]=h.useState(null),[O,B]=h.useState(null),[H,Z]=h.useState(!1),{showDeleteConversation:q=!0}=e,X=h.useRef(l);X.current=l;const U=h.useRef(a);U.current=a;const S=h.useRef(null),P=h.useRef(null);h.useEffect(()=>{P.current=k},[k]),h.useEffect(()=>{if(!I||!z)return;const K=I.userID;if(!K)return;const W=`${K}::${i}`;if(S.current===W)return;S.current=W;const Q=()=>{S.current===W&&(S.current=null)};(async()=>{var te,Ce;try{E&&console.log("[MessagingShell] Loading initial conversation with:",i);const ee=await I.queryChannels({type:"messaging",members:{$eq:[K,i]}},{},{limit:1});if(ee.length>0){A(ee[0]),B(null),(te=U.current)==null||te.call(U,ee[0]),E&&console.log("[MessagingShell] Initial conversation loaded:",ee[0].id);return}const oe=X.current;if(!oe||!D){Q(),B("No conversation found with this account"),E&&console.log("[MessagingShell] No conversation found for:",i);return}try{const re=await D.startChannelWithParticipant({id:oe.id,name:oe.name,phone:oe.phone});A(re),B(null),(Ce=U.current)==null||Ce.call(U,re),E&&console.log("[MessagingShell] Channel created and loaded:",re.id)}catch(re){console.error("[MessagingShell] Failed to create conversation:",re),Q(),B("Failed to create conversation")}}catch(ee){console.error("[MessagingShell] Failed to load initial conversation:",ee),Q(),P.current||B("Failed to load conversation")}})()},[i,I,z,D,E]);const G=h.useRef(r);G.current=r;const $=h.useCallback(()=>{var K;A(null),Z(!0),(K=G.current)==null||K.call(G)},[]);return F?t.jsx(Ae,{}):M?t.jsx(pe,{message:M,onBack:T}):!z||!I?t.jsx(pe,{message:"Not connected to messaging service",onBack:T}):O?t.jsx(pe,{message:O}):H&&!k?t.jsx(pe,{message:"Conversation ended"}):k?t.jsx("div",{className:"messaging-shell h-full bg-background-primary overflow-hidden",children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:t.jsx(xt,{channel:k,renderMessageInputActions:s,renderConversationFooter:n,renderChannelBanner:c,onLeaveConversation:$,onBlockParticipant:$,CustomChannelEmptyState:o,showDeleteConversation:q,onBlockParticipantClick:d,onReportParticipantClick:u,dmAgentEnabled:f,onMessageSent:m,viewerLanguage:x,customChannelActions:v,renderChannelActions:j,onParticipantNameClick:p,onOutboundClick:g,resolveOutbound:b,renderMessage:y,onMessageLinkClick:_,showChannelInfo:R,composerInput:L},k.id)})}):t.jsx(Ae,{})};function ri(e){const s=e.state.pending_messages;if(s!=null&&s.length)for(const n of s)e.state.addMessageSorted(n.message)}const Ds=h.createContext({selectedChannel:void 0,onChannelSelect:()=>{},debug:!1,renderMessagePreview:void 0,channelPreview:void 0,viewerLanguage:void 0}),ii=Ds.Provider,oi=()=>h.useContext(Ds),li=(e,s)=>{const n=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()),a=Date.UTC(s.getFullYear(),s.getMonth(),s.getDate());return Math.floor((a-n)/(1e3*60*60*24))},Ps=e=>{const s=new Date;if(Math.floor((s.getTime()-e.getTime())/1e3)<60)return"Just now";const a=li(e,s);return a===0?e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0}):a===1?"Yesterday":a<7?e.toLocaleDateString(void 0,{weekday:"short"}):e.getFullYear()===s.getFullYear()?e.toLocaleDateString(void 0,{month:"short",day:"numeric"}):e.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})},Os=h.memo(e=>{var z,F,M;const{channel:s,unread:n}=e,{selectedChannel:a,onChannelSelect:r,debug:i,channelPreview:l,renderMessagePreview:o,viewerLanguage:d}=oi(),{client:u}=w.useChatContext(),f=(a==null?void 0:a.id)===(s==null?void 0:s.id),m=es(s);if(l){const T=l;return t.jsx(T,{...e,active:f,selectedChannel:a,onChannelSelect:r,viewerLanguage:d})}const x=()=>{s&&r(s)},c=T=>{const D=T.key==="Enter"||T.key===" ",E=T.repeat;!D||E||(T.preventDefault(),x())},v=qe((z=s==null?void 0:s.state)==null?void 0:z.members,u==null?void 0:u.userID,s==null?void 0:s.type),j=Xe(v==null?void 0:v.user),p=(F=v==null?void 0:v.user)==null?void 0:F.image,g=(()=>{var D;const T=(D=s==null?void 0:s.state)==null?void 0:D.messages;if(T!=null&&T.length){for(let E=T.length-1;E>=0;E--)if(T[E].type!=="system")return T[E]}})(),y=(()=>{var A;const T=Ke({message:g,viewerLanguage:d}),{custom_type:D,attachment_content_type:E}=(g==null?void 0:g.metadata)||{};if(D===Y.MESSAGE_CUSTOM_TYPE.TIP)return T||"Sent a tip";if(D===Y.MESSAGE_CUSTOM_TYPE.PAID)return T||"Sent a message";if(D===Y.MESSAGE_CUSTOM_TYPE.ATTACHMENT){if(E==="text")return"🔒 Sent a locked message";if(E==="media")return"🔒 Sent a locked attachment"}if(T)return T;const k=(A=g==null?void 0:g.attachments)==null?void 0:A[0];return k?k.og_scrape_url?k.og_scrape_url:k.type==="image"?"📷 Sent an image":k.type==="video"?"🎥 Sent a video":k.type==="audio"?"🎵 Sent audio":k.type==="file"?"📎 Sent a file":"📎 Sent an attachment":"No messages yet"})(),_=g!=null&&g.created_at?Ps(new Date(g.created_at)):"",R=g?Ee(g):!1,L=o?o(g,y):`${R?"✨ ":""}${y}`,I=n??0;return i&&console.log("📺 [ChannelList] 📋 CHANNEL PREVIEW RENDER",{channelId:s==null?void 0:s.id,isSelected:f,participantName:j,unreadCount:I,hasTimestamp:!!_}),t.jsx("div",{role:"button",tabIndex:0,onClick:x,onKeyDown:c,className:N("group w-full px-4 py-3 transition-colors text-left max-w-full overflow-hidden focus-ring rounded-[12px] [&+&]:mt-2",{"bg-black/[0.04]":f,"hover:bg-black/[0.02]":!f}),"data-dd-privacy":"mask",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx(de,{id:((M=v==null?void 0:v.user)==null?void 0:M.id)||s.id||"unknown",name:j,image:p,size:48,starred:m}),t.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("h3",{className:N("text-sm font-medium truncate text-[#191918]"),children:[m&&t.jsx("span",{className:"sr-only",children:"Starred conversation. "}),j]}),_&&t.jsx("span",{className:"text-xs text-[#717070] flex-shrink-0",children:_})]}),t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[t.jsx("p",{className:"text-sm text-[#717070] flex-1 line-clamp-1",children:L}),I>0&&t.jsx("span",{className:"bg-[#7f22fe] text-white text-[10px] rounded-full h-4 flex items-center justify-center p-1 min-w-4 text-center flex-shrink-0",children:I>99?"99+":I})]})]})]})})});Os.displayName="CustomChannelPreview";const ci={last_message_at:-1},Fs=h.memo(({onChannelSelect:e,selectedChannel:s,filters:n,allowNewMessagesFromUnfilteredChannels:a=!1,channelRenderFilterFn:r,sort:i=ci,className:l,customEmptyStateIndicator:o,channelListPaginator:d=w.InfiniteScroll,channelPreview:u,renderMessagePreview:f,viewerLanguage:m,lockChannelOrder:x,onMessageNewHandler:c,onMessageNew:v,onChannelVisible:j,onAddedToChannel:p,onChannelUpdated:g})=>{const b=h.useRef(0);b.current++;const{debug:y=!1}=We(),_=h.useCallback(L=>{for(const I of L)ri(I);return r?r(L):L},[r]);y&&console.log("📺 [ChannelList] 🔄 RENDER START",{renderCount:b.current,selectedChannelId:s==null?void 0:s.id,filters:n});const R=h.useMemo(()=>({selectedChannel:s,onChannelSelect:e,debug:y,channelPreview:u,renderMessagePreview:f,viewerLanguage:m}),[s,e,y,u,f,m]);return t.jsx("div",{className:N("messaging-channel-list h-full flex flex-col min-w-0 overflow-hidden",l),children:t.jsx("div",{className:"flex-1 overflow-hidden min-w-0",children:t.jsx(ii,{value:R,children:t.jsx(w.ChannelList,{filters:n,sort:i,options:{limit:30},allowNewMessagesFromUnfilteredChannels:a,channelRenderFilterFn:_,lockChannelOrder:x,onMessageNewHandler:c,onMessageNew:v,onChannelVisible:j,onAddedToChannel:p,onChannelUpdated:g,Paginator:d,Preview:Os,EmptyStateIndicator:o},`${JSON.stringify(n)}:${JSON.stringify(i)}`)})})})});Fs.displayName="ChannelList";const di="line-clamp-2 text-[14px] font-medium leading-5 tracking-[0.28px] [text-wrap:balance]",ui="text-[12px] leading-4 tracking-[0.24px] [text-wrap:pretty]",Kt=({surface:e,actions:s,layout:n})=>{if(s==null||s.length===0)return null;const a=n==="stacked";return t.jsx("div",{className:N("flex gap-2",a?"mt-3 flex-col":"min-w-0 max-w-[60%] flex-row flex-wrap justify-end"),children:s.map((r,i)=>t.jsx(xs,{variant:e,cta:r,fullWidth:a,standalone:!0},`${r.label}-${i}`))})},mi=({ctaSurface:e,chinTextColor:s,title:n,subtitle:a,subtitleLines:r=3,appIcon:i,actions:l})=>{var v;const o=n!=null&&n.trim()!=="",d=a!=null&&a.trim()!=="",u=l!=null&&l.length>0;if(!o&&!d&&!u)return null;const f={color:s},m=r>1?{...f,display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:r,overflow:"hidden"}:f,x=u&&(((v=l==null?void 0:l[0])==null?void 0:v.variant)??"primary")==="secondary",c=t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-[2px]",children:[o&&t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i?t.jsx("span",{className:"shrink-0",children:i}):null,t.jsx("p",{className:N("min-w-0",di),style:f,children:n})]}),d&&t.jsx("p",{className:N(ui,r>1&&"whitespace-pre-line",r<=1&&"truncate"),style:m,children:a})]});return t.jsx("div",{className:"shrink-0 px-4 py-3",children:x?t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[c,t.jsx(Kt,{surface:e,actions:l,layout:"row"})]}):t.jsxs(t.Fragment,{children:[c,t.jsx(Kt,{surface:e,actions:l,layout:"stacked"})]})})},hi={dark:"bg-white/[0.06]",light:"bg-black/[0.04]"},fi={1:[0],2:[-10,10],3:[-13,0,13]},xi={1:[0],2:[-26,26],3:[-40,0,40]},gi={1:[0],2:[0,1],3:[1,3,2]},pi={1:[1],2:[1,1],3:[1,1.08,1]},bi=({variant:e,images:s})=>{const[n,a]=h.useState({}),r=s.join(`
2
+ `),[i,l]=h.useState(r);r!==i&&(l(r),a({}));const o=s.slice(0,3).map((c,v)=>({src:c,index:v})).filter(({index:c})=>!n[c]),d=o.length>=3?3:o.length===2?2:1,u=fi[d],f=xi[d],m=gi[d],x=pi[d];return t.jsx("div",{className:N("relative flex min-h-0 w-full flex-1 items-center justify-center overflow-hidden",hi[e]),children:o.map(({src:c,index:v},j)=>t.jsx("img",{src:se(c)??c,alt:"",draggable:!1,loading:"lazy",decoding:"async",onError:()=>a(p=>({...p,[v]:!0})),className:"absolute left-1/2 top-1/2 w-[62%] aspect-[3/2] rounded-[12px] bg-[#ffffff] object-cover shadow-md",style:{transform:`translate(-50%, -50%) translateX(${f[j]}px) rotate(${u[j]}deg) scale(${x[j]})`,zIndex:m[j]}},`${c}-${v}`))})},vi="flex h-[180px] w-full shrink-0 flex-col overflow-hidden",ji=({variant:e,presentation:s,images:n,title:a,heroUrl:r,onHeroError:i})=>t.jsx("div",{className:vi,children:s==="fan"?t.jsx(bi,{variant:e,images:n}):t.jsx(ve,{variant:e,thumbnailUrl:r,title:a,mimeType:"image/*",onImageError:i})}),zs=({variant:e,title:s,subtitle:n,subtitleLines:a,images:r=[],imagePresentation:i,actions:l,appIcon:o,accentColor:d,groupPosition:u="single"})=>{const f=Y.resolveRichCardImagePresentation({imagePresentation:i,images:r}),m=r.length>0,x=m&&f==="hero",c=De({variant:e,accentColor:d,layout:"featured",thumbnailUrl:x?r[0]:void 0}),v=u==="single"||u==="end";return t.jsx(ot,{accentHex:c.accentHex,side:e==="dark"?"sender":"receiver",visible:v,children:t.jsxs(be,{variant:e,accentHex:c.accentHex,"data-testid":"rich-card",children:[m&&t.jsx(ji,{variant:e,presentation:f,images:r,title:s,heroUrl:x?c.thumbnailUrl:void 0,onHeroError:c.onImageError}),t.jsx(mi,{ctaSurface:c.surface,chinTextColor:c.chinTextColor,title:s,subtitle:n,subtitleLines:a,appIcon:o,actions:l})]})})},wi=e=>t.jsx(zs,{...e,variant:"dark"}),_i=e=>t.jsx(zs,{...e,variant:"light"}),yi={Sent:wi,Received:_i},Zt=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='23' fill='none'%3E%3Cpath fill='black' d='M0 0H15C15 10.1934 15.859 15.2345 19.168 21.4893C19.527 22.168 19.039 22.9917 18.274 22.9178C5.176 21.6506 0.32 6.0737 0 0Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%`,Ni={sent:"var(--str-chat__own-message-bubble-background-color, #1e2330)",received:"var(--str-chat__message-bubble-background-color, #f1f0ee)"},Ci=({variant:e})=>t.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute bottom-0 z-[-1] h-[1.4375rem] w-5",style:{insetInlineEnd:e==="sent"?"calc(-1 * 0.25rem)":void 0,insetInlineStart:e==="received"?"calc(-1 * 0.25rem)":void 0,transform:e==="received"?"scaleX(-1)":void 0,transformOrigin:"center",backgroundColor:Ni[e],WebkitMask:Zt,mask:Zt}}),Si={sent:{backgroundColor:"var(--str-chat__own-message-bubble-background-color, #1e2330)",color:"var(--str-chat__own-message-bubble-color, #fff)"},received:{backgroundColor:"var(--str-chat__message-bubble-background-color, #f1f0ee)",color:"var(--str-chat__message-bubble-color, #000000)"}},Bs=({variant:e,text:s,tail:n=!0,header:a,className:r})=>t.jsxs("div",{"data-dd-privacy":"mask",className:N("relative px-4 py-3","text-[0.875rem] leading-[1.3125rem] tracking-[0.14px]",r),style:{...Si[e],borderRadius:"var(--str-chat__message-bubble-border-radius, 1.5rem)",isolation:"isolate"},children:[a!=null&&t.jsx("div",{className:"mb-1 font-medium","data-testid":"message-bubble-header",children:a}),t.jsx("p",{className:"m-0 whitespace-pre-wrap break-words hyphens-manual",children:s}),n&&t.jsx(Ci,{variant:e})]}),ki=({text:e,tail:s,header:n,className:a})=>t.jsx(Bs,{variant:"received",text:e,tail:s,header:n,className:a}),Ei=({text:e,tail:s,className:n})=>t.jsx(Bs,{variant:"sent",text:e,tail:s,className:n}),Ii={Sent:Ei,Received:ki},$s=({question:e,onClick:s,loading:n=!1,className:a})=>t.jsx("button",{type:"button",onClick:s,disabled:n,style:{backgroundColor:"#E6E5E3"},className:N("w-full text-center p-4 rounded-xl text-charcoal font-medium transition-colors focus-ring",{"hover:brightness-95 active:brightness-90":!n,"opacity-50 cursor-not-allowed":n},a),children:e}),Ti=({faqs:e,onFaqClick:s,loadingFaqId:n,headerText:a,className:r,avatarImage:i,avatarName:l})=>{const o=Y.selectEnabledFaqs(e);return o.length===0?null:t.jsx("div",{className:r,children:t.jsxs("div",{className:"flex gap-3 items-end",children:[(i||l)&&t.jsx("div",{className:"flex-none",children:t.jsx(de,{id:l||"account",name:l||"Account",image:i,size:24,shape:"circle"})}),t.jsxs("div",{className:"flex-1 flex flex-col gap-3 rounded-lg p-4",style:{backgroundColor:"#F1F0EE"},children:[a&&t.jsx("p",{className:"text-md text-charcoal mb-4",children:a}),o.map(d=>t.jsx($s,{question:d.question,onClick:()=>s(d.id),loading:n===d.id},d.id))]})]})})};exports.ActionButton=he;exports.AttachmentThumbnail=Ze;exports.Avatar=de;exports.ChannelEmptyState=Ls;exports.ChannelList=Fs;exports.ChannelView=xt;exports.CustomMessageProvider=En;exports.FaqList=Ti;exports.FaqListItem=$s;exports.LinkAttachment=Te;exports.LockedAttachment=ge;exports.MediaMessage=Cn;exports.MessageAttachment=fe;exports.MessageBubble=Ii;exports.MessagingProvider=Ys;exports.MessagingShell=ai;exports.RichCard=yi;exports.bubbleGroupPositionFromStream=xa;exports.buildCompactMetaLabel=vs;exports.formatFileSize=ps;exports.formatRelativeTime=Ps;exports.getFileExtensionLabel=bs;exports.getMessageDisplayText=Ke;exports.getSourceType=ae;exports.isLinkAttachment=je;exports.isUuidLike=ts;exports.normalizeLanguageCode=ns;exports.optimizeMessagingAttachmentUrl=se;exports.renderTypeIcon=ce;exports.resolveConversationParticipant=qe;exports.resolveLinkAttachment=Me;exports.resolveMediaFromMessage=Le;exports.resolveParticipantDisplayName=Xe;exports.useComposerLocked=Ur;exports.useCustomMessage=ds;exports.useMessaging=Qt;
3
+ //# sourceMappingURL=index-CwkY7QwT.cjs.map