@linktr.ee/messaging-react 3.7.0-rc-1783333034 → 3.7.0-rc-1783334820

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 (40) hide show
  1. package/dist/{Card-C8fHW9JN.js → Card-B00W_V2V.js} +2 -2
  2. package/dist/{Card-C8fHW9JN.js.map → Card-B00W_V2V.js.map} +1 -1
  3. package/dist/{Card-DPysc-d8.js → Card-B22ztgFZ.js} +3 -3
  4. package/dist/{Card-DPysc-d8.js.map → Card-B22ztgFZ.js.map} +1 -1
  5. package/dist/{Card-BApYAXry.js → Card-B6M_Z_2p.js} +2 -2
  6. package/dist/{Card-BApYAXry.js.map → Card-B6M_Z_2p.js.map} +1 -1
  7. package/dist/{Card-CZ6WAwfm.cjs → Card-B9wzbhJO.cjs} +2 -2
  8. package/dist/{Card-CZ6WAwfm.cjs.map → Card-B9wzbhJO.cjs.map} +1 -1
  9. package/dist/{Card-BcTN2501.cjs → Card-Bh7-DiTk.cjs} +2 -2
  10. package/dist/{Card-BcTN2501.cjs.map → Card-Bh7-DiTk.cjs.map} +1 -1
  11. package/dist/{Card-DU_zHX8a.cjs → Card-Qudta4p2.cjs} +2 -2
  12. package/dist/{Card-DU_zHX8a.cjs.map → Card-Qudta4p2.cjs.map} +1 -1
  13. package/dist/{LockedThumbnail-CbK80G-d.js → LockedThumbnail-CrYroEV1.js} +2 -2
  14. package/dist/{LockedThumbnail-CbK80G-d.js.map → LockedThumbnail-CrYroEV1.js.map} +1 -1
  15. package/dist/{LockedThumbnail-Ca-qH-ZE.cjs → LockedThumbnail-DPIsI8LL.cjs} +2 -2
  16. package/dist/{LockedThumbnail-Ca-qH-ZE.cjs.map → LockedThumbnail-DPIsI8LL.cjs.map} +1 -1
  17. package/dist/index-B-1G-O9u.cjs +2 -0
  18. package/dist/index-B-1G-O9u.cjs.map +1 -0
  19. package/dist/{index-CNoa6hhY.js → index-XS-fkenc.js} +6 -4
  20. package/dist/index-XS-fkenc.js.map +1 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.ts +31 -16
  23. package/dist/index.js +1 -1
  24. package/dist/testing.cjs +1 -1
  25. package/dist/testing.cjs.map +1 -1
  26. package/dist/testing.js +59 -48
  27. package/dist/testing.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/components/ChannelView.stories.tsx +4 -24
  30. package/src/components/CustomMessage/CustomMessage.stories.tsx +3 -12
  31. package/src/components/CustomMessageInput/CustomMessageInput.stories.tsx +2 -6
  32. package/src/providers/MessagingProvider.test.tsx +43 -0
  33. package/src/providers/MessagingProvider.tsx +8 -1
  34. package/src/stories/mocks.tsx +4 -20
  35. package/src/testing/createMockMessagingClient.ts +27 -20
  36. package/src/testing/createMockStreamChatClient.ts +44 -0
  37. package/src/types.ts +35 -18
  38. package/dist/index-C1p97mNU.cjs +0 -2
  39. package/dist/index-C1p97mNU.cjs.map +0 -1
  40. package/dist/index-CNoa6hhY.js.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import React from 'react'
2
- import { ConnectionOpen, StreamChat } from 'stream-chat'
3
2
  import { Chat } from 'stream-chat-react'
4
3
 
4
+ import { createMockStreamChatClient } from '../testing/createMockStreamChatClient'
5
+
5
6
  // Mock Stream Chat client for Storybook
6
7
  const mockUser = {
7
8
  id: 'storybook-user',
@@ -9,25 +10,8 @@ const mockUser = {
9
10
  image: 'https://i.pravatar.cc/150?img=1',
10
11
  }
11
12
 
12
- const createMockClient = () => {
13
- const client = new StreamChat('mock-api-key', {
14
- allowServerSideConnect: true,
15
- })
16
-
17
- // Mock the client methods
18
- client.connectUser = async () => {
19
- return { me: mockUser } as unknown as ConnectionOpen
20
- }
21
-
22
- client.disconnectUser = async () => {
23
- return Promise.resolve()
24
- }
25
-
26
- client.userID = mockUser.id
27
- client.user = mockUser
28
-
29
- return client
30
- }
13
+ const createMockClient = () =>
14
+ createMockStreamChatClient(mockUser, { stubConnection: true })
31
15
 
32
16
  export const MockChatProvider: React.FC<{ children: React.ReactNode }> = ({
33
17
  children,
@@ -6,6 +6,8 @@ import type {
6
6
  } from 'stream-chat'
7
7
  import { StreamChat } from 'stream-chat'
8
8
 
9
+ import { createMockStreamChatClient } from './createMockStreamChatClient'
10
+
9
11
  /** A participant in the mock conversation. */
10
12
  export interface MockMessagingUser {
11
13
  id: string
@@ -77,25 +79,15 @@ export function createMockMessagingClient({
77
79
  channelId = 'mock-dm',
78
80
  onSend,
79
81
  }: CreateMockMessagingClientOptions): MockMessagingClient {
80
- const client = new StreamChat('mock-api-key', {
81
- allowServerSideConnect: true,
82
+ // Offline client marked connected without a WebSocket. `stubConnection` also
83
+ // no-ops connectUser/disconnectUser/userMuteStatus: `MessagingProvider`
84
+ // renders `<Chat client={client}>` directly so it never calls connectUser,
85
+ // and handling the `message.new` events dispatched on send + echo below runs
86
+ // Channel._countMessageAsUnread → client.userMuteStatus, which throws offline.
87
+ const client = createMockStreamChatClient(currentUser, {
88
+ stubConnection: true,
82
89
  })
83
90
 
84
- // Mark connected without opening a WebSocket. `MessagingProvider` renders
85
- // `<Chat client={client}>` directly for an injected client, so it never
86
- // calls connectUser itself.
87
- client.connectUser = async () => ({ me: currentUser }) as never
88
- client.disconnectUser = async () => undefined
89
- client.userID = currentUser.id
90
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- client.user = currentUser as any
92
- // Handling a `message.new` event (dispatched on send + echo below) runs
93
- // Channel._countMessageAsUnread → client.userMuteStatus, which throws
94
- // "Make sure to await connectUser() first." without a live WebSocket. Stub
95
- // the mute lookups so offline event dispatch doesn't throw.
96
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
- client.userMuteStatus = (() => false) as any
98
-
99
91
  const cid = `messaging:${channelId}`
100
92
 
101
93
  const toStreamMessage = (
@@ -154,7 +146,11 @@ export function createMockMessagingClient({
154
146
  // Read/unread bookkeeping consults channel mute status; without a live
155
147
  // connection the real method throws, so report "not muted".
156
148
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
- channel.muteStatus = (() => ({ muted: false, createdAt: null, expiresAt: null })) as any
149
+ channel.muteStatus = (() => ({
150
+ muted: false,
151
+ createdAt: null,
152
+ expiresAt: null,
153
+ })) as any
158
154
 
159
155
  // Neutralise the rest of the connection-dependent channel API that
160
156
  // stream-chat-react calls during the chat lifecycle. Each of these POSTs to
@@ -170,6 +166,9 @@ export function createMockMessagingClient({
170
166
  channel.countUnread = (() => 0) as any
171
167
  // Pagination: report no older pages so "load more" resolves to a no-op.
172
168
  channel.query = (async () => ({ messages: [] }) as any) as any
169
+ // Leave/Delete Conversation calls channel.hide(); the real method POSTs to
170
+ // Stream, so no-op it to keep the action working offline.
171
+ channel.hide = (async () => ({}) as any) as any
173
172
  /* eslint-enable @typescript-eslint/no-explicit-any */
174
173
 
175
174
  // Seed state locally instead of fetching. Mirrors the proven ChannelView
@@ -211,13 +210,17 @@ export function createMockMessagingClient({
211
210
  }
212
211
 
213
212
  let sentCount = 0
213
+ let replyCount = 0
214
214
  channel.sendMessage = async (message) => {
215
215
  const text =
216
216
  typeof message === 'string'
217
217
  ? message
218
218
  : ((message as { text?: string })?.text ?? '')
219
219
  const sent = {
220
- ...toStreamMessage({ text, from: 'me', id: `mock-sent-${sentCount++}` }, seededMessages.length),
220
+ ...toStreamMessage(
221
+ { text, from: 'me', id: `mock-sent-${sentCount++}` },
222
+ seededMessages.length
223
+ ),
221
224
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
222
225
  ...(typeof message === 'object' ? (message as any) : {}),
223
226
  user: currentUser,
@@ -233,6 +236,10 @@ export function createMockMessagingClient({
233
236
  const replyText = typeof reply === 'string' ? reply : reply.text
234
237
  const replyAttachments =
235
238
  typeof reply === 'string' ? undefined : reply.attachments
239
+ // Capture a unique id before scheduling: two sends within REPLY_DELAY_MS
240
+ // would otherwise both read the same later `sentCount` at fire time and
241
+ // emit colliding reply ids, so Stream's id-based dedupe drops one echo.
242
+ const replyId = `mock-reply-${replyCount++}`
236
243
  setTimeout(() => {
237
244
  appendMessage(
238
245
  toStreamMessage(
@@ -241,7 +248,7 @@ export function createMockMessagingClient({
241
248
  from: 'them',
242
249
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
250
  attachments: replyAttachments as any,
244
- id: `mock-reply-${sentCount}`,
251
+ id: replyId,
245
252
  },
246
253
  seededMessages.length
247
254
  )
@@ -0,0 +1,44 @@
1
+ import { StreamChat } from 'stream-chat'
2
+
3
+ import type { MockMessagingUser } from './createMockMessagingClient'
4
+
5
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
+
7
+ export interface CreateMockStreamChatClientOptions {
8
+ /**
9
+ * Also replace the connection-dependent client methods (`connectUser`,
10
+ * `disconnectUser`, `userMuteStatus`) with offline no-ops. Needed when the
11
+ * client drives a flow that would otherwise open a WebSocket or throw
12
+ * "Make sure to await connectUser() first." offline. Direct `<Chat client>`
13
+ * rendering (e.g. component stories) does not need this.
14
+ */
15
+ stubConnection?: boolean
16
+ }
17
+
18
+ /**
19
+ * Builds an offline `StreamChat` for mocks and stories: a real client on a
20
+ * throwaway api key with `userID`/`user` set so `<Chat>` treats it as
21
+ * connected without a backend. The single place that knows how to construct a
22
+ * connectionless Stream client, so a stream-chat version bump only needs
23
+ * updating here rather than in each mock surface.
24
+ */
25
+ export function createMockStreamChatClient(
26
+ user: MockMessagingUser,
27
+ { stubConnection = false }: CreateMockStreamChatClientOptions = {}
28
+ ): StreamChat {
29
+ const client = new StreamChat('mock-api-key', {
30
+ allowServerSideConnect: true,
31
+ })
32
+ client.userID = user.id
33
+ client.user = user as any
34
+
35
+ if (stubConnection) {
36
+ client.connectUser = async () => ({ me: user }) as any
37
+ client.disconnectUser = async () => undefined
38
+ client.userMuteStatus = (() => false) as any
39
+ }
40
+
41
+ return client
42
+ }
43
+
44
+ /* eslint-enable @typescript-eslint/no-explicit-any */
package/src/types.ts CHANGED
@@ -443,26 +443,43 @@ export interface MessagingShellProps extends ChannelViewPassthroughProps {
443
443
  initialParticipantData?: Participant
444
444
  }
445
445
 
446
- /**
447
- * MessagingProvider component props
448
- */
449
- export interface MessagingProviderProps {
446
+ interface MessagingProviderBaseProps {
450
447
  children: React.ReactNode
451
448
  user: MessagingUser | null
452
- /**
453
- * An already-constructed Stream client. When provided it takes precedence
454
- * over `apiKey`: the provider renders `<Chat>` against this exact instance
455
- * and does NOT create a StreamChatService or call `connectUser` — the caller
456
- * owns the client's connection lifecycle. This is the seam for offline/dev
457
- * (`createMockMessagingClient` from `@linktr.ee/messaging-react/testing`) and
458
- * for tests, so consumers render the real UI instead of forking it.
459
- * `apiKey`/`serviceConfig` are ignored while `client` is set.
460
- */
461
- client?: StreamChat
462
- /** Required unless `client` is provided. */
463
- serviceConfig?: Omit<StreamChatServiceConfig, 'apiKey'>
464
- /** Required unless `client` is provided. */
465
- apiKey?: string
466
449
  capabilities?: MessagingCapabilities
467
450
  debug?: boolean
468
451
  }
452
+
453
+ /**
454
+ * Injected-client mode: the provider renders `<Chat>` against an
455
+ * already-constructed Stream client and does NOT create a StreamChatService or
456
+ * call `connectUser` — the caller owns the client's connection lifecycle. This
457
+ * is the seam for offline/dev (`createMockMessagingClient` from
458
+ * `@linktr.ee/messaging-react/testing`) and for tests, so consumers render the
459
+ * real UI instead of forking it. `apiKey`/`serviceConfig` are not used here.
460
+ */
461
+ interface MessagingProviderInjectedClientProps extends MessagingProviderBaseProps {
462
+ client: StreamChat
463
+ apiKey?: never
464
+ serviceConfig?: never
465
+ }
466
+
467
+ /**
468
+ * apiKey mode: the provider builds its own Stream client from `apiKey` and owns
469
+ * the connect/disconnect lifecycle. Both fields are required so a non-injected
470
+ * consumer cannot compile a provider that never connects.
471
+ */
472
+ interface MessagingProviderApiKeyProps extends MessagingProviderBaseProps {
473
+ client?: undefined
474
+ apiKey: string
475
+ serviceConfig: Omit<StreamChatServiceConfig, 'apiKey'>
476
+ }
477
+
478
+ /**
479
+ * MessagingProvider component props. Either an injected `client` (caller owns
480
+ * the lifecycle) or an `apiKey` + `serviceConfig` (provider owns it) — never
481
+ * neither.
482
+ */
483
+ export type MessagingProviderProps =
484
+ | MessagingProviderInjectedClientProps
485
+ | MessagingProviderApiKeyProps
@@ -1,2 +0,0 @@
1
- "use strict";const t=require("react/jsx-runtime"),u=require("react"),Is=require("@linktr.ee/messaging-core"),Pe=require("stream-chat"),N=require("stream-chat-react"),j=require("@phosphor-icons/react"),k=require("classnames"),Ge=require("stream-chat-react/experimental"),Ot=u.createContext({service:null,client:null,isConnected:!1,isLoading:!1,error:null,capabilities:{},refreshConnection:async()=>{},debug:!1}),He=()=>u.useContext(Ot),Es=({children:e,user:s,serviceConfig:n,apiKey:a,capabilities:r={},debug:i=!1,client:l})=>{var I,L;const o=u.useCallback((E,...z)=>{i&&console.log(`🔥 [MessagingProvider] ${E}`,...z)},[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,m]=u.useState(null),[f,x]=u.useState(null),[h,c]=u.useState(!1),[b,w]=u.useState(!1),[p,g]=u.useState(null),v=u.useRef(!1),y=u.useRef(null),S=u.useRef(n);S.current=n;const A=u.useRef(i);A.current=i;const M=u.useRef({userId:s==null?void 0:s.id,apiKey:a,serviceConfig:n,capabilities:r}),D=u.useRef(0);D.current++,o("📊 RENDER INFO",{renderCount:D.current,currentProps:{userId:s==null?void 0:s.id,apiKey:(a==null?void 0:a.substring(0,8))+"..."},propChanges:{userChanged:M.current.userId!==(s==null?void 0:s.id),apiKeyChanged:M.current.apiKey!==a,serviceConfigChanged:M.current.serviceConfig!==n,capabilitiesChanged:M.current.capabilities!==r}}),M.current={userId:s==null?void 0:s.id,apiKey:a,serviceConfig:n,capabilities:r};const B=u.useRef(null);!l&&a&&((I=B.current)==null?void 0:I.apiKey)!==a&&(B.current={apiKey:a,client:new Pe.StreamChat(a)});const O=l||(a?((L=B.current)==null?void 0:L.client)??null:null);u.useEffect(()=>{const E=D.current,z=S.current;if(l)return;if(!a||!O||!z){o("⚠️ SERVICE INIT SKIPPED",{renderCount:E,reason:"Missing apiKey, client, or serviceConfig"});return}o("🚀 CREATING SERVICE",{renderCount:E,apiKey:(a==null?void 0:a.substring(0,8))+"..."});const $=new Is.StreamChatService({...z,apiKey:a,debug:A.current,client:O});y.current=$,m($),o("✅ SERVICE SET",{renderCount:E,serviceInstance:!!$})},[a,O,l]);const F=u.useRef(null);u.useEffect(()=>{var z,$;if(o("🔗 USER CONNECTION EFFECT TRIGGERED",{hasService:!!d,hasUser:!!s,userId:s==null?void 0:s.id,isConnecting:v.current,isConnected:h,dependencies:{service:!!d,userId:s==null?void 0:s.id}}),!d||!s){o("⚠️ USER CONNECTION SKIPPED","Missing service or user");return}if(v.current){o("⚠️ USER CONNECTION SKIPPED","Already connecting");return}if(((z=F.current)==null?void 0:z.serviceId)===d&&(($=F.current)==null?void 0:$.userId)===s.id){o("⚠️ USER CONNECTION SKIPPED","Already connected this user with this service");return}(async()=>{o("🚀 STARTING USER CONNECTION",{userId:s.id}),v.current=!0,w(!0),g(null);try{o("📞 CALLING SERVICE.CONNECTUSER",{userId:s.id});const V=await d.connectUser(s);x(V),c(!0),F.current={serviceId:d,userId:s.id},o("✅ USER CONNECTION SUCCESS",{userId:s.id,clientId:V.userID})}catch(V){const X=V instanceof Error?V.message:"Connection failed";g(X),o("❌ USER CONNECTION ERROR",{userId:s.id,error:X})}finally{w(!1),v.current=!1,o("🔄 USER CONNECTION FINISHED",{userId:s.id,isConnected:h})}})()},[d,s,o,h]),u.useEffect(()=>{const E=O;return()=>{var z;E&&(F.current=null,(z=y.current)==null||z.disconnectUser().catch(console.error))}},[O]);const C=u.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}),w(!0);try{o("🔌 DISCONNECTING FOR REFRESH"),await d.disconnectUser(),o("📞 RECONNECTING FOR REFRESH");const E=await d.connectUser(s);x(E),c(!0),g(null),o("✅ CONNECTION REFRESH SUCCESS",{userId:s.id})}catch(E){const z=E instanceof Error?E.message:"Refresh failed";g(z),o("❌ CONNECTION REFRESH ERROR",{userId:s.id,error:z})}finally{w(!1),o("🔄 CONNECTION REFRESH FINISHED",{userId:s.id})}}},[d,s,o,l]),T=u.useMemo(()=>(o("💫 CONTEXT VALUE MEMOIZATION",{hasService:!!d,hasClient:!!f,isConnected:h,isLoading:b,hasError:!!p,capabilitiesKeys:Object.keys(r)}),{service:l?null:d,client:l??f,isConnected:l?!0:h,isLoading:l?!1:b,error:l?null:p,capabilities:r,refreshConnection:C,debug:i}),[d,f,l,h,b,p,r,C,i,o]);return o("🔄 RENDER END",{renderCount:D.current,willRenderChat:!!O,contextValueReady:!!T}),t.jsx(Ot.Provider,{value:T,children:O?t.jsx(N.Chat,{client:O,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})},$t=()=>He(),Ye=e=>{var a,r;const[s,n]=u.useState(!!((r=(a=e==null?void 0:e.state)==null?void 0:a.membership)!=null&&r.pinned_at));return u.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},Ts="linktree-official",As="linktree-official-sender";function fe(e,s,n){const a=Object.values(e||{});if(n===Ts){const r=a.find(i=>{var l;return((l=i.user)==null?void 0:l.id)===As});if(r)return r}return a.find(r=>{var i;return((i=r.user)==null?void 0:i.id)&&r.user.id!==s})}const Ms=/^[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 Bt(e){return Ms.test(e.trim())}function At(e,s){const n=e==null?void 0:e.trim();return!n||s&&n===s?!1:!Bt(n)}function Se(e){return At(e==null?void 0:e.name,e==null?void 0:e.id)?e.name.trim():At(e==null?void 0:e.username,e==null?void 0:e.id)?e.username.trim():"Unknown member"}const Mt=[{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 Rs(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 Ut(e){return Mt[Rs(e)%Mt.length]}function Ls(e){return Ut(e).emoji}function Ds(e){return Ut(e).bgColor}const Z=({id:e,image:s,size:n=40,className:a,starred:r=!1,shape:i="squircle",dmAgentEnabled:l=!1})=>{const o=Ls(e),d=Ds(e),m=.45,x=n<32?Math.round(n*m):n<56?14:n<120?18:36,h=n>=40?2:1,c=i==="circle"?{borderRadius:"50%"}:{borderRadius:"1rem"},b=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:k("avatar-fallback flex h-full w-full items-center justify-center font-semibold select-none transition-colors"),style:{fontSize:x,lineHeight:1},children:o})});return t.jsxs("div",{className:k("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(j.StarIcon,{className:"size-3 text-yellow-600",weight:"duotone"})}),t.jsx("div",{"data-testid":"avatar-ring",className:k("h-full w-full","bg-transparent"),style:{...c,...l&&{borderWidth:`${h}px`,borderStyle:"solid",borderColor:"var(--AI-Gradient, #7F22FE)",boxShadow:"inset 0 1px 2px 0 rgba(255, 255, 255, 0.5)"}},children:b})]})},Fs="https://linktr.ee/s/about/trust-center/report",zs=({channel:e,participant:s,showBlockParticipant:n=!0,enabled:a=!0,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:l,onBlockParticipantClick:o,onReportParticipantClick:d,onActionComplete:m,logLabel:f="useChannelModerationActions"})=>{var T;const{service:x,debug:h}=He(),c=(T=s==null?void 0:s.user)==null?void 0:T.id,b=!!(a&&n&&x&&c),[w,p]=u.useState(!1),[g,v]=u.useState(null),[y,S]=u.useState(!1),[A,M]=u.useState(!1),D=b&&((g==null?void 0:g.participantId)!==c||(g==null?void 0:g.service)!==x);return u.useEffect(()=>{if(!b||!x||!c){p(!1),v(null);return}let I=!1;return(async()=>{try{const L=await x.getBlockedUsers();if(I)return;p(L.some(E=>E.blocked_user_id===c))}catch(L){I||console.error(`[${f}] Failed to check blocked status:`,L)}finally{I||v({participantId:c,service:x})}})(),()=>{I=!0}},[b,x,c,f]),{isParticipantBlocked:w,isCheckingBlockedStatus:D,isLeaving:y,isUpdatingBlockStatus:A,handleLeaveConversation:async()=>{var I;if(!y){l==null||l(),h&&console.log(`[${f}] Leave conversation`,e.cid),S(!0);try{const L=((I=e._client)==null?void 0:I.userID)??null;await e.hide(L,!1),r&&await r(e),m==null||m()}catch(L){console.error(`[${f}] Failed to leave conversation`,L)}finally{S(!1)}}},handleBlockUser:async()=>{var I,L,E;if(!(A||!x)){o==null||o(),h&&console.log(`[${f}] Block member`,(I=s==null?void 0:s.user)==null?void 0:I.id),M(!0);try{await x.blockUser((L=s==null?void 0:s.user)==null?void 0:L.id),i&&await i((E=s==null?void 0:s.user)==null?void 0:E.id),m==null||m()}catch(z){console.error(`[${f}] Failed to block member`,z)}finally{M(!1)}}},handleUnblockUser:async()=>{var I,L,E;if(!(A||!x)){o==null||o(),h&&console.log(`[${f}] Unblock member`,(I=s==null?void 0:s.user)==null?void 0:I.id),M(!0);try{await x.unBlockUser((L=s==null?void 0:s.user)==null?void 0:L.id),i&&await i((E=s==null?void 0:s.user)==null?void 0:E.id),m==null||m()}catch(z){console.error(`[${f}] Failed to unblock member`,z)}finally{M(!1)}}},handleReportUser:()=>{d==null||d(),m==null||m(),window.open(Fs,"_blank","noopener,noreferrer")}}},me=({variant:e="default",className:s,children:n,...a})=>{const r=e==="danger";return t.jsx("button",{type:"button",className:k("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})},Oe=({channel:e,participant:s,showDeleteConversation:n=!0,showBlockParticipant:a=!0,showReportParticipant:r=!0,onLeaveConversation:i,onBlockParticipant:l,onDeleteConversationClick:o,onBlockParticipantClick:d,onReportParticipantClick:m,customChannelActions:f,triggerClassName:x})=>{const[h,c]=u.useState(!1),b=u.useRef(null),w=u.useId(),p=u.useCallback(()=>c(!1),[]),{isParticipantBlocked:g,isCheckingBlockedStatus:v,isLeaving:y,isUpdatingBlockStatus:S,handleLeaveConversation:A,handleBlockUser:M,handleUnblockUser:D,handleReportUser:B}=zs({channel:e,participant:s,showBlockParticipant:a,enabled:h,onLeaveConversation:i,onBlockParticipant:l,onDeleteConversationClick:o,onBlockParticipantClick:d,onReportParticipantClick:m,onActionComplete:p,logLabel:"ChannelActionsMenu"});return u.useEffect(()=>{if(!h)return;const F=T=>{b.current&&!b.current.contains(T.target)&&c(!1)},C=T=>{T.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",F),document.addEventListener("keydown",C),()=>{document.removeEventListener("mousedown",F),document.removeEventListener("keydown",C)}},[h]),!s||!(n||a||r||!!f)?null:t.jsxs("div",{ref:b,className:"relative",children:[t.jsxs("button",{className:x,type:"button","aria-haspopup":"true","aria-expanded":h,"aria-controls":h?w:void 0,onClick:()=>c(F=>!F),children:[t.jsx(j.DotsThreeIcon,{className:"size-5 text-black/90"}),t.jsx("span",{className:"sr-only",children:"More options"})]}),h&&t.jsx("div",{id:w,"aria-label":"Conversation options",className:k("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(me,{onClick:A,disabled:y,"aria-busy":y,children:[y?t.jsx(j.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(j.SignOutIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Delete Conversation"})]})}),a&&t.jsx("li",{children:v?t.jsxs(me,{disabled:!0,"aria-busy":!0,children:[t.jsx(j.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}),t.jsx("span",{children:"Block"})]}):g?t.jsxs(me,{onClick:D,disabled:S,"aria-busy":S,children:[S?t.jsx(j.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(j.ProhibitInsetIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Unblock"})]}):t.jsxs(me,{onClick:M,disabled:S,"aria-busy":S,children:[S?t.jsx(j.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(j.ProhibitInsetIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Block"})]})}),r&&t.jsx("li",{children:t.jsxs(me,{variant:"danger",onClick:B,children:[t.jsx(j.FlagIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Report"})]})}),f]})})]})},Re="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",Ps="CUSTOMER_PAID",Os="Replies instantly with AI assistant",$s=e=>typeof e=="string"&&e.trim().replace(/[\s-]+/g,"_").toUpperCase()===Ps,Bs=e=>{const s=e;return[s==null?void 0:s.customerTag,s==null?void 0:s.customer_tag].some($s)},Us=({onBack:e,showBackButton:s,showStarButton:n=!1,dmAgentEnabled:a=!1,onLeaveConversation:r,onBlockParticipant:i,showDeleteConversation:l=!0,showBlockParticipant:o=!0,showReportParticipant:d=!0,onDeleteConversationClick:m,onBlockParticipantClick:f,onReportParticipantClick:x,customChannelActions:h,renderChannelActions:c,showChannelInfo:b=!0,onParticipantNameClick:w})=>{var B,O,F;const{channel:p}=N.useChannelStateContext(),{client:g}=N.useChatContext(),v=u.useMemo(()=>{var C;return fe((C=p.state)==null?void 0:C.members,g==null?void 0:g.userID,p.type)},[(B=p.state)==null?void 0:B.members,g==null?void 0:g.userID,p.type]),y=Se(v==null?void 0:v.user),S=(O=v==null?void 0:v.user)==null?void 0:O.image,A=Ye(p),M=Bs(v),D=async()=>{try{A?await p.unpin():await p.pin()}catch(C){console.error("[ChannelHeaderRedesign] Failed to update pinned status:",C)}};return t.jsx("div",{className:"@container w-full bg-[linear-gradient(180deg,#FBFAF9_0%,rgba(251,250,249,0.92)_58%,rgba(251,250,249,0)_100%)]",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:s&&t.jsx("button",{className:k(Re,"messaging-channel-view-back-button-mobile messaging-channel-view-back-button-desktop"),onClick:e||(()=>{}),type:"button","aria-label":"Back to conversations",children:t.jsx(j.ArrowLeftIcon,{className:"size-5 text-black/90"})})}),t.jsx("div",{className:"flex min-w-0 justify-center","data-dd-privacy":"mask",children:t.jsxs("button",{type:"button",onClick:w,"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:[t.jsx(Z,{id:((F=v==null?void 0:v.user)==null?void 0:F.id)||p.id||"unknown",name:y,image:S,dmAgentEnabled:a,shape:"circle",size:48,className:"-mb-2"}),t.jsxs("span",{className:"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 pl-3 pr-2 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",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}),t.jsxs("span",{className:"ml-2 flex gap-1",children:[M&&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(j.CurrencyDollarIcon,{className:"size-2.5",weight:"bold"})}),n&&A&&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(j.StarIcon,{className:"size-2.5",weight:"fill"})}),t.jsx(j.CaretRightIcon,{"aria-hidden":"true",className:"size-4 shrink-0 text-black/65",weight:"bold"})]})]}),a&&t.jsxs("span",{className:"mt-1 flex items-center gap-1 px-1 pb-0.5 text-[10px] leading-3 text-black/55",children:[t.jsx(j.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),t.jsx("span",{children:Os})]})]})]})}),t.jsxs("div",{className:"flex items-start justify-end gap-2",children:[n&&t.jsx("button",{className:Re,onClick:D,type:"button","aria-pressed":A,"aria-label":A?"Unstar conversation":"Star conversation",children:t.jsx(j.StarIcon,{className:k("size-5",{"text-[#FFD60A]":A,"text-black/90":!A}),weight:A?"fill":"regular"})}),b&&(c!==void 0?c:t.jsx(Oe,{channel:p,participant:v,showDeleteConversation:l,showBlockParticipant:o,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:m,onBlockParticipantClick:f,onReportParticipantClick:x,customChannelActions:h,triggerClassName:Re}))]})]})})},Vs=e=>t.jsx(N.DateSeparator,{...e,position:"center"}),$e="vote_up",Be="vote_down";function Gs(e){return e!=null&&e.length?e.some(s=>s.type===Be)?"down":e.some(s=>s.type===$e)?"up":null:null}function Vt(e){const{channel:s}=N.useChannelStateContext(),{client:n}=N.useChatContext("useMessageVote"),a=u.useMemo(()=>Gs(e.own_reactions),[e.own_reactions]),r=u.useCallback(async()=>{if(n!=null&&n.userID)try{a==="up"?await s.deleteReaction(e.id,$e):await s.sendReaction(e.id,{type:$e},{enforce_unique:!0,skip_push:!0})}catch{}},[s,n==null?void 0:n.userID,e.id,a]),i=u.useCallback(async()=>{if(n!=null&&n.userID)try{a==="down"?await s.deleteReaction(e.id,Be):await s.sendReaction(e.id,{type:Be},{enforce_unique:!0,skip_push:!0})}catch{}},[s,n==null?void 0:n.userID,e.id,a]);return{selected:a,voteUp:r,voteDown:i}}function Gt(e){return(e==null?void 0:e.trim().toLowerCase().split(/[-_]/)[0])||void 0}function qe({message:e,viewerLanguage:s}){var r;const n=e==null?void 0:e.text,a=Gt(s);return a?((r=e==null?void 0:e.i18n)==null?void 0:r[`${a}_text`])??n:n}const Hs=u.lazy(()=>Promise.resolve().then(()=>require("./Card-CZ6WAwfm.cjs"))),Ys=u.lazy(()=>Promise.resolve().then(()=>require("./Card-BcTN2501.cjs"))),qs=u.lazy(()=>Promise.resolve().then(()=>require("./Card-DU_zHX8a.cjs"))),Xe=()=>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}),Xs=e=>t.jsx(u.Suspense,{fallback:t.jsx(Xe,{}),children:t.jsx(Hs,{...e})}),Ht=e=>t.jsx(u.Suspense,{fallback:t.jsx(Xe,{}),children:t.jsx(Ys,{...e})}),Yt=e=>t.jsx(u.Suspense,{fallback:t.jsx(Xe,{}),children:t.jsx(qs,{...e})}),Ws=Ht,Ks=Yt,Ue={Composer:Xs,Sent:Ht,Received:Yt,Creator:Ws,Visitor:Ks},Js=[[/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 te(e){return e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":e.startsWith("image/")?"image":"document"}function qt(e){const s=Js.find(([n])=>n.test(e));return s?s[1]:"generic"}const Zs={video:j.VideoCameraIcon,audio:j.SpeakerHighIcon,image:j.ImageIcon,document:j.FileIcon},Qs={pdf:j.FilePdfIcon,doc:j.FileDocIcon,xls:j.FileXlsIcon,csv:j.FileCsvIcon,ppt:j.FilePptIcon,zip:j.FileZipIcon,text:j.FileTextIcon,markdown:j.FileMdIcon,generic:j.FileIcon};function en(e){const s=te(e);return s!=="document"?Zs[s]:Qs[qt(e)]}function ie(e,s){return u.createElement(en(e),s)}const tn=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},sn=({source:e,mimeType:s,poster:n,autoPlay:a=!1,playing:r,loop:i=!1,controls:l=!0,showProgress:o=!1,muted:d=!1,onContainerClick:m})=>{const f=te(s),x=u.useRef(null),h=u.useRef(null),c=u.useRef(null),b=u.useRef(r),[w,p]=u.useState(a),[g,v]=u.useState(0),[y,S]=u.useState(!1),[A,M]=u.useState(!1),[D,B]=u.useState(!1),[O,F]=u.useState(!1),[C,T]=u.useState(!0),[I,L]=u.useState(null),E=u.useCallback(()=>{B(!1),p(!0)},[]),z=u.useCallback(_=>{const R=h.current;if(!R)return 0;const G=R.getBoundingClientRect();return Math.max(0,Math.min(1,(tn(_)-G.left)/G.width))},[]),$=u.useCallback(_=>{const R=x.current;R&&R.duration&&(R.currentTime=_*R.duration)},[]),V=_=>{_.stopPropagation(),S(!0);const R=z(_);v(R),$(R)};u.useEffect(()=>{r!==void 0&&r!==b.current&&(b.current=r,p(r))},[r]),u.useEffect(()=>{if(!w){c.current!==null&&(cancelAnimationFrame(c.current),c.current=null);return}const _=()=>{const R=x.current;R&&R.duration&&!y&&v(R.currentTime/R.duration),c.current=requestAnimationFrame(_)};return c.current=requestAnimationFrame(_),()=>{c.current!==null&&cancelAnimationFrame(c.current)}},[w,y]),u.useEffect(()=>{const _=x.current;_&&(w?_.play().catch(R=>{p(!1),B(!0)}):_.pause())},[w]),u.useEffect(()=>{if(!y)return;const _=G=>v(z(G)),R=G=>{S(!1),$(z(G))};return window.addEventListener("mousemove",_),window.addEventListener("mouseup",R),window.addEventListener("touchmove",_,{passive:!0}),window.addEventListener("touchend",R),()=>{window.removeEventListener("mousemove",_),window.removeEventListener("mouseup",R),window.removeEventListener("touchmove",_),window.removeEventListener("touchend",R)}},[y,z,$]);const X=I?{aspectRatio:String(I)}:void 0,J=I?"":" aspect-video",W=Math.round(g*100);return t.jsxs("div",{role:"button",tabIndex:0,className:`relative cursor-pointer overflow-hidden bg-black ${J}`,style:X,onClick:_=>{if(m){m(_);return}D||l&&p(R=>!R)},onKeyDown:_=>{if(!(_.key!=="Enter"&&_.key!==" ")){if(_.preventDefault(),m){m(_);return}D||l&&p(R=>!R)}},children:[n&&(f==="audio"||C)&&t.jsx("img",{src:n,alt:"",className:"absolute inset-0 h-full w-full object-cover"}),!n&&(f==="audio"||C)&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:ie(s,{className:"size-12 text-black/20",weight:"regular"})}),t.jsx("div",{className:"absolute inset-0",children:f==="audio"?t.jsx("audio",{ref:x,src:e,loop:i,muted:d,style:{width:"100%",height:"100%"},onLoadStart:()=>F(!0),onCanPlay:()=>{F(!1),T(!1)},onWaiting:()=>F(!0),onPlay:()=>B(!1),onEnded:()=>{i||(p(!1),v(0))},children:t.jsx("track",{kind:"captions"})}):t.jsx("video",{ref:x,src:e,loop:i,muted:d,playsInline:!0,style:{width:"100%",height:"100%"},onLoadStart:()=>F(!0),onCanPlay:()=>{F(!1),T(!1)},onWaiting:()=>F(!0),onPlay:()=>B(!1),onLoadedMetadata:()=>{const _=x.current;_ instanceof HTMLVideoElement&&_.videoWidth&&_.videoHeight&&L(_.videoWidth/_.videoHeight)},onEnded:()=>{i||(p(!1),v(0))},children:t.jsx("track",{kind:"captions"})})}),O&&!D&&t.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center",children:t.jsx(j.CircleNotchIcon,{className:"size-8 animate-spin text-white/80",weight:"bold"})}),D&&!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:_=>{_.stopPropagation(),E()},onKeyDown:_=>{_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),_.stopPropagation(),E())},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(j.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":W,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,ref:h,className:"relative flex h-4 w-full cursor-pointer items-center",onMouseDown:V,onTouchStart:V,onClick:_=>_.stopPropagation(),onKeyDown:_=>{_.key==="ArrowRight"&&$(Math.min(1,g+.05)),_.key==="ArrowLeft"&&$(Math.max(0,g-.05))},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:`${W}%`}})})})}),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:_=>{_.stopPropagation(),p(R=>!R)},className:"shrink-0 text-white","aria-label":w?"Pause":"Play",children:w?t.jsx(j.PauseIcon,{className:"size-5",weight:"fill"}):t.jsx(j.PlayIcon,{className:"size-5 translate-x-px",weight:"fill"})}),t.jsxs("div",{role:"slider","aria-label":"Playback position","aria-valuenow":W,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,ref:h,className:"relative flex h-4 w-full cursor-pointer items-center",onMouseDown:V,onTouchStart:V,onClick:_=>_.stopPropagation(),onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),onKeyDown:_=>{_.key==="ArrowRight"&&$(Math.min(1,g+.05)),_.key==="ArrowLeft"&&$(Math.max(0,g-.05))},children:[t.jsx("div",{className:`w-full overflow-hidden rounded-full bg-white/30 transition-all duration-200 ${A||y?"h-1.5":"h-1"}`,children:t.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${W}%`}})}),t.jsx("div",{className:`absolute size-3 -translate-x-1/2 rounded-full bg-white shadow transition-[opacity,transform] duration-200 ${A||y?"scale-100 opacity-100":"scale-0 opacity-0"}`,style:{left:`${W}%`}})]})]})]})},Rt=e=>e==="dark"?"size-12 text-white/20":"size-12 text-black/20",nn=e=>e==="dark"?"aspect-video overflow-hidden bg-white/10":"aspect-video overflow-hidden bg-black/5",We=({mimeType:e,sourceUrl:s,thumbnailUrl:n,title:a,variant:r,mediaPlayerProps:i,containedImage:l=!1})=>{const o=te(e),[d,m]=u.useState(!1);return s&&(o==="video"||o==="audio")?t.jsx(sn,{source:s,mimeType:e,poster:n,controls:!0,...i}):s&&o==="image"?l?t.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:t.jsx("img",{src: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:()=>m(!0)})}):t.jsx("img",{src: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: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:()=>m(!0)})}):t.jsx("img",{src: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:ie(e,{className:Rt(r),weight:"regular"})}):n?t.jsx("div",{className:`relative ${nn(r)}`,children:t.jsx("img",{src: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:ie(e,{className:Rt(r),weight:"regular"})})},Xt=({variant:e,thumbnail:s,title:n,placeholderTitle:a="Attachment title",mimeType:r,detail:i,statusBadge:l,action:o,topLeft:d,topRight:m,rootRef:f,"data-testid":x})=>{const h=e==="dark",c=h?n??a:n??"",b=h&&!n;return t.jsxs("div",{ref:f,"data-testid":x,className:k("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)]",h?"bg-[#121110]":"bg-white"),children:[d?t.jsx("div",{className:"pointer-events-auto absolute left-3 top-3 z-50",children:d}):null,m?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-50",children:m}):null,s,t.jsxs("div",{className:"px-4 pb-3 pt-3",children:[c.trim()!==""&&t.jsx("p",{className:k("mb-0.5 truncate text-base font-medium",{"text-black":!h,"text-white/30":h&&b,"text-white":h&&!b}),children:c}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[ie(r,{className:k("size-5 shrink-0",h?"text-white/55":"text-black/55"),weight:"regular"}),i!=null&&i!==""&&t.jsx("span",{className:k("text-xs font-medium",h?"text-white/55":"text-black/55"),children:i}),l]}),o]})]})};function Wt(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ke(e){return`w-[280px] select-none overflow-hidden rounded-[24px] ${e?"bg-[#121110]":"bg-[#F3F3F1]"} shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]`}function an(e){return e?"bg-white/10":"bg-black/5"}function rn(e){return e?"text-white":"text-black"}function on(e){return e?"text-white/55":"text-black/55"}function ln(e){return e?"text-white/40":"text-black/40"}function cn(e){return e?"text-white/20":"text-black/20"}const Je=({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,m=t.jsxs(u.Fragment,{children:[t.jsx("div",{className:"p-2",children:r?t.jsx("img",{src:r,alt:n??"",className:"aspect-video w-full rounded-[20px] object-cover"}):t.jsx("div",{className:`aspect-video w-full rounded-[20px] ${an(s)} flex items-center justify-center`,children:t.jsx(j.LinkIcon,{className:`size-12 ${cn(s)}`})})}),t.jsxs("div",{className:"px-3 pb-3",children:[n&&t.jsx("p",{className:`truncate text-[14px] font-medium leading-5 ${rn(s)}`,children:n}),a&&t.jsx("p",{className:`truncate text-[12px] leading-4 ${on(s)}`,children:a}),d&&t.jsx("p",{className:`mt-1 truncate text-[12px] leading-4 ${ln(s)}`,children:d})]})]});return d?t.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"block no-underline",children:m}):t.jsx("div",{className:"block",children:m})};function Ze(e){return e.type==="link"||!!e.og_scrape_url&&!e.asset_url}function Ie(e){var s;return(s=e.attachments)==null?void 0:s.find(Ze)}async function dn(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 un=({url:e,filename:s})=>{const[n,a]=u.useState(!1),r=i=>{i.stopPropagation();const l=window.open("","_blank","noopener,noreferrer");a(!0),dn(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(j.CircleNotchIcon,{className:"size-4 animate-spin text-white",weight:"bold"}):t.jsxs(u.Fragment,{children:[t.jsx(j.DownloadSimpleIcon,{className:"size-4 text-white",weight:"bold"}),"Download"]})})};function Ee(e){var x,h,c,b;const s=(x=e.attachments)==null?void 0:x.find(w=>w.type==="video"&&w.asset_url),n=(h=e.attachments)==null?void 0:h.find(w=>w.type==="image"&&w.image_url),a=(c=e.attachments)==null?void 0:c.find(w=>w.type==="audio"&&w.asset_url),r=(b=e.attachments)==null?void 0:b.find(w=>w.type==="file"&&w.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,m=i==null?void 0:i.file_size,f=s==null?void 0:s.thumb_url;return{resolvedUrl:l,resolvedType:o,title:d,fileSize:m,thumbnailUrl:f}}const Kt=({resolvedUrl:e,resolvedType:s,title:n,fileSize:a,thumbnailUrl:r})=>{const i=a!==void 0?Wt(a):void 0;return t.jsx(Xt,{variant:"dark",title:n,placeholderTitle:"",mimeType:s,detail:i,thumbnail:t.jsx(We,{mimeType:s,sourceUrl:e,thumbnailUrl:r,title:n,variant:"dark"})})},Jt=({resolvedUrl:e,resolvedType:s,title:n,fileSize:a,thumbnailUrl:r})=>{const i=te(s),l=a!==void 0?Wt(a):void 0;return t.jsx(Xt,{variant:"light",title:n,mimeType:s,detail:l,thumbnail:t.jsx(We,{mimeType:s,sourceUrl:e,thumbnailUrl:r,title:n,variant:"light",containedImage:i==="image"||i==="document"}),action:t.jsx(un,{url:e,filename:n})})},mn=({message:e,isMyMessage:s=!1})=>{const n=Ie(e),a=Ee(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(Z,{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",style:{padding:0,borderRadius:0,overflow:"visible",background:"transparent"},children:n?t.jsx("div",{className:Ke(s),children:t.jsx(Je,{attachment:n,isMyMessage:s})}):s?t.jsx(Kt,{...a}):t.jsx(Jt,{...a})})})})]})},xn=({message:e})=>{const s=Ie(e);if(s)return t.jsx("div",{className:Ke(!0),"data-dd-privacy":"mask",children:t.jsx(Je,{attachment:s,isMyMessage:!0})});const n=Ee(e);return n?t.jsx("div",{style:{display:"contents"},"data-dd-privacy":"mask",children:t.jsx(Kt,{...n})}):null},hn=({message:e})=>{const s=Ie(e);if(s)return t.jsx("div",{className:Ke(!1),"data-dd-privacy":"mask",children:t.jsx(Je,{attachment:s,isMyMessage:!1})});const n=Ee(e);return n?t.jsx("div",{style:{display:"contents"},"data-dd-privacy":"mask",children:t.jsx(Jt,{...n})}):null},fn=Object.assign(mn,{Creator:xn,Visitor:hn}),gn={dark:"bg-[#121110]",light:"bg-[#e9eaed]"},pn={dark:"text-white",light:"text-[#080707]"},bn={dark:"border-white/[0.08]",light:"border-black/[0.08]"},vn=e=>e==="dark"?"sender":"receiver",jn={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]"}},ge=({variant:e,text:s,bordered:n=!0,groupPosition:a="single",className:r,children:i,"data-testid":l})=>{const o=s!=null&&s!=="",d=jn[vn(e)][a];return t.jsxs("div",{"data-testid":l,"data-group-position":a,className:k("relative w-[280px] overflow-hidden px-2 py-2",d,gn[e],pn[e],n&&"border",n&&bn[e],r),children:[i,o?t.jsx("p",{className:k("whitespace-pre-wrap break-words leading-snug","pt-2","px-2"),children:s}):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:k("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(j.XIcon,{className:"size-3",weight:"bold"})}),be=e=>e==="received"?"light":"dark",Zt=({firstOfGroup:e,endOfGroup:s,groupedByUser:n})=>!n||e&&s?"single":e?"first":s?"end":"middle",wn=({src:e,mimeType:s,filename:n,items:a})=>a&&a.length>0?a:e?[{src:e,mimeType:s,filename:n}]:[],_n=({item:e,preload:s,trailingAction:n})=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("audio",{src:e.src,controls:!0,preload:e.preload??s,className:"block min-w-0 flex-1",children:e.mimeType?t.jsx("source",{src:e.src,type:e.mimeType}):null}),n??null]}),Qe=({state:e,src:s,mimeType:n,filename:a,items:r,text:i,groupPosition:l,preload:o,onDismiss:d})=>{const m=be(e),f=e==="composer"&&!!d,x=wn({src:s,mimeType:n,filename:a,items:r});if(x.length===0)return null;const h=o??(x.length>1?"none":"metadata");return t.jsx(ge,{variant:m,text:i,groupPosition:l,"data-testid":"audio-attachment",children:t.jsx("div",{className:"flex flex-col gap-2",children:x.map((c,b)=>t.jsx(_n,{item:c,preload:h,trailingAction:f&&b===0?t.jsx(pe,{onClick:d,variant:"inline"}):void 0},`${c.src}-${b}`))})})},Nn=e=>t.jsx(Qe,{...e,state:"composer"}),yn=e=>t.jsx(Qe,{...e,state:"sent"}),Cn=e=>t.jsx(Qe,{...e,state:"received"}),kn={Composer:Nn,Sent:yn,Received:Cn};function Qt(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 Sn={pdf:"PDF",doc:"DOC",xls:"XLS",csv:"CSV",ppt:"PPT",zip:"ZIP",text:"TXT",markdown:"MD"};function es(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(te(e)==="document"){const r=qt(e),i=Sn[r];if(i)return i;if(e==="application/octet-stream")return}const a=e.split("/")[1];if(!(!a||a==="*"))return a.toUpperCase()}function ts(e,s,n){const a=es(e,s),r=typeof n=="number"&&n>0?Qt(n):void 0;return[a,r].filter(Boolean).join(" · ")||void 0}function ee(e){try{const n=new URL(e).pathname.split("/").pop();return n&&n.length>0?decodeURIComponent(n):"download"}catch{return"download"}}const In={dark:"text-white/55",light:"text-black/65"},En={dark:"bg-white/10",light:"bg-black/5"},Tn={dark:"text-white/85",light:"text-black/85"},ss=({variant:e,filename:s,title:n,mimeType:a="application/octet-stream",fileSize:r,onActivate:i,activateLabel:l,trailingAction:o})=>{const d=n??s??"File",m=ts(a,s,r),f=t.jsx("div",{className:k("flex size-10 shrink-0 items-center justify-center rounded-sm",En[e]),"aria-hidden":!0,children:ie(a,{className:k("size-6",Tn[e]),weight:"regular"})}),x=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}),m?t.jsx("p",{className:k("truncate text-xs leading-4",In[e]),children:m}):null]}),h=i?t.jsxs("button",{type:"button",onClick:i,"aria-label":l,className:k("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,x]}):t.jsxs(t.Fragment,{children:[f,x]});return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[h,o?t.jsx("div",{className:"shrink-0",children:o}):null]})};async function ns(e,s){const n=s??ee(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 An=({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}]:[],Mn=({variant:e,item:s,index:n,onActivate:a,trailingAction:r})=>{const i=s.filename??ee(s.src);return t.jsx(ss,{variant:e,filename:i,title:s.title,mimeType:s.mimeType??"application/octet-stream",fileSize:s.fileSize,onActivate:()=>a(n),activateLabel:`Download ${i}`,trailingAction:r})},et=({state:e,src:s,filename:n,fileSize:a,mimeType:r,title:i,items:l,text:o,groupPosition:d,onClick:m,onDismiss:f})=>{const x=be(e),h=e==="composer"&&!!f,c=An({src:s,filename:n,fileSize:a,mimeType:r,title:i,items:l}),b=p=>{if((m==null?void 0:m(p))===!1)return;const g=c[p];if(!g)return;const v=g.filename??ee(g.src);ns(g.src,v)};if(c.length===0)return null;const w=t.jsx("span",{className:k("flex size-8 items-center justify-center rounded-full",x==="dark"?"text-white/70":"text-black/70"),"aria-hidden":!0,children:t.jsx(j.DownloadSimpleIcon,{className:"size-5",weight:"bold"})});return t.jsx(ge,{variant:x,text:o,groupPosition:d,"data-testid":"file-attachment",children:t.jsx("div",{className:"flex flex-col gap-2",children:c.map((p,g)=>{const v=h&&g===0?t.jsx(pe,{onClick:f,variant:"inline"}):w;return t.jsx(Mn,{variant:x,item:p,index:g,onActivate:b,trailingAction:v},`${p.src}-${g}`)})})})},Rn=e=>t.jsx(et,{...e,state:"composer"}),Ln=e=>t.jsx(et,{...e,state:"sent"}),Dn=e=>t.jsx(et,{...e,state:"received"}),Fn={Composer:Rn,Sent:Ln,Received:Dn},tt=({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:"mes-media-viewer__nav mes-media-viewer__nav--prev",children:t.jsx(j.CaretLeftIcon,{size:20,weight:"bold","aria-hidden":!0})}),t.jsx("button",{type:"button",onClick:s,"aria-label":a,className:"mes-media-viewer__nav mes-media-viewer__nav--next",children:t.jsx(j.CaretRightIcon,{size:20,weight:"bold","aria-hidden":!0})})]}),as=({url:e,filename:s,variant:n="pill",label:a="Download",iconOnly:r,tone:i="dark",onTriggered:l})=>{const[o,d]=u.useState(!1),m=u.useCallback(c=>{c.stopPropagation(),!o&&(d(!0),ns(e,s).catch(()=>{}).finally(()=>{d(!1),l==null||l()}))},[o,e,s,l]),f=r??n!=="pill",h={className:k(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:m,disabled:o,"aria-label":a,className:k("flex size-8 shrink-0 items-center justify-center rounded-full transition-colors disabled:opacity-70",c[i]),children:o?t.jsx(j.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):t.jsx(j.DownloadSimpleIcon,{className:"size-5 shrink-0",weight:"bold","aria-hidden":!0})})}return n==="viewer"?t.jsx("button",{type:"button",onClick:m,disabled:o,"aria-label":a,className:"mes-media-viewer__action",children:o?t.jsx(j.CircleNotchIcon,{size:20,weight:"bold","aria-hidden":!0}):t.jsx(j.DownloadSimpleIcon,{size:20,weight:"bold","aria-hidden":!0})}):t.jsxs("button",{type:"button",onClick:m,disabled:o,"aria-label":f?a:void 0,className:k("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(j.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):t.jsx(j.DownloadSimpleIcon,{...h,"aria-hidden":!0}),f?null:a]})},Le=(e,s,n)=>Math.min(Math.max(e,s),n),st=({length:e,initialIndex:s,open:n})=>{const a=Le(s,0,Math.max(e-1,0)),[r,i]=u.useState(a);u.useEffect(()=>{n&&i(Le(s,0,Math.max(e-1,0)))},[n,s,e]),u.useEffect(()=>{i(d=>Le(d,0,Math.max(e-1,0)))},[e]);const l=u.useCallback(()=>{e<=1||i(d=>d<=0?e-1:d-1)},[e]),o=u.useCallback(()=>{e<=1||i(d=>d>=e-1?0:d+1)},[e]);return u.useEffect(()=>{if(!n||e<=1)return;const d=m=>{if(m.key!=="ArrowLeft"&&m.key!=="ArrowRight")return;const f=document.activeElement;f&&(f.tagName==="VIDEO"||f.tagName==="AUDIO")||(m.preventDefault(),m.key==="ArrowLeft"?l():o())};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n,e,l,o]),{index:r,prev:l,next:o}},nt=({open:e,onClose:s,ariaLabel:n,counter:a,actions:r,children:i,"data-testid":l})=>{const o=u.useRef(null),d=u.useRef(null);u.useEffect(()=>{var h;const x=o.current;if(x){if(e){if(!x.open)if(typeof x.showModal=="function")try{x.showModal()}catch{x.setAttribute("open","")}else x.setAttribute("open","");const c=typeof document<"u"?document.activeElement:null;return(h=d.current)==null||h.focus(),()=>{if(x.open)if(typeof x.close=="function")try{x.close()}catch{x.removeAttribute("open")}else x.removeAttribute("open");c&&document.body.contains(c)&&c.focus()}}if(x.open)if(typeof x.close=="function")try{x.close()}catch{x.removeAttribute("open")}else x.removeAttribute("open")}},[e]);const m=()=>{s()},f=x=>{x.target===o.current&&s()};return t.jsxs("dialog",{ref:o,className:"mes-media-viewer","aria-label":n??"Attachment viewer","data-testid":l,onClose:m,onClick:f,children:[t.jsxs("div",{className:"mes-media-viewer__chrome",children:[a?t.jsx("span",{className:"mes-media-viewer__counter",children:a}):null,t.jsxs("div",{className:"mes-media-viewer__actions",children:[r,t.jsx("button",{ref:d,type:"button",onClick:s,"aria-label":"Close viewer",className:"mes-media-viewer__action",children:t.jsx(j.XIcon,{size:20,weight:"bold","aria-hidden":!0})})]})]}),t.jsx("div",{className:"mes-media-viewer__body",children:i})]})},rs=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=st({length:s.length,initialIndex:n,open:e}),o=s[r],d=u.useMemo(()=>(o==null?void 0:o.filename)??(o?ee(o.src):"image"),[o]);return o?t.jsxs(nt,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,actions:t.jsx(as,{url:o.src,filename:d,variant:"viewer",label:`Download ${d}`}),"data-testid":"image-viewer",children:[t.jsx("img",{src:o.src,alt:o.alt??d,draggable:!1,loading:"eager",decoding:"async",className:"mes-media-viewer__image"},`${r}:${o.src}`),s.length>1?t.jsx(tt,{onPrev:i,onNext:l,prevLabel:"Previous image",nextLabel:"Next image"}):null]}):null},zn="relative block size-full overflow-hidden bg-black/5 outline-none focus-visible:ring-2 focus-visible:ring-white/80 focus-visible:ring-offset-2 focus-visible:ring-offset-black",is=({tiles:e,onTileActivate:s,maxVisible:n=4,className:a})=>{const r=e.length;if(r===0)return null;const i=e.slice(0,Math.min(r,n)),l=r-i.length,o=(d,m,f)=>{const x=k(zn,"h-full w-full");return s?t.jsxs("button",{type:"button",onClick:()=>s(m),"aria-label":d.ariaLabel??`Open media ${m+1}`,className:k(x,"cursor-zoom-in"),children:[d.content,f]},m):t.jsxs("div",{className:x,children:[d.content,f]},m)};return i.length===1?t.jsx("div",{className:k("aspect-square w-full",a),children:o(i[0],0)}):i.length===2?t.jsx("div",{className:k("grid aspect-[16/9] w-full grid-cols-2 gap-0.5",a),children:i.map((d,m)=>o(d,m))}):i.length===3?t.jsxs("div",{className:k("grid aspect-[4/3] w-full grid-cols-2 grid-rows-2 gap-0.5",a),children:[t.jsx("div",{className:"row-span-2",children:o(i[0],0)}),o(i[1],1),o(i[2],2)]}):t.jsx("div",{className:k("grid aspect-[4/3] w-full grid-cols-2 grid-rows-2 gap-0.5",a),children:i.map((d,m)=>{const f=l>0&&m===i.length-1;return o(d,m,f?t.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-black/55 text-2xl font-semibold text-white",children:["+",l]}):null)})})},ve=e=>{const[s,n]=u.useState(!1),[a,r]=u.useState(0),i=u.useCallback(o=>{(e==null?void 0:e(o))!==!1&&(r(o),n(!0))},[e]),l=u.useCallback(()=>n(!1),[]);return{viewerOpen:s,viewerIndex:a,handleActivate:i,closeViewer:l}},Pn=(e,s,n,a)=>({ariaLabel:`Open image ${s+1} of ${n}`,content:t.jsx("img",{src:e.src,alt:e.alt??"",width:e.width,height:e.height,draggable:!1,loading:e.loading??a,decoding:"async",className:"absolute inset-0 size-full rounded-md object-cover"})}),On=({src:e,alt:s,items:n})=>n&&n.length>0?n:e?[{src:e,alt:s}]:[],os=(e,s)=>e.map((n,a)=>({src:n.src,alt:n.alt,filename:s&&e.length===1?s:s?`${s} (${a+1})`:void 0})),$n=({src:e,alt:s,filename:n,loading:a="lazy",onClick:r,onDismiss:i})=>{const{viewerOpen:l,viewerIndex:o,handleActivate:d,closeViewer:m}=ve(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: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(rs,{open:l,items:os([{src:e,alt:s}],n),initialIndex:o,onClose:m})]})},ls=({state:e,src:s,alt:n,filename:a,items:r,text:i,groupPosition:l,loading:o="lazy",onClick:d})=>{const m=On({src:s,alt:n,items:r}),f=be(e),{viewerOpen:x,viewerIndex:h,handleActivate:c,closeViewer:b}=ve(d);if(m.length===0)return null;const w=m.map((p,g)=>Pn(p,g,m.length,o));return t.jsxs(ge,{variant:f,text:i,groupPosition:l,"data-testid":"image-attachment",children:[t.jsx("div",{className:"relative",children:t.jsx(is,{tiles:w,onTileActivate:c})}),t.jsx(rs,{open:x,items:os(m,a),initialIndex:h,onClose:b})]})},Bn=e=>t.jsx($n,{...e}),Un=e=>t.jsx(ls,{...e,state:"sent"}),Vn=e=>t.jsx(ls,{...e,state:"received"}),Gn={Composer:Bn,Sent:Un,Received:Vn},Hn=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=st({length:s.length,initialIndex:n,open:e}),o=s[r],d=u.useMemo(()=>(o==null?void 0:o.filename)??(o?ee(o.src):"document"),[o]),m=u.useMemo(()=>o?Yn(o.src):void 0,[o]);return!o||!m?null:t.jsxs(nt,{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:m,title:d,className:"mes-media-viewer__iframe",sandbox:"allow-scripts allow-forms allow-popups allow-downloads"},`${r}:${o.src}`),s.length>1?t.jsx(tt,{onPrev:i,onNext:l,prevLabel:"Previous document",nextLabel:"Next document"}):null]})},Yn=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()}`},qn=({src:e,filename:s,fileSize:n,title:a,items:r})=>r&&r.length>0?r:e?[{src:e,filename:s,fileSize:n,title:a}]:[],Xn=({variant:e,item:s,index:n,onActivate:a,trailingAction:r})=>{const i=s.filename??ee(s.src);return t.jsx(ss,{variant:e,filename:i,title:s.title,mimeType:"application/pdf",fileSize:s.fileSize,onActivate:()=>a(n),activateLabel:`Open ${i}`,trailingAction:r})},at=({state:e,src:s,filename:n,fileSize:a,title:r,items:i,text:l,groupPosition:o,onClick:d,onDismiss:m})=>{const f=be(e),x=qn({src:s,filename:n,fileSize:a,title:r,items:i}),{viewerOpen:h,viewerIndex:c,handleActivate:b,closeViewer:w}=ve(d),p=e==="composer"&&!!m;if(x.length===0)return null;const g=x.map(v=>({src:v.src,filename:v.filename??ee(v.src)}));return t.jsxs(ge,{variant:f,text:l,groupPosition:o,"data-testid":"pdf-attachment",children:[t.jsx("div",{className:"flex flex-col gap-2",children:x.map((v,y)=>{const S=v.filename??ee(v.src),A=p&&y===0?t.jsx(pe,{onClick:m,variant:"inline"}):e==="composer"?void 0:t.jsx(as,{url:v.src,filename:S,variant:"inline",label:`Download ${S}`,tone:f});return t.jsx(Xn,{variant:f,item:v,index:y,onActivate:b,trailingAction:A},`${v.src}-${y}`)})}),t.jsx(Hn,{open:h,items:g,initialIndex:c,onClose:w})]})},Wn=e=>t.jsx(at,{...e,state:"composer"}),Kn=e=>t.jsx(at,{...e,state:"sent"}),Jn=e=>t.jsx(at,{...e,state:"received"}),Zn={Composer:Wn,Sent:Kn,Received:Jn},cs=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=st({length:s.length,initialIndex:n,open:e}),o=s[r],d=u.useMemo(()=>(o==null?void 0:o.filename)??(o?ee(o.src):"video"),[o]);return o?t.jsxs(nt,{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:"mes-media-viewer__video",children:o.mimeType?t.jsx("source",{src:o.src,type:o.mimeType}):null},`${r}:${o.src}`),s.length>1?t.jsx(tt,{onPrev:i,onNext:l,prevLabel:"Previous video",nextLabel:"Next video"}):null]}):null},Qn=()=>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(j.PlayIcon,{className:"size-6",weight:"fill","aria-hidden":!0})})}),ds=({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 rounded-md object-cover"}):t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:t.jsx(j.VideoCameraIcon,{className:"size-16 rounded-md text-white/30",weight:"regular","aria-hidden":!0})}),t.jsx(Qn,{})]}),ea=(e,s,n)=>({ariaLabel:`Play video ${s+1} of ${n}`,content:t.jsx(ds,{item:e,index:s})}),ta=({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}]:[],us=(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})),sa=({src:e,poster:s,mimeType:n,filename:a,preload:r,onClick:i,onDismiss:l})=>{const{viewerOpen:o,viewerIndex:d,handleActivate:m,closeViewer:f}=ve(i);return t.jsxs("div",{className:"relative w-fit",children:[t.jsx("button",{type:"button",onClick:()=>m(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(ds,{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(cs,{open:o,items:us([{src:e,poster:s,mimeType:n,preload:r}],a),initialIndex:d,onClose:f})]})},ms=({state:e,src:s,poster:n,mimeType:a,filename:r,items:i,text:l,groupPosition:o,preload:d,onClick:m})=>{const f=ta({src:s,poster:n,mimeType:a,preload:d,items:i}),x=be(e),{viewerOpen:h,viewerIndex:c,handleActivate:b,closeViewer:w}=ve(m);if(f.length===0)return null;const p=f.map((g,v)=>ea(g,v,f.length));return t.jsxs(ge,{variant:x,text:l,groupPosition:o,"data-testid":"video-attachment",children:[t.jsx("div",{className:"relative",children:t.jsx(is,{tiles:p,onTileActivate:b,className:"overflow-hidden rounded-md"})}),t.jsx(cs,{open:h,items:us(f,r),initialIndex:c,onClose:w})]})},na=e=>t.jsx(sa,{...e}),aa=e=>t.jsx(ms,{...e,state:"sent"}),ra=e=>t.jsx(ms,{...e,state:"received"}),ia={Composer:na,Sent:aa,Received:ra},xe={Image:Gn,Video:ia,Audio:kn,Pdf:Zn,File:Fn},oa={isUnlocking:()=>!1},la={LockedAttachment:oa},xs=u.createContext({}),ca=xs.Provider;function hs(e){return u.useContext(xs)[e]??la[e]}const da=({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})}),ua=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)==="MESSAGE_TIP"},ma=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)==="MESSAGE_PAID"},Ne=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)==="MESSAGE_CHATBOT"},xa=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)==="MESSAGE_ATTACHMENT"},fs=e=>ua(e)||ma(e),ha=e=>{var s;return fs(e)&&!((s=e.text)!=null&&s.trim())},De=({message:e,standalone:s=!1,isMyMessage:n=!1,hasAttachment:a=!1})=>{var x;const r=fs(e),i=Ne(e);if(!r&&!i)return null;if(r){const h=(x=e.metadata)==null?void 0:x.amount_text;if(!h)return null;const c=s?"message-tip-standalone":"message-tag message-tag--tip",b=s?`${h} tip`:`Delivered with ${h} tip`;return t.jsxs("div",{className:c,children:[t.jsx(j.GiftIcon,{size:s?14:12}),t.jsx("span",{children:b})]})}const l=n&&a,o=l?"Sent with AI":"Sent by AI Assistant",d=["message-chatbot-indicator",n?"message-chatbot-indicator--sender":"message-chatbot-indicator--receiver",l?"message-chatbot-indicator--attachment":"message-chatbot-indicator--text"].join(" "),m=t.jsx("span",{className:"message-chatbot-indicator__label",children:o}),f=t.jsx("span",{className:"message-chatbot-indicator__icon",children:t.jsx(da,{size:l?12:15})});return t.jsx("div",{className:d,"data-testid":"message-chatbot-indicator",children:n&&!l?t.jsxs(t.Fragment,{children:[m,f]}):t.jsxs(t.Fragment,{children:[f,m]})})},gs=({selected:e,onVoteUp:s,onVoteDown:n})=>t.jsxs("div",{className:"message-vote-buttons",children:[t.jsx("button",{type:"button",className:k("message-vote-button focus-ring",{"message-vote-button--selected":e==="up"}),onClick:s,"aria-label":"Good response","aria-pressed":e==="up","data-tooltip":"Good response",children:t.jsx(j.ThumbsUpIcon,{size:16,weight:e==="up"?"fill":"regular"})}),t.jsx("button",{type:"button",className:k("message-vote-button focus-ring",{"message-vote-button--selected":e==="down"}),onClick:n,"aria-label":"Bad response","aria-pressed":e==="down","data-tooltip":"Bad response",children:t.jsx(j.ThumbsDownIcon,{size:16,weight:e==="down"?"fill":"regular"})})]}),fa=/^([a-z][a-z0-9+.-]*):/i,ga=new Set(["http","https","mailto","tel","sms"]);function rt(e){if(typeof e!="string")return;const s=e.trim();if(s==="")return;const n=fa.exec(s);if(n){const a=n[1].toLowerCase();return ga.has(a)?s:void 0}return s.startsWith("//")||s.startsWith("/")?s:`https://${s}`}const pa={dark:"bg-white text-[#121110] hover:bg-white/90",light:"bg-[#121110] text-white hover:bg-[#2a2928]"},ba=({variant:e,cta:s})=>{const n=k("mt-2 inline-flex h-10 w-full items-center justify-center rounded-full px-4 text-sm font-medium leading-none transition-colors",pa[e]),a=rt(s.href);return a?t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",onClick:r=>{var i;r.stopPropagation(),(i=s.onClick)==null||i.call(s)},className:`${n} no-underline`,children:s.label}):t.jsx("button",{type:"button",onClick:r=>{var i;r.stopPropagation(),(i=s.onClick)==null||i.call(s)},className:n,children:s.label})},va={dark:"text-white",light:"text-black/90"},ja="text-white/30",wa={dark:"text-white/55",light:"text-black/55"},it=({variant:e,title:s,placeholderTitle:n,description:a,url:r,appIcon:i,cta:l,trailingAction:o})=>{const d=e==="dark",m=s??(d?n:void 0)??"",f=m.trim()!=="",x=a!=null&&a.trim()!=="",h=typeof r=="string"?r.trim():"",c=h!=="",b=l!=null;if(!f&&!x&&!c&&!b)return null;const p=k("truncate text-base font-medium leading-6",d&&!s?ja:va[e]),g=k("truncate text-xs leading-4",wa[e]);return t.jsxs("div",{className:"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-2",children:[t.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[f&&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:k("min-w-0",p),children:m})]}),x&&t.jsx("p",{className:g,children:a})]}),!b&&c&&t.jsx("p",{className:g,children:h})]}),o&&t.jsx("div",{className:"shrink-0",children:o})]}),l&&t.jsx(ba,{variant:e,cta:l})]})},_a=k("relative block w-[280px] select-none overflow-hidden rounded-md","border border-black/[0.08]","shadow-[0_1px_2px_rgba(0,0,0,0.04),0_8px_32px_rgba(0,0,0,0.1)]"),ye=({variant:e,children:s,href:n,onClick:a,ariaLabel:r,rootRef:i,topRight:l,bgClassName:o,"data-testid":d})=>{const m=n!=null||a!=null,f=k(_a,o??(e==="dark"?"bg-[#121110]":"bg-white"),m?"cursor-pointer no-underline focus-ring":null),x=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":d,className:f,children:[s,x]}):a?t.jsxs("button",{ref:i,type:"button",onClick:a,"aria-label":r,"data-testid":d,className:k(f,"text-left"),children:[s,x]}):t.jsxs("div",{ref:i,"data-testid":d,className:f,children:[s,x]})},Na={dark:"bg-white/10",light:"bg-black/5"},ya={dark:"size-16 text-white/25",light:"size-16 text-black/25"},Te=(e,s)=>!!s&&!!e&&te(e)==="audio",ot=(e,s)=>{if(!s||!e)return!1;const n=te(e);return n==="video"||n==="audio"},lt="bg-[#F2F3F4]",Ce=({variant:e,thumbnailUrl:s,sourceUrl:n,title:a,mimeType:r="image/*",topLeft:i,topRight:l})=>{const o=te(r),d=!!n&&o==="video";return Te(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:k("relative h-[180px] w-full overflow-hidden",d&&"bg-black"),children:[d?t.jsx("video",{src:n,poster:s,controls:!0,playsInline:!0,preload:"metadata",className:"absolute inset-0 h-full w-full object-contain",children:t.jsx("track",{kind:"captions"})}):s?t.jsx("img",{src:s,alt:a??"",draggable:!1,className:"absolute inset-0 h-full w-full object-cover"}):t.jsx("div",{className:k("flex h-full w-full items-center justify-center",Na[e]),children:ie(r,{className:ya[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]})},Ca=({title:e,placeholderTitle:s,description:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:l,layout:o="featured",appIcon:d,cta:m,onDismiss:f,onEditClick:x})=>{const h=o==="classic",c=Te(r,l),b=f?t.jsx("button",{type:"button",onClick:f,"aria-label":"Dismiss attachment",className:"flex size-6 items-center justify-center rounded-full bg-[#121110] text-white",children:t.jsx(j.XIcon,{className:"size-3",weight:"bold"})}):void 0,w=x?t.jsx("button",{type:"button",onClick:x,"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(j.PencilSimpleIcon,{className:"size-5",weight:"regular"})}):void 0;return c?t.jsx(ye,{variant:"dark",bgClassName:lt,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(Ce,{variant:"dark",sourceUrl:l,title:e,mimeType:r})}),b&&t.jsx("div",{className:"shrink-0",children:b})]})}):t.jsxs(ye,{variant:"dark",topRight:h?b:void 0,children:[!h&&t.jsx(Ce,{variant:"dark",thumbnailUrl:i,sourceUrl:l,title:e,mimeType:r,topRight:b}),t.jsx(it,{variant:"dark",title:e,placeholderTitle:s,description:n,url:a,appIcon:d,cta:m,trailingAction:w})]})},ka=({title:e,description:s,url:n,mimeType:a,thumbnailUrl:r,sourceUrl:i,layout:l="featured",appIcon:o,cta:d,onClick:m})=>{const f=ot(a,i),x=rt(n),h=d==null&&x!=null&&!f?x:void 0,c=d==null&&!f?m:void 0,b=Te(a,i)?lt:void 0,w=d&&m?{...d,onClick:()=>{var p;m(),(p=d.onClick)==null||p.call(d)}}:d;return t.jsxs(ye,{variant:"light",href:h,onClick:c,ariaLabel:e??"Open attachment preview",bgClassName:b,"data-testid":"link-attachment",children:[l==="featured"&&t.jsx(Ce,{variant:"light",thumbnailUrl:r,sourceUrl:i,title:e,mimeType:a}),t.jsx(it,{variant:"light",title:e,description:s,url:n,appIcon:o,cta:w})]})},Sa=({title:e,placeholderTitle:s,description:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:l,layout:o="featured",appIcon:d,cta:m,onClick:f})=>{const x=ot(r,l),h=rt(a),c=m==null&&h!=null&&!x?h:void 0,b=m==null&&!x&&c!=null?f:void 0;return t.jsxs(ye,{variant:"dark",href:c,onClick:b,bgClassName:Te(r,l)?lt:void 0,children:[o==="featured"&&t.jsx(Ce,{variant:"dark",thumbnailUrl:i,sourceUrl:l,title:e,mimeType:r}),t.jsx(it,{variant:"dark",title:e,placeholderTitle:s,description:n,url:a,appIcon:d,cta:m})]})},Ve={Composer:Ca,Sent:Sa,Received:ka},Ia="mt-[2px] max-w-[280px] whitespace-pre-wrap break-words rounded-[18px] bg-[#121110] px-4 py-2 text-white",Ea="mt-[2px] max-w-[280px] whitespace-pre-wrap break-words rounded-[18px] bg-[#e9eaed] px-4 py-2 text-[#080707]";function P(e){const s=e==null?void 0:e.trim();return s||void 0}function Lt(e){return e.trim().replace(/^https?:\/\//i,"").replace(/\/+$/,"").toLowerCase()}function Ta(e,s){if(!(e!=null&&e.trim())||!(s!=null&&s.trim()))return!1;const n=Lt(e),a=Lt(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 Dt(e){const s=P(e.og_scrape_url)??P(e.title_link),n=P(e.image_url)??P(e.thumb_url),a=P(e.asset_url),r=P(e.mime_type);return{title:P(e.title),description:P(e.text),url:s,thumbnailUrl:n,sourceUrl:a,layout:n||ot(r,a)?"featured":"classic",mimeType:r}}function Aa(e){var s;return ps(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 ps(e){const s=P(e.og_scrape_url);return e.type==="link"||!!s&&!e.asset_url}function bs(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(ps(r)){a(r);continue}const i=Aa(r);i&&n(i,r)}return s}function Ma(e){let s=0;for(const n of e)s+=n.type==="link"?n.attachments.length:1;return s}function Ra(e){return e.filter(s=>s.type==="media").length}function La(e,s,n){return s<=1?n:e===0?"first":e===s-1?"end":"middle"}function Ft(e){return P(e.image_url)??P(e.asset_url)??""}function Da(e){switch(e){case"image":return xe.Image;case"video":return xe.Video;case"audio":return xe.Audio;case"pdf":return xe.Pdf;default:return xe.File}}function Fa(e,s){if(s.length>1)switch(e){case"image":return{items:s.map(a=>({src:Ft(a),alt:P(a.title)}))};case"video":return{items:s.map(a=>({src:P(a.asset_url)??"",poster:P(a.thumb_url),mimeType:P(a.mime_type)}))};case"audio":return{items:s.map(a=>({src:P(a.asset_url)??"",mimeType:P(a.mime_type)??"audio/mpeg",filename:P(a.title)}))};case"pdf":return{items:s.map(a=>({src:P(a.asset_url)??"",filename:P(a.title),fileSize:a.file_size}))};case"file":return{items:s.map(a=>({src:P(a.asset_url)??"",filename:P(a.title),fileSize:a.file_size,mimeType:P(a.mime_type)??"application/octet-stream"}))}}const n=s[0];if(!n)return{};switch(e){case"image":return{src:Ft(n),alt:P(n.title)};case"video":return{src:P(n.asset_url)??"",poster:P(n.thumb_url),mimeType:P(n.mime_type)};case"audio":return{src:P(n.asset_url)??"",mimeType:P(n.mime_type)??"audio/mpeg",filename:P(n.title)};case"pdf":return{src:P(n.asset_url)??"",filename:P(n.title),fileSize:n.file_size};case"file":return{src:P(n.asset_url)??"",filename:P(n.title),fileSize:n.file_size,mimeType:P(n.mime_type)??"application/octet-stream"}}}function za({groupPosition:e,isMyMessage:s,segment:n,text:a}){const r=Da(n.kind),i={...Fa(n.kind,n.attachments),groupPosition:e,...a?{text:a}:{}};return s?t.jsx(r.Sent,{...i}):t.jsx(r.Received,{...i})}const Pa=({groupPosition:e,isMyMessage:s,message:n})=>{var w;const a=bs(n.attachments);if(a.length===0)return null;const r=Ma(a),i=Ra(a),l=(w=n.text)==null?void 0:w.trim(),o=a.find(p=>p.type==="link"),d=(o==null?void 0:o.type)==="link"?Dt(o.attachments[0]??{}).url:void 0,m=l&&Ta(l,d)?void 0:l;let f=0,x=0;const h=[],c=(p,g)=>{const v=f===r-1;f+=1;const y=s?Ve.Sent:Ve.Received;h.push(t.jsxs(u.Fragment,{children:[t.jsx(y,{...Dt(p)}),v&&m?t.jsx("div",{className:s?Ia:Ea,children:m}):null]},g))},b=(p,g)=>{const v=f===r-1,y=La(x,i,e);f+=1,x+=1,h.push(t.jsx(za,{groupPosition:y,isMyMessage:s,segment:p,text:v?m:void 0},g))};return a.forEach((p,g)=>{if(p.type==="link"){p.attachments.forEach((v,y)=>{c(v,`link-${g}-${y}`)});return}b(p,`media-${g}`)}),t.jsx(t.Fragment,{children:h})},Oa=e=>{var ft,gt,pt,bt,vt,jt,wt,_t,Nt,yt,Ct,kt,St,It;const{additionalMessageInputProps:s,chatbotVotingEnabled:n,editing:a,endOfGroup:r,firstOfGroup:i,groupedByUser:l,handleAction:o,handleOpenThread:d,handleRetry:m,highlighted:f,isMessageAIGenerated:x,isMyMessage:h,message:c,renderText:b,threadList:w,viewerLanguage:p}=e,{client:g}=N.useChatContext("CustomMessage"),{channel:v}=N.useChannelStateContext("CustomMessage"),{isUnlocking:y,onUnlockClick:S,onFetchSource:A,onDownloadClick:M}=hs("LockedAttachment"),[D,B]=u.useState(!1),O=N.useMessageReminder(c.id),{selected:F,voteUp:C,voteDown:T}=Vt(c),{Attachment:I=N.Attachment,EditMessageModal:L=N.EditMessageModal,MessageActions:E,MessageBlocked:z=N.MessageBlocked,MessageBouncePrompt:$=N.MessageBouncePrompt,MessageDeleted:V=N.MessageDeleted,MessageIsThreadReplyInChannelButtonIndicator:X=N.MessageIsThreadReplyInChannelButtonIndicator,MessageRepliesCountButton:J=N.MessageRepliesCountButton,ReminderNotification:W=N.ReminderNotification,StreamedMessageText:_=N.StreamedMessageText,PinIndicator:R}=N.useComponentContext("CustomMessage"),G=N.messageHasAttachments(c),Y=N.messageHasReactions(c),H=u.useMemo(()=>x==null?void 0:x(c),[x,c]),U=u.useMemo(()=>{const re=c.attachments??[],de=c.shared_location?[c.shared_location,...re]:re;if(!Ne(c))return de;const Et=de.filter(Tt=>!("type"in Tt)||!Ze(Tt));return Et.length===de.length?de:Et},[c]),q=u.useMemo(()=>bs(U),[U]),K=u.useMemo(()=>{const re=qe({message:c,viewerLanguage:p});return re===c.text?c:{...c,text:re}},[c,p]),ne=q.length>0,je=q.reduce((re,de)=>re+de.attachments.length,0)===((U==null?void 0:U.length)??0),we=Zt({endOfGroup:r,firstOfGroup:i,groupedByUser:l});if(N.isDateSeparatorMessage(c))return null;if(c.deleted_at||c.type==="deleted")return t.jsx(V,{message:c});if(N.isMessageBlocked(c))return t.jsx(z,{});const Q=!w&&!!c.reply_count,ae=!w&&c.show_in_channel&&c.parent_id,se=c.status==="failed"&&((ft=c.error)==null?void 0:ft.status)!==403,ut=N.isMessageBounced(c);let oe;se?oe=()=>m(c):ut&&(oe=()=>B(!0));const le=h(),ks=k("str-chat__message str-chat__message-simple",`str-chat__message--${c.type}`,`str-chat__message--${c.status}`,le?"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":G,"str-chat__message--highlighted":f,"str-chat__message--pinned pinned-message":c.pinned,"str-chat__message--with-reactions":Y,"str-chat__message-send-can-be-retried":(c==null?void 0:c.status)==="failed"&&((gt=c==null?void 0:c.error)==null?void 0:gt.status)!==403,"str-chat__message-with-thread-link":Q||ae,"str-chat__virtual-message__wrapper--end":r,"str-chat__virtual-message__wrapper--first":i,"str-chat__virtual-message__wrapper--group":l}),Ae=c.poll_id&&g.polls.fromState(c.poll_id),mt=ha(c),ce=Ne(c),xt=xa(c),Me=!!(U!=null&&U.length&&!c.quoted_message),ht=ce&&le&&Me,Ss=ne&&je&&!c.quoted_message&&!Ae&&!H&&!ce;return t.jsxs(t.Fragment,{children:[a&&t.jsx(L,{additionalMessageInputProps:s}),D&&t.jsx(N.MessageBounceModal,{MessageBouncePrompt:$,onClose:()=>B(!1),open:D}),t.jsxs("div",{className:ks,"data-message-id":c.id,"data-dd-privacy":"mask",children:[R&&t.jsx(R,{}),!!O&&t.jsx(W,{reminder:O}),c.user&&t.jsx(Z,{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:ce}),t.jsx("div",{className:k("str-chat__message-inner",{"str-chat__simple-message--error-failed":se||ut}),"data-testid":"message-inner",onClick:oe,onKeyDown:oe,role:oe?"button":void 0,tabIndex:oe?0:void 0,style:{marginInlineEnd:0,marginInlineStart:0},children:xt?t.jsxs("div",{className:"str-chat__message-bubble-wrapper",children:[le?t.jsxs("div",{className:"flex items-center gap-2",children:[E&&t.jsx(E,{}),t.jsx(Ue.Sent,{title:(pt=c.metadata)==null?void 0:pt.attachment_title,mimeType:(bt=c.metadata)==null?void 0:bt.attachment_mime_type,thumbnailUrl:(vt=c.metadata)==null?void 0:vt.attachment_thumbnail,amountText:(jt=c.metadata)==null?void 0:jt.amount_text,detail:(wt=c.metadata)==null?void 0:wt.attachment_detail,paymentStatus:(_t=c.metadata)==null?void 0:_t.payment_status,onPreviewClick:()=>S==null?void 0:S(c,v),onFetchSource:async()=>await(A==null?void 0:A(c,v))})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ue.Received,{title:(Nt=c.metadata)==null?void 0:Nt.attachment_title,mimeType:(yt=c.metadata)==null?void 0:yt.attachment_mime_type,thumbnailUrl:(Ct=c.metadata)==null?void 0:Ct.attachment_thumbnail,amountText:(kt=c.metadata)==null?void 0:kt.amount_text,detail:(St=c.metadata)==null?void 0:St.attachment_detail,paymentStatus:(It=c.metadata)==null?void 0:It.payment_status,isUnlocking:y(c.id),onUnlockClick:()=>S==null?void 0:S(c,v),onFetchSource:async()=>await(A==null?void 0:A(c,v)),onDownloadClick:()=>M==null?void 0:M(c,v)}),E&&t.jsx(E,{})]}),c.text&&t.jsx("div",{className:"str-chat__message-bubble",children:t.jsx(N.MessageText,{message:K,renderText:b})})]}):mt?t.jsx(De,{message:c,standalone:!0}):Ss?t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsxs("div",{className:"str-chat__message-bubble",style:{background:"transparent",borderRadius:0,overflow:"visible",padding:0},children:[t.jsx(Pa,{groupPosition:we,isMyMessage:le,message:{attachments:U,text:K.text}}),t.jsx(N.MessageErrorIcon,{})]})}):t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsxs("div",{className:"str-chat__message-bubble",children:[ce&&!ht&&t.jsx(De,{message:c,hasAttachment:Me,isMyMessage:le}),Ae&&t.jsx(N.Poll,{poll:Ae}),U!=null&&U.length&&!c.quoted_message?t.jsx(I,{actionHandler:o,attachments:U}):null,H?t.jsx(_,{message:K,renderText:b}):t.jsx(N.MessageText,{message:K,renderText:b}),t.jsx(N.MessageErrorIcon,{})]})})}),!xt&&!mt&&t.jsxs("div",{className:"str-chat__message-footer",children:[(!ce||ht)&&t.jsx(De,{message:c,hasAttachment:Me,isMyMessage:le}),n&&ce&&t.jsx(gs,{selected:F,onVoteUp:C,onVoteDown:T})]}),Q&&t.jsx(J,{onClick:d,reply_count:c.reply_count}),ae&&t.jsx(X,{})]},c.id)]})},$a=u.memo(Oa,(e,s)=>e.chatbotVotingEnabled!==s.chatbotVotingEnabled||e.viewerLanguage!==s.viewerLanguage?!1:N.areMessageUIPropsEqual(e,s)),Ba=e=>{const s=N.useMessageContext("CustomMessage");return t.jsx($a,{...s,...e})},Ua=()=>{var n;const{handleDelete:e,message:s}=N.useMessageContext("CustomMessageActions");return((n=s.metadata)==null?void 0:n.payment_status)==="paid"?null:t.jsx(Ge.DefaultDropdownActionButton,{onClick:e,"aria-label":"Delete",title:"Delete",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:t.jsx(j.TrashSimpleIcon,{size:16,weight:"light","aria-hidden":!0})})},Va=()=>{const{handleFlag:e}=N.useMessageContext("CustomMessageActions");return t.jsx(Ge.DefaultDropdownActionButton,{onClick:e,"aria-label":"Report",title:"Report",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:t.jsx(j.FlagIcon,{size:16,weight:"light","aria-hidden":!0})})},Ga=()=>{var s;const{message:e}=N.useMessageContext("CustomMessageActions");return((s=e.metadata)==null?void 0:s.custom_type)!=="MESSAGE_ATTACHMENT"?null:t.jsx(Ge.MessageActions,{messageActionSet:[{Component:Ua,placement:"quick",type:"delete"},{Component:Va,placement:"quick",type:"flag"}]})},Ha=({link:e,onDismiss:s})=>{const{og_scrape_url:n,title:a,image_url:r}=e,i=l=>{l.preventDefault(),s(n)};return t.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"relative block w-full rounded-[24px] bg-[#121110] p-2 no-underline transition-opacity hover:opacity-90",children:[r&&t.jsx("img",{src:r,alt:a||"",className:"h-[180px] w-full rounded-[20px] object-cover"}),t.jsx("button",{type:"button",onClick:i,className:"absolute right-4 top-4 flex size-6 items-center justify-center rounded-full border border-white/40 bg-white/70 backdrop-blur-2xl focus-ring","aria-label":"Close link preview",children:t.jsx(j.XIcon,{className:"size-4 text-black/90"})}),t.jsxs("div",{className:"p-2",children:[a&&t.jsx("div",{className:"truncate text-[14px] font-medium leading-5 text-white",children:a}),t.jsx("div",{className:"truncate text-[12px] leading-4 text-white/55",children:n})]})]})},Ya=e=>({linkPreviews:Array.from(e.previews.values()).filter(s=>Pe.LinkPreviewsManager.previewIsLoaded(s)||Pe.LinkPreviewsManager.previewIsLoading(s))}),qa=()=>{const{linkPreviewsManager:e}=N.useMessageComposer(),{linkPreviews:s}=N.useStateStore(e.state,Ya),n=r=>{e.dismissPreview(r)};return s.length>0?t.jsx("div",{className:"messaging-link-preview-list flex min-h-0 flex-col items-stretch w-full gap-2 mb-4 overflow-y-auto overscroll-contain",children:s.map(r=>t.jsx("div",{className:"w-full shrink-0",children:t.jsx(Ha,{link:r,onDismiss:n})},r.og_scrape_url))}):null},ct=u.createContext(!1),Xa=()=>u.useContext(ct),Wa=({sendMessage:e,disabled:s,...n})=>t.jsx("button",{...n,type:"button","aria-label":"Send",disabled:s,onClick:e,children:t.jsx(j.ArrowUpIcon,{weight:"bold",className:"size-4"})}),Ka=()=>{const e=u.useContext(ct),{handleSubmit:s}=N.useMessageInputContext(),n=N.useMessageComposerHasSendableData(),a=e||!n,{SendButton:r=Wa,AttachmentPreviewList:i=N.AttachmentPreviewList}=N.useComponentContext("CustomMessageInput");return t.jsxs("div",{className:"central-container flex min-h-0 flex-col gap-2 min-w-0 w-full self-stretch p-2 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)]","data-dd-privacy":"mask",children:[t.jsx(N.QuotedMessagePreview,{}),t.jsx(qa,{}),t.jsx(i,{}),t.jsxs("div",{className:"flex shrink-0",children:[t.jsx("div",{className:"w-full ml-2 mr-4 self-center leading-[0]",children:t.jsx(N.TextareaComposer,{"aria-disabled":e||void 0,className:"w-full resize-none outline-none leading-5 placeholder:text-black/30 text-sm",autoFocus:!e,maxRows:4,readOnly:e,tabIndex:e?-1:void 0})}),t.jsx(r,{sendMessage:s,"aria-label":"Send",className:"str-chat__send-button mt-auto flex justify-center items-center flex-shrink-0 rounded-full size-8 bg-[#121110] disabled:bg-[#F1F0EE] disabled:text-black/20 text-white focus-ring","data-testid":"send-button",disabled:a,type:"button"})]})]})},Ja=({renderActions:e,renderFooter:s,disabled:n=!1,disabledReason:a,composerInput:r})=>{var o;const{channel:i}=N.useChannelStateContext(),l=((o=i==null?void 0:i.data)==null?void 0:o.frozen)===!0;return n?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"messaging-composer-locked-panel flex w-full flex-col items-center justify-center gap-3 px-6 py-4",children:a?t.jsx("p",{className:"max-w-[345px] text-center text-xs font-normal leading-[1.3] tracking-[0.12px] text-black/40",children:a}):null}),s==null?void 0:s()]}):t.jsxs("div",{className:"flex min-h-0 flex-col gap-4 p-4",children:[t.jsxs("div",{inert:l?"":void 0,"aria-disabled":l||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(ct.Provider,{value:l,children:t.jsx(N.MessageInput,{Input:r??Ka})})]}),s==null?void 0:s()]})},Za=["SYSTEM_DM_AGENT_PAUSED","SYSTEM_DM_AGENT_RESUMED"],Qa={SYSTEM_DM_AGENT_PAUSED:"DM Agent has left the conversation",SYSTEM_DM_AGENT_RESUMED:"DM Agent has rejoined the conversation"},er=["SYSTEM_AGE_SAFETY_BLOCKED"],tr={SYSTEM_AGE_SAFETY_BLOCKED:"This user isn’t able to reply because they don’t meet our age safety guidelines."},Fe="age safety guidelines.",sr="https://linktr.ee/s/about/contact",zt=e=>Za.includes(e),nr=e=>er.includes(e),ar=e=>{var a;const s=(a=e.metadata)==null?void 0:a.custom_type;if(zt(s))return{kind:"dm-agent",type:s};if(nr(s))return{kind:"age-safety",type:s};const n=e.dm_agent_system_type;if(zt(n))return{kind:"dm-agent",type:n}},rr=e=>{const s=e.indexOf(Fe);if(s===-1)return e;const n=s+Fe.length;return t.jsxs(t.Fragment,{children:[e.slice(0,s),t.jsx("a",{href:sr,target:"_blank",rel:"noopener noreferrer",className:"mes-age-safety-system-message__emphasis font-medium text-inherit underline",children:Fe}),e.slice(n)]})},ir=e=>{var a,r;const s=e.message.hide_date===!0,n=ar(e.message);if((n==null?void 0:n.kind)==="dm-agent"){const i=((a=e.message.text)==null?void 0:a.trim())||Qa[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(j.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(N.MessageTimestamp,{message:e.message})]})}if((n==null?void 0:n.kind)==="age-safety"){const i=((r=e.message.text)==null?void 0:r.trim())||tr[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(j.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:rr(i)})})]}),!s&&t.jsx(N.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(N.MessageTimestamp,{message:e.message})]})},vs=u.createContext(!1),ze=({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"})}),or=new Set([N.AIStates.Thinking,N.AIStates.Generating,N.AIStates.ExternalSources]),lr=({threadList:e})=>{var b,w;const{channel:s,channelConfig:n,thread:a}=N.useChannelStateContext(),{client:r}=N.useChatContext(),{typing:i={}}=N.useTypingContext(),{aiState:l}=N.useAIState(s),o=u.useContext(vs);if(!e&&o&&or.has(l)){const p=cr(s,(b=r.user)==null?void 0:b.id);return t.jsx(Pt,{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 m=e?[]:Object.values(i).filter(({parent_id:p,user:g})=>{var v;return(g==null?void 0:g.id)!==((v=r.user)==null?void 0:v.id)&&!p}),f=e?Object.values(i).filter(({parent_id:p,user:g})=>{var v;return(g==null?void 0:g.id)!==((v=r.user)==null?void 0:v.id)&&p===(a==null?void 0:a.id)}):[],x=e?f:m;if(!x.length)return null;const h=(w=x[0])==null?void 0:w.user,c=h!=null&&h.id&&s.state.members[h.id]?s.state.members[h.id].user:void 0;return t.jsx(Pt,{avatarId:(h==null?void 0:h.id)??(c==null?void 0:c.id)??"typing-user",avatarName:(h==null?void 0:h.name)??(c==null?void 0:c.name)??(h==null?void 0:h.id)??"Typing user",avatarImage:(h==null?void 0:h.image)??(c==null?void 0:c.image),testId:"typing-indicator"})},Pt=({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(Z,{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.jsx("div",{className:"str-chat__message-bubble",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(ze,{cx:"4",index:0}),t.jsx(ze,{cx:"16",index:1}),t.jsx(ze,{cx:"28",index:2})]})})})})})})]})});function cr(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 js=()=>null,dr=({className:e,message:s})=>t.jsxs("div",{className:k("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})]}),ke=u.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(dr,{className:"w-6 h-6"}),t.jsx("span",{className:"text-sm text-stone",children:"Loading messages"})]})}));ke.displayName="LoadingState";const ue="size-10 rounded-full hover:bg-[#E5E4E1] flex items-center justify-center transition-colors duration-150 focus-ring",_e="Replies instantly with AI assistant",ur=({onBack:e,showBackButton:s,showStarButton:n=!1,dmAgentEnabled:a=!1,onLeaveConversation:r,onBlockParticipant:i,showDeleteConversation:l=!0,showBlockParticipant:o=!0,showReportParticipant:d=!0,onDeleteConversationClick:m,onBlockParticipantClick:f,onReportParticipantClick:x,customChannelActions:h,renderChannelActions:c,showChannelInfo:b=!0,onParticipantNameClick:w,renderHeaderTitleBadges:p})=>{var T,I,L,E,z,$;const{channel:g}=N.useChannelStateContext(),{client:v}=N.useChatContext(),y=u.useMemo(()=>{var V;return fe((V=g.state)==null?void 0:V.members,v==null?void 0:v.userID,g.type)},[(T=g.state)==null?void 0:T.members,v==null?void 0:v.userID,g.type]),S=Se(y==null?void 0:y.user),A=(I=y==null?void 0:y.user)==null?void 0:I.image,M=Ye(g),D=p==null?void 0:p({channel:g,participant:y}),B="flex max-w-full flex-col items-center gap-1 rounded-[12px] px-1 py-0.5 text-center text-xs font-medium text-black/90",O="flex min-w-0 max-w-full items-center gap-4 rounded-[12px] px-1 py-0.5 text-left text-black/90",F=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"min-w-0 truncate",children:S}),D&&t.jsx("span",{className:"shrink-0",children:D})]}),C=async()=>{try{M?await g.unpin():await g.pin()}catch(V){console.error("[CustomChannelHeader] Failed to update pinned status:",V)}};return t.jsxs("div",{className:"@container",children:[t.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] w-full items-center @lg:hidden px-6 py-3",children:[t.jsx("div",{className:"flex items-center gap-2",children:s&&t.jsx("button",{className:k(ue,"messaging-channel-view-back-button-mobile bg-[#F1F0EE]"),onClick:e||(()=>{}),type:"button","aria-label":"Back to conversations",children:t.jsx(j.ArrowLeftIcon,{className:"size-5 text-black/90"})})}),t.jsx("div",{className:"flex flex-col gap-1 items-center","data-dd-privacy":"mask",children:w?t.jsxs("button",{type:"button",onClick:w,"aria-label":`View details for ${S}`,className:k(B,"appearance-none border-0 bg-transparent transition-opacity hover:opacity-70 focus-ring focus-visible:outline-none"),children:[t.jsx(Z,{id:((L=y==null?void 0:y.user)==null?void 0:L.id)||g.id||"unknown",name:S,image:A,starred:n&&M,dmAgentEnabled:a,size:48}),t.jsxs("span",{className:"flex max-w-full items-center gap-0.5",children:[F,t.jsx(j.CaretRightIcon,{className:"size-3 shrink-0",weight:"bold"})]}),a&&t.jsxs("div",{className:"flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[t.jsx(j.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),t.jsx("span",{children:_e})]})]}):t.jsxs("div",{className:B,children:[t.jsx(Z,{id:((E=y==null?void 0:y.user)==null?void 0:E.id)||g.id||"unknown",name:S,image:A,starred:n&&M,dmAgentEnabled:a,size:48}),t.jsxs("p",{className:"flex max-w-full items-center justify-center gap-0.5",children:[F,t.jsx(j.CaretRightIcon,{className:"invisible size-3 shrink-0",weight:"bold"})]}),a&&t.jsxs("div",{className:"flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[t.jsx(j.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),t.jsx("span",{children:_e})]})]})}),t.jsxs("div",{className:"flex justify-end items-center gap-2",children:[n&&t.jsx("button",{className:ue,onClick:C,type:"button","aria-label":M?"Unstar conversation":"Star conversation",children:t.jsx(j.StarIcon,{className:k("size-5",{"text-yellow-600":M,"text-black/90":!M}),weight:M?"duotone":"regular"})}),b&&(c!==void 0?c:t.jsx(Oe,{channel:g,participant:y,showDeleteConversation:l,showBlockParticipant:o,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:m,onBlockParticipantClick:f,onReportParticipantClick:x,customChannelActions:h,triggerClassName:k(ue,"bg-[#F1F0EE]")}))]})]}),t.jsxs("div",{className:"px-6 py-3 hidden @lg:flex items-center justify-between gap-3 min-h-12 border-b border-b-black/[0.08]",children:[t.jsxs("div",{className:"flex items-center gap-4 min-w-0","data-dd-privacy":"mask",children:[s&&e&&t.jsx("button",{className:k(ue,"messaging-channel-view-back-button-desktop"),type:"button",onClick:e,"aria-label":"Back to conversations",children:t.jsx(j.ArrowLeftIcon,{className:"size-5 text-black/90"})}),w?t.jsxs("button",{type:"button",onClick:w,"aria-label":`View details for ${S}`,className:k(O,"appearance-none border-0 bg-transparent transition-opacity hover:opacity-70 focus-ring focus-visible:outline-none"),children:[t.jsx(Z,{id:((z=y==null?void 0:y.user)==null?void 0:z.id)||g.id||"unknown",name:S,image:A,starred:n&&M,dmAgentEnabled:a,size:48}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("h1",{className:"flex min-w-0 items-center gap-1 font-medium text-black/90",children:[F,t.jsx(j.CaretRightIcon,{className:"size-4 shrink-0",weight:"bold"})]}),a&&t.jsxs("div",{className:"mt-0.5 flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[t.jsx(j.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),t.jsx("span",{className:"truncate",children:_e})]})]})]}):t.jsxs("div",{className:O,children:[t.jsx(Z,{id:(($=y==null?void 0:y.user)==null?void 0:$.id)||g.id||"unknown",name:S,image:A,starred:n&&M,dmAgentEnabled:a,size:48}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("h1",{className:"flex min-w-0 items-center gap-1 font-medium text-black/90",children:[F,t.jsx(j.CaretRightIcon,{className:"invisible size-4 shrink-0",weight:"bold"})]}),a&&t.jsxs("div",{className:"mt-0.5 flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[t.jsx(j.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),t.jsx("span",{className:"truncate",children:_e})]})]})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[n&&t.jsx("button",{className:ue,onClick:C,type:"button","aria-label":M?"Unstar conversation":"Star conversation",children:t.jsx(j.StarIcon,{className:k("size-6",{"text-yellow-600":M,"text-black/90":!M}),weight:M?"duotone":"regular"})}),b&&(c!==void 0?c:t.jsx(Oe,{channel:g,participant:y,showDeleteConversation:l,showBlockParticipant:o,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:m,onBlockParticipantClick:f,onReportParticipantClick:x,customChannelActions:h,triggerClassName:ue}))]})]})]})},mr=({onBack:e,showBackButton:s,renderMessageInputActions:n,renderMessageInputFooter:a,renderConversationFooter:r,onLeaveConversation:i,onBlockParticipant:l,showDeleteConversation:o=!0,onDeleteConversationClick:d,onBlockParticipantClick:m,onReportParticipantClick:f,showBlockParticipant:x=!0,showReportParticipant:h=!0,composerDisabled:c=!1,composerDisabledReason:b,showStarButton:w=!1,chatbotVotingEnabled:p=!1,renderChannelBanner:g,renderHeaderTitleBadges:v,customChannelActions:y,renderChannelActions:S,renderMessage:A,dmAgentEnabled:M=!1,viewerLanguage:D,showChannelInfo:B=!0,onParticipantNameClick:O,composerInput:F})=>{var _,R,G,Y;const{channel:C}=N.useChannelStateContext(),{client:T}=N.useChatContext(),I=u.useMemo(()=>{var H;return fe((H=C.state)==null?void 0:H.members,T==null?void 0:T.userID,C.type)},[(_=C.state)==null?void 0:_.members,T==null?void 0:T.userID,C.type]),L=u.useMemo(()=>{var q;const H=T==null?void 0:T.userID;return H?Object.values(((q=C.state)==null?void 0:q.members)||{}).find(K=>{var ne;return((ne=K.user)==null?void 0:ne.id)===H}):void 0},[T==null?void 0:T.userID,(R=C.state)==null?void 0:R.members]),E=((G=L==null?void 0:L.user)==null?void 0:G.is_account)??(L==null?void 0:L.is_account),z=((Y=I==null?void 0:I.user)==null?void 0:Y.is_account)??(I==null?void 0:I.is_account),$=M&&E===!1&&z===!0,V=C.state.messages.some(H=>H.type!=="deleted"),X=g?t.jsx(u.Fragment,{children:g()},"lt-channel-banner"):null,J=O?t.jsx(Us,{onBack:e,showBackButton:s,showChannelInfo:B,showStarButton:w,dmAgentEnabled:$,onLeaveConversation:i,onBlockParticipant:l,showDeleteConversation:o,showBlockParticipant:x,showReportParticipant:h,onDeleteConversationClick:d,onBlockParticipantClick:m,onReportParticipantClick:f,customChannelActions:y,renderChannelActions:S,onParticipantNameClick:O}):null,W=u.useCallback(H=>{const{message:U}=N.useMessageContext("ChannelView"),q=t.jsx(Ba,{...H,chatbotVotingEnabled:p,viewerLanguage:D});return!A||!U?q:A(q,U)},[p,A,D]);return t.jsx(t.Fragment,{children:t.jsx(N.WithComponents,{overrides:{Message:W,MessageActions:Ga},children:t.jsxs(N.Window,{children:[!O&&t.jsxs(t.Fragment,{children:[t.jsx("div",{children:t.jsx(ur,{onBack:e,showBackButton:s,showChannelInfo:B,showStarButton:w,dmAgentEnabled:$,onLeaveConversation:i,onBlockParticipant:l,showDeleteConversation:o,showBlockParticipant:x,showReportParticipant:h,onDeleteConversationClick:d,onBlockParticipantClick:m,onReportParticipantClick:f,customChannelActions:y,renderChannelActions:S,renderHeaderTitleBadges:v})},"lt-channel-header"),X]}),O&&!V&&t.jsxs("div",{className:"px-4 @lg:px-6",children:[J,X]}),t.jsx("div",{className:"flex-1 overflow-hidden relative",children:t.jsx(N.MessageList,{head:O&&V?t.jsxs("div",{className:"sticky top-0 z-10",children:[J,X]}):void 0,hideDeletedMessages:!0,hideNewMessageSeparator:!1})},"lt-channel-message-list"),r?t.jsx(u.Fragment,{children:r(C)},"lt-channel-conversation-footer"):null,t.jsx(Ja,{...n&&{renderActions:()=>n==null?void 0:n(C)},renderFooter:()=>a==null?void 0:a(C),disabled:c,disabledReason:b,composerInput:F},"lt-channel-message-input")]})})})},dt=u.memo(({channel:e,onBack:s,showBackButton:n=!1,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:l,onBlockParticipant:o,className:d,CustomChannelEmptyState:m=js,showDeleteConversation:f=!0,onDeleteConversationClick:x,onBlockParticipantClick:h,onReportParticipantClick:c,showBlockParticipant:b=!0,showReportParticipant:w=!0,composerDisabled:p=!1,composerDisabledReason:g,dmAgentEnabled:v,messageMetadata:y,onMessageSent:S,showStarButton:A=!1,chatbotVotingEnabled:M=!1,renderChannelBanner:D,renderHeaderTitleBadges:B,customChannelActions:O,renderChannelActions:F,renderMessage:C,onMessageLinkClick:T,sendButton:I,attachmentPreviewList:L,viewerLanguage:E,showChannelInfo:z=!0,onParticipantNameClick:$,composerInput:V})=>{const X=u.useCallback(async(W,_,R)=>{var K;const G=((K=e.data)==null?void 0:K.chatbot_paused)===!0,Y=v&&!G,H={..._,...Y&&{silent:!0},...y&&{metadata:{..._.metadata??{},...y}}},U={...R,...Y&&{skip_push:!0}},q=await e.sendMessage(H,U);return S==null||S(q),q},[e,v,y,S]),J=u.useRef(null);return u.useEffect(()=>{if(!T)return;const W=J.current;if(!W)return;const _=R=>{const G=R.target,Y=G==null?void 0:G.closest("a[href]"),H=Y==null?void 0:Y.getAttribute("href");if(!H)return;const U=Y==null?void 0:Y.closest("[data-message-id]"),q=U==null?void 0:U.getAttribute("data-message-id"),K=q?e.state.messages.find(ne=>ne.id===q):void 0;T(H,K)};return W.addEventListener("click",_),()=>W.removeEventListener("click",_)},[T,e]),t.jsx("div",{ref:J,className:k("messaging-channel-view h-full flex flex-col",d),children:t.jsx(vs.Provider,{value:v??!1,children:t.jsx(N.Channel,{channel:e,MessageSystem:ir,EmptyStateIndicator:m,LoadingIndicator:ke,DateSeparator:Vs,TypingIndicator:lr,doSendMessageRequest:X,...I?{SendButton:I}:{},...L?{AttachmentPreviewList:L}:{},children:t.jsx(mr,{onBack:s,showBackButton:n,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:l,onBlockParticipant:o,CustomChannelEmptyState:m,showDeleteConversation:f,onDeleteConversationClick:x,onBlockParticipantClick:h,onReportParticipantClick:c,showBlockParticipant:b,showReportParticipant:w,composerDisabled:p,composerDisabledReason:g,showStarButton:A,dmAgentEnabled:v,chatbotVotingEnabled:M,renderChannelBanner:D,renderHeaderTitleBadges:B,customChannelActions:O,renderChannelActions:F,renderMessage:C,viewerLanguage:E,showChannelInfo:z,onParticipantNameClick:$,composerInput:V})})})})});dt.displayName="ChannelView";const he=u.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"})]})}));he.displayName="ErrorState";const xr=({capabilities:e={},renderMessageInputActions:s,renderConversationFooter:n,onChannelSelect:a,onExitConversation:r,initialParticipantFilter:i,initialParticipantData:l,CustomChannelEmptyState:o,onBlockParticipantClick:d,onReportParticipantClick:m,dmAgentEnabled:f,onMessageSent:x,chatbotVotingEnabled:h=!1,viewerLanguage:c,renderHeaderTitleBadges:b,renderChannelBanner:w,customChannelActions:p,renderChannelActions:g,onParticipantNameClick:v,renderMessage:y,onMessageLinkClick:S,showChannelInfo:A,composerInput:M})=>{const{client:D,isConnected:B,isLoading:O,error:F,refreshConnection:C,service:T,debug:I}=$t(),[L,E]=u.useState(null),[z,$]=u.useState(null),[V,X]=u.useState(!1),{showDeleteConversation:J=!0}=e,W=u.useRef(l);W.current=l;const _=u.useRef(a);_.current=a;const R=u.useRef(null),G=u.useRef(null);u.useEffect(()=>{G.current=L},[L]),u.useEffect(()=>{if(!D||!B)return;const U=D.userID;if(!U)return;const q=`${U}::${i}`;if(R.current===q)return;R.current=q;const K=()=>{R.current===q&&(R.current=null)};(async()=>{var je,we;try{I&&console.log("[MessagingShell] Loading initial conversation with:",i);const Q=await D.queryChannels({type:"messaging",members:{$eq:[U,i]}},{},{limit:1});if(Q.length>0){E(Q[0]),$(null),(je=_.current)==null||je.call(_,Q[0]),I&&console.log("[MessagingShell] Initial conversation loaded:",Q[0].id);return}const ae=W.current;if(!ae||!T){K(),$("No conversation found with this account"),I&&console.log("[MessagingShell] No conversation found for:",i);return}try{const se=await T.startChannelWithParticipant({id:ae.id,name:ae.name,phone:ae.phone});E(se),$(null),(we=_.current)==null||we.call(_,se),I&&console.log("[MessagingShell] Channel created and loaded:",se.id)}catch(se){console.error("[MessagingShell] Failed to create conversation:",se),K(),$("Failed to create conversation")}}catch(Q){console.error("[MessagingShell] Failed to load initial conversation:",Q),K(),G.current||$("Failed to load conversation")}})()},[i,D,B,T,I]);const Y=u.useRef(r);Y.current=r;const H=u.useCallback(()=>{var U;E(null),X(!0),(U=Y.current)==null||U.call(Y)},[]);return O?t.jsx(ke,{}):F?t.jsx(he,{message:F,onBack:C}):!B||!D?t.jsx(he,{message:"Not connected to messaging service",onBack:C}):z?t.jsx(he,{message:z}):V&&!L?t.jsx(he,{message:"Conversation ended"}):L?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(dt,{channel:L,renderMessageInputActions:s,renderConversationFooter:n,renderChannelBanner:w,onLeaveConversation:H,onBlockParticipant:H,CustomChannelEmptyState:o,showDeleteConversation:J,onBlockParticipantClick:d,onReportParticipantClick:m,dmAgentEnabled:f,onMessageSent:x,chatbotVotingEnabled:h,viewerLanguage:c,renderHeaderTitleBadges:b,customChannelActions:p,renderChannelActions:g,onParticipantNameClick:v,renderMessage:y,onMessageLinkClick:S,showChannelInfo:A,composerInput:M},L.id)})}):t.jsx(ke,{})};function hr(e){const s=e.state.pending_messages;if(s!=null&&s.length)for(const n of s)e.state.addMessageSorted(n.message)}const ws=u.createContext({selectedChannel:void 0,onChannelSelect:()=>{},debug:!1,renderMessagePreview:void 0,channelPreview:void 0,viewerLanguage:void 0}),fr=ws.Provider,gr=()=>u.useContext(ws),pr=(e,s)=>{const n=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())),r=new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth(),s.getUTCDate())).getTime()-n.getTime();return Math.floor(r/(1e3*60*60*24))},_s=e=>{const s=new Date;if(Math.floor((s.getTime()-e.getTime())/1e3)<60)return"Just now";const a=pr(e,s);return a===0?e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0}):a===1?"Yesterday":a<7?`${a}d`:a<28?`${Math.floor(a/7)}w`:e.toLocaleDateString("en-US",{month:"numeric",day:"numeric",year:"2-digit"})},Ns=u.memo(e=>{var B,O,F;const{channel:s,unread:n}=e,{selectedChannel:a,onChannelSelect:r,debug:i,channelPreview:l,renderMessagePreview:o,viewerLanguage:d}=gr(),{client:m}=N.useChatContext(),f=(a==null?void 0:a.id)===(s==null?void 0:s.id),x=Ye(s);if(l){const C=l;return t.jsx(C,{...e,active:f,selectedChannel:a,onChannelSelect:r,viewerLanguage:d})}const h=()=>{s&&r(s)},c=C=>{const T=C.key==="Enter"||C.key===" ",I=C.repeat;!T||I||(C.preventDefault(),h())},b=fe((B=s==null?void 0:s.state)==null?void 0:B.members,m==null?void 0:m.userID,s==null?void 0:s.type),w=Se(b==null?void 0:b.user),p=(O=b==null?void 0:b.user)==null?void 0:O.image,g=(()=>{var T;const C=(T=s==null?void 0:s.state)==null?void 0:T.messages;if(C!=null&&C.length){for(let I=C.length-1;I>=0;I--)if(C[I].type!=="system")return C[I]}})(),y=(()=>{var z,$,V,X;const C=qe({message:g,viewerLanguage:d});if(((z=g==null?void 0:g.metadata)==null?void 0:z.custom_type)==="MESSAGE_TIP")return C?`💵 ${C}`:"💵 Sent a tip";if((($=g==null?void 0:g.metadata)==null?void 0:$.custom_type)==="MESSAGE_PAID")return C?`💰 ${C}`:"💰 Sent a message";if(((V=g==null?void 0:g.metadata)==null?void 0:V.custom_type)==="MESSAGE_ATTACHMENT")return C?`📎 ${C}`:"📎 Sent an attachment";if(C)return C;const E=(X=g==null?void 0:g.attachments)==null?void 0:X[0];return E?E.og_scrape_url?E.og_scrape_url:E.type==="image"?"📷 Sent an image":E.type==="video"?"🎥 Sent a video":E.type==="audio"?"🎵 Sent audio":E.type==="file"?"📎 Sent a file":"📎 Sent an attachment":"No messages yet"})(),S=g!=null&&g.created_at?_s(new Date(g.created_at)):"",A=g?Ne(g):!1,M=o?o(g,y):`${A?"✨ ":""}${y}`,D=n??0;return i&&console.log("📺 [ChannelList] 📋 CHANNEL PREVIEW RENDER",{channelId:s==null?void 0:s.id,isSelected:f,participantName:w,unreadCount:D,hasTimestamp:!!S}),t.jsx("div",{role:"button",tabIndex:0,onClick:h,onKeyDown:c,className:k("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(Z,{id:((F=b==null?void 0:b.user)==null?void 0:F.id)||s.id||"unknown",name:w,image:p,size:48,starred:x}),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:k("text-sm font-medium truncate text-[#191918]"),children:[x&&t.jsx("span",{className:"sr-only",children:"Starred conversation. "}),w]}),S&&t.jsx("span",{className:"text-xs text-[#717070] flex-shrink-0",children:S})]}),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:M}),D>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:D>99?"99+":D})]})]})]})})});Ns.displayName="CustomChannelPreview";const br={last_message_at:-1},ys=u.memo(({onChannelSelect:e,selectedChannel:s,filters:n,allowNewMessagesFromUnfilteredChannels:a=!1,channelRenderFilterFn:r,sort:i=br,className:l,customEmptyStateIndicator:o,channelListPaginator:d=N.InfiniteScroll,channelPreview:m,renderMessagePreview:f,viewerLanguage:x})=>{const h=u.useRef(0);h.current++;const{debug:c=!1}=He(),b=u.useCallback(p=>{for(const g of p)hr(g);return r?r(p):p},[r]);c&&console.log("📺 [ChannelList] 🔄 RENDER START",{renderCount:h.current,selectedChannelId:s==null?void 0:s.id,filters:n});const w=u.useMemo(()=>({selectedChannel:s,onChannelSelect:e,debug:c,channelPreview:m,renderMessagePreview:f,viewerLanguage:x}),[s,e,c,m,f,x]);return t.jsx("div",{className:k("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(fr,{value:w,children:t.jsx(N.ChannelList,{filters:n,sort:i,options:{limit:30},allowNewMessagesFromUnfilteredChannels:a,channelRenderFilterFn:b,Paginator:d,Preview:Ns,EmptyStateIndicator:o},`${JSON.stringify(n)}:${JSON.stringify(i)}`)})})})});ys.displayName="ChannelList";const Cs=({question:e,onClick:s,loading:n=!1,className:a})=>t.jsx("button",{type:"button",onClick:s,disabled:n,style:{backgroundColor:"#E6E5E3"},className:k("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}),vr=({faqs:e,onFaqClick:s,loadingFaqId:n,headerText:a,className:r,avatarImage:i,avatarName:l})=>{const o=e.filter(d=>d.enabled).sort((d,m)=>(d.order??0)-(m.order??0));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(Z,{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(Cs,{question:d.question,onClick:()=>s(d.id),loading:n===d.id},d.id))]})]})})};exports.ActionButton=me;exports.AttachmentThumbnail=We;exports.Avatar=Z;exports.ChannelEmptyState=js;exports.ChannelList=ys;exports.ChannelView=dt;exports.CustomMessageProvider=ca;exports.FaqList=vr;exports.FaqListItem=Cs;exports.LinkAttachment=Ve;exports.LockedAttachment=Ue;exports.MediaMessage=fn;exports.MessageAttachment=xe;exports.MessageVoteButtons=gs;exports.MessagingProvider=Es;exports.MessagingShell=xr;exports.bubbleGroupPositionFromStream=Zt;exports.buildCompactMetaLabel=ts;exports.formatFileSize=Qt;exports.formatRelativeTime=_s;exports.getFileExtensionLabel=es;exports.getMessageDisplayText=qe;exports.getSourceType=te;exports.isLinkAttachment=Ze;exports.isUuidLike=Bt;exports.normalizeLanguageCode=Gt;exports.renderTypeIcon=ie;exports.resolveConversationParticipant=fe;exports.resolveLinkAttachment=Ie;exports.resolveMediaFromMessage=Ee;exports.resolveParticipantDisplayName=Se;exports.useComposerLocked=Xa;exports.useCustomMessage=hs;exports.useMessageVote=Vt;exports.useMessaging=$t;
2
- //# sourceMappingURL=index-C1p97mNU.cjs.map