@linktr.ee/messaging-react 3.14.0 → 3.14.1-rc-1784609552
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.
- package/dist/{Card-C0aP28ZH.cjs → Card-BoBmGI_a.cjs} +2 -2
- package/dist/{Card-C0aP28ZH.cjs.map → Card-BoBmGI_a.cjs.map} +1 -1
- package/dist/{Card-fPhu90tj.js → Card-Cr8EMVg2.js} +2 -2
- package/dist/{Card-fPhu90tj.js.map → Card-Cr8EMVg2.js.map} +1 -1
- package/dist/{index-Cw1ij-Py.js → index-4OY62Yxz.js} +613 -607
- package/dist/{index-Cw1ij-Py.js.map → index-4OY62Yxz.js.map} +1 -1
- package/dist/index-BOh2WCXX.cjs +2 -0
- package/dist/{index-34_jzKSz.cjs.map → index-BOh2WCXX.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/components/CustomMessageInput/CustomMessageInput.test.tsx +129 -1
- package/src/components/CustomMessageInput/index.tsx +49 -1
- package/dist/index-34_jzKSz.cjs +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-BOh2WCXX.cjs");exports.ActionButton=e.ActionButton;exports.Avatar=e.Avatar;exports.ChannelEmptyState=e.ChannelEmptyState;exports.ChannelList=e.ChannelList;exports.ChannelView=e.ChannelView;exports.CustomMessageProvider=e.CustomMessageProvider;exports.FaqList=e.FaqList;exports.FaqListItem=e.FaqListItem;exports.LinkAttachment=e.LinkAttachment;exports.LockedAttachment=e.LockedAttachment;exports.MediaMessage=e.MediaMessage;exports.MessageAttachment=e.MessageAttachment;exports.MessageBubble=e.MessageBubble;exports.MessageVoteButtons=e.MessageVoteButtons;exports.MessagingProvider=e.MessagingProvider;exports.MessagingShell=e.MessagingShell;exports.buildCompactMetaLabel=e.buildCompactMetaLabel;exports.formatFileSize=e.formatFileSize;exports.formatRelativeTime=e.formatRelativeTime;exports.getFileExtensionLabel=e.getFileExtensionLabel;exports.getMessageDisplayText=e.getMessageDisplayText;exports.isLinkAttachment=e.isLinkAttachment;exports.isUuidLike=e.isUuidLike;exports.messageAttachmentGroupPositionFromStream=e.bubbleGroupPositionFromStream;exports.normalizeLanguageCode=e.normalizeLanguageCode;exports.optimizeMessagingAttachmentUrl=e.optimizeMessagingAttachmentUrl;exports.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as p, m as d, n as v, p as C, q as A, s as k, t as F, u as b, v as P, w as f, x, o as y, y as z, z as B, B as S, D as q, E as D, G as E, H as V, I as w } from "./index-
|
|
1
|
+
import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as p, m as d, n as v, p as C, q as A, s as k, t as F, u as b, v as P, w as f, x, o as y, y as z, z as B, B as S, D as q, E as D, G as E, H as V, I as w } from "./index-4OY62Yxz.js";
|
|
2
2
|
export {
|
|
3
3
|
e as ActionButton,
|
|
4
4
|
t as Avatar,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linktr.ee/messaging-react",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.1-rc-1784609552",
|
|
4
4
|
"description": "React messaging components built on messaging-core for web applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@linktr.ee/component-library": "11.8.6",
|
|
53
|
-
"@linktr.ee/messaging-core": "
|
|
53
|
+
"@linktr.ee/messaging-core": "2.3.0-rc-1784609552",
|
|
54
54
|
"@phosphor-icons/react": "^2.1.10"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
import { renderWithProviders, screen } from '../../test/utils'
|
|
5
5
|
|
|
@@ -276,4 +276,132 @@ describe('CustomMessageInput', () => {
|
|
|
276
276
|
expect(screen.queryByText(/should not show/i)).not.toBeInTheDocument()
|
|
277
277
|
expect(screen.getByTestId('stream-message-input')).toBeInTheDocument()
|
|
278
278
|
})
|
|
279
|
+
|
|
280
|
+
// MES-1303: the floating composer overlays the message list, so growing it
|
|
281
|
+
// reserves space via padding-bottom but never moves the viewport. The resize
|
|
282
|
+
// observer re-pins the thread to the latest message when the composer grows —
|
|
283
|
+
// but only if the user was already at the bottom.
|
|
284
|
+
describe('re-pins the thread when the floating composer grows (MES-1303)', () => {
|
|
285
|
+
// Render the floating composer inside the real layout structure so its
|
|
286
|
+
// `parentElement` is `.messaging-channel-layout` and it can find the Stream
|
|
287
|
+
// scroll container the way it does in ChannelView.
|
|
288
|
+
const renderInLayout = () =>
|
|
289
|
+
renderWithProviders(
|
|
290
|
+
<div className="messaging-channel-layout">
|
|
291
|
+
<div className="messaging-channel-message-list--floating">
|
|
292
|
+
{/* `.str-chat__list` is the real scroll viewport (overflow-y:
|
|
293
|
+
auto); the re-pin targets it, not the padded content wrapper. */}
|
|
294
|
+
<div className="str-chat__list" data-testid="scroller" />
|
|
295
|
+
</div>
|
|
296
|
+
<CustomMessageInput
|
|
297
|
+
composerInput={() => <div data-testid="custom-composer" />}
|
|
298
|
+
/>
|
|
299
|
+
</div>
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
// Force jsdom's zero-valued scroll geometry to a chosen shape. jsdom has no
|
|
303
|
+
// layout engine, so setProperty can't grow scrollHeight the way a browser
|
|
304
|
+
// reflow would; we set the post-growth geometry directly.
|
|
305
|
+
const setScrollGeometry = (
|
|
306
|
+
el: HTMLElement,
|
|
307
|
+
{ scrollHeight, clientHeight, scrollTop }: Record<string, number>
|
|
308
|
+
) => {
|
|
309
|
+
Object.defineProperty(el, 'scrollHeight', {
|
|
310
|
+
value: scrollHeight,
|
|
311
|
+
configurable: true,
|
|
312
|
+
})
|
|
313
|
+
Object.defineProperty(el, 'clientHeight', {
|
|
314
|
+
value: clientHeight,
|
|
315
|
+
configurable: true,
|
|
316
|
+
})
|
|
317
|
+
el.scrollTop = scrollTop
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Simulate the composer growing/shrinking. The observer only re-pins when
|
|
321
|
+
// the composer's offsetHeight increased; jsdom reports 0, so set it
|
|
322
|
+
// explicitly. Mounts with height 0, so any positive value reads as growth.
|
|
323
|
+
const setComposerHeight = (container: HTMLElement, height: number) => {
|
|
324
|
+
const composer = container.querySelector(
|
|
325
|
+
'.messaging-composer-chrome--floating'
|
|
326
|
+
) as HTMLElement
|
|
327
|
+
Object.defineProperty(composer, 'offsetHeight', {
|
|
328
|
+
value: height,
|
|
329
|
+
configurable: true,
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let resizeCallback: ResizeObserverCallback | undefined
|
|
334
|
+
|
|
335
|
+
beforeEach(() => {
|
|
336
|
+
mockChannelData = {}
|
|
337
|
+
resizeCallback = undefined
|
|
338
|
+
vi.stubGlobal(
|
|
339
|
+
'ResizeObserver',
|
|
340
|
+
class {
|
|
341
|
+
constructor(cb: ResizeObserverCallback) {
|
|
342
|
+
resizeCallback = cb
|
|
343
|
+
}
|
|
344
|
+
observe() {}
|
|
345
|
+
unobserve() {}
|
|
346
|
+
disconnect() {}
|
|
347
|
+
}
|
|
348
|
+
)
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
afterEach(() => {
|
|
352
|
+
vi.unstubAllGlobals()
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
it('scrolls to the bottom when the composer grows and the user was at the bottom', () => {
|
|
356
|
+
const { container } = renderInLayout()
|
|
357
|
+
const scroller = screen.getByTestId('scroller')
|
|
358
|
+
|
|
359
|
+
// At the bottom: scrollHeight - scrollTop - clientHeight = 0.
|
|
360
|
+
setScrollGeometry(scroller, {
|
|
361
|
+
scrollHeight: 560,
|
|
362
|
+
clientHeight: 300,
|
|
363
|
+
scrollTop: 260,
|
|
364
|
+
})
|
|
365
|
+
setComposerHeight(container, 200) // grew from 0
|
|
366
|
+
|
|
367
|
+
resizeCallback?.([], {} as ResizeObserver)
|
|
368
|
+
|
|
369
|
+
expect(scroller.scrollTop).toBe(560)
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
it('leaves the scroll position alone when the user has scrolled up', () => {
|
|
373
|
+
const { container } = renderInLayout()
|
|
374
|
+
const scroller = screen.getByTestId('scroller')
|
|
375
|
+
|
|
376
|
+
// Scrolled up reading history: distance from bottom (600px) is well over
|
|
377
|
+
// the threshold.
|
|
378
|
+
setScrollGeometry(scroller, {
|
|
379
|
+
scrollHeight: 1000,
|
|
380
|
+
clientHeight: 300,
|
|
381
|
+
scrollTop: 100,
|
|
382
|
+
})
|
|
383
|
+
setComposerHeight(container, 200) // grew, but user is not near the bottom
|
|
384
|
+
|
|
385
|
+
resizeCallback?.([], {} as ResizeObserver)
|
|
386
|
+
|
|
387
|
+
expect(scroller.scrollTop).toBe(100)
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
it('does not re-pin when the composer did not grow (shrink / width-only resize)', () => {
|
|
391
|
+
renderInLayout()
|
|
392
|
+
const scroller = screen.getByTestId('scroller')
|
|
393
|
+
|
|
394
|
+
// User is at the bottom, but the composer height is unchanged (0 → 0),
|
|
395
|
+
// e.g. a width-only window resize — nothing new covers the last message.
|
|
396
|
+
setScrollGeometry(scroller, {
|
|
397
|
+
scrollHeight: 560,
|
|
398
|
+
clientHeight: 300,
|
|
399
|
+
scrollTop: 260,
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
resizeCallback?.([], {} as ResizeObserver)
|
|
403
|
+
|
|
404
|
+
expect(scroller.scrollTop).toBe(260)
|
|
405
|
+
})
|
|
406
|
+
})
|
|
279
407
|
})
|
|
@@ -23,6 +23,16 @@ import { CustomLinkPreviewList } from '../CustomLinkPreviewList'
|
|
|
23
23
|
*/
|
|
24
24
|
const ComposerLockedContext = React.createContext(false)
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Distance from the bottom (px) still treated as "at the latest message", used
|
|
28
|
+
* to decide whether a growing composer should re-pin the thread to the bottom
|
|
29
|
+
* (MES-1303). Matches stream-chat-react's own `scrolledUpThreshold` default
|
|
30
|
+
* (200) so composer growth keeps the thread pinned under the same condition
|
|
31
|
+
* Stream already auto-scrolls a new message — anything closer than one message
|
|
32
|
+
* would let a user resting just off the bottom fall through and get covered.
|
|
33
|
+
*/
|
|
34
|
+
const NEAR_BOTTOM_THRESHOLD_PX = 200
|
|
35
|
+
|
|
26
36
|
/**
|
|
27
37
|
* Read the composer's locked (frozen-channel) state from inside a custom
|
|
28
38
|
* composer supplied via `composerInput`. Returns true when the channel is
|
|
@@ -169,11 +179,49 @@ export const CustomMessageInput: React.FC<CustomMessageInputProps> = ({
|
|
|
169
179
|
return
|
|
170
180
|
}
|
|
171
181
|
|
|
182
|
+
// Track the composer height across resizes so we can re-pin only when it
|
|
183
|
+
// actually grows (see below).
|
|
184
|
+
let previousComposerHeight = composer.offsetHeight
|
|
185
|
+
|
|
172
186
|
const updateComposerHeight = () => {
|
|
187
|
+
// The floating composer overlays the message list; growing it only
|
|
188
|
+
// reserves space via padding-bottom, which never moves the viewport, so
|
|
189
|
+
// a taller composer creeps up over the last message (MES-1303). Capture
|
|
190
|
+
// whether the thread is pinned to the latest message *before* the padding
|
|
191
|
+
// grows, then re-pin afterwards.
|
|
192
|
+
const nextComposerHeight = composer.offsetHeight
|
|
193
|
+
// Only growth can cover the latest message: shrinks free up space and
|
|
194
|
+
// width-only resizes (window/layout changes) cover nothing, so re-pinning
|
|
195
|
+
// then would needlessly yank a user resting just off the bottom.
|
|
196
|
+
const grew = nextComposerHeight > previousComposerHeight
|
|
197
|
+
previousComposerHeight = nextComposerHeight
|
|
198
|
+
|
|
199
|
+
// The scroll viewport is Stream's `.str-chat__list` (overflow-y: auto);
|
|
200
|
+
// its child `.str-chat__message-list-scroll` holds the padding but has
|
|
201
|
+
// overflow: visible and never scrolls. The redesigned empty state also
|
|
202
|
+
// renders a placeholder `.str-chat__list`, so select the one that is
|
|
203
|
+
// actually scrollable rather than the first match — that is also the only
|
|
204
|
+
// one where re-pinning can do anything.
|
|
205
|
+
const scroller =
|
|
206
|
+
Array.from(
|
|
207
|
+
layout.querySelectorAll<HTMLElement>('.str-chat__list')
|
|
208
|
+
).find((el) => el.scrollHeight > el.clientHeight) ?? null
|
|
209
|
+
// Guarded on `wasAtBottom` so we never yank a user reading history.
|
|
210
|
+
const wasAtBottom = scroller
|
|
211
|
+
? scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight <
|
|
212
|
+
NEAR_BOTTOM_THRESHOLD_PX
|
|
213
|
+
: false
|
|
214
|
+
|
|
173
215
|
layout.style.setProperty(
|
|
174
216
|
'--messaging-composer-height',
|
|
175
|
-
`${
|
|
217
|
+
`${nextComposerHeight + 16}px`
|
|
176
218
|
)
|
|
219
|
+
|
|
220
|
+
// Reading scrollHeight forces a synchronous reflow, so it reflects the
|
|
221
|
+
// padding-bottom we just set; scrolling to it pins the true bottom.
|
|
222
|
+
if (grew && wasAtBottom && scroller) {
|
|
223
|
+
scroller.scrollTop = scroller.scrollHeight
|
|
224
|
+
}
|
|
177
225
|
}
|
|
178
226
|
|
|
179
227
|
updateComposerHeight()
|
package/dist/index-34_jzKSz.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("react/jsx-runtime"),h=require("react"),Mt=require("@linktr.ee/messaging-core"),Be=require("stream-chat"),w=require("stream-chat-react"),_=require("@phosphor-icons/react"),S=require("classnames"),qe=require("stream-chat-react/experimental"),Bs=h.createContext({service:null,client:null,isConnected:!1,isLoading:!1,error:null,capabilities:{},refreshConnection:async()=>{},debug:!1}),We=()=>h.useContext(Bs),At=({children:e,user:t,serviceConfig:n,apiKey:a,capabilities:r={},debug:i=!1,client:o})=>{var C,M;const l=h.useCallback((A,...O)=>{i&&console.log(`🔥 [MessagingProvider] ${A}`,...O)},[i]);l("🔄 RENDER START",{userId:t==null?void 0:t.id,apiKey:(a==null?void 0:a.substring(0,8))+"...",serviceConfig:!!n,capabilities:Object.keys(r)});const[d,u]=h.useState(null),[x,m]=h.useState(null),[f,c]=h.useState(!1),[p,b]=h.useState(!1),[v,g]=h.useState(null),N=h.useRef(!1),j=h.useRef(null),E=h.useRef(n);E.current=n;const P=h.useRef(i);P.current=i;const I=h.useRef({userId:t==null?void 0:t.id,apiKey:a,serviceConfig:n,capabilities:r}),L=h.useRef(0);L.current++,l("📊 RENDER INFO",{renderCount:L.current,currentProps:{userId:t==null?void 0:t.id,apiKey:(a==null?void 0:a.substring(0,8))+"..."},propChanges:{userChanged:I.current.userId!==(t==null?void 0:t.id),apiKeyChanged:I.current.apiKey!==a,serviceConfigChanged:I.current.serviceConfig!==n,capabilitiesChanged:I.current.capabilities!==r}}),I.current={userId:t==null?void 0:t.id,apiKey:a,serviceConfig:n,capabilities:r};const $=h.useRef(null);!o&&a&&((C=$.current)==null?void 0:C.apiKey)!==a&&($.current={apiKey:a,client:new Be.StreamChat(a)});const z=o||(a?((M=$.current)==null?void 0:M.client)??null:null);h.useEffect(()=>{const A=L.current,O=E.current;if(o){j.current=null,u(null),m(null),c(!1),g(null),b(!1);return}if(!a||!z||!O){l("⚠️ SERVICE INIT SKIPPED",{renderCount:A,reason:"Missing apiKey, client, or serviceConfig"});return}l("🚀 CREATING SERVICE",{renderCount:A,apiKey:(a==null?void 0:a.substring(0,8))+"..."});const U=new Mt.StreamChatService({...O,apiKey:a,debug:P.current,client:z});j.current=U,u(U),l("✅ SERVICE SET",{renderCount:A,serviceInstance:!!U})},[a,z,o]);const D=h.useRef(null);h.useEffect(()=>{var O,U;if(l("🔗 USER CONNECTION EFFECT TRIGGERED",{hasService:!!d,hasUser:!!t,userId:t==null?void 0:t.id,isConnecting:N.current,isConnected:f,dependencies:{service:!!d,userId:t==null?void 0:t.id}}),o)return;if(!d||!t){l("⚠️ USER CONNECTION SKIPPED","Missing service or user");return}if(N.current){l("⚠️ USER CONNECTION SKIPPED","Already connecting");return}if(((O=D.current)==null?void 0:O.serviceId)===d&&((U=D.current)==null?void 0:U.userId)===t.id){l("⚠️ USER CONNECTION SKIPPED","Already connected this user with this service");return}(async()=>{l("🚀 STARTING USER CONNECTION",{userId:t.id}),N.current=!0,b(!0),g(null);try{l("📞 CALLING SERVICE.CONNECTUSER",{userId:t.id});const V=await d.connectUser(t);m(V),c(!0),D.current={serviceId:d,userId:t.id},l("✅ USER CONNECTION SUCCESS",{userId:t.id,clientId:V.userID})}catch(V){const X=V instanceof Error?V.message:"Connection failed";g(X),l("❌ USER CONNECTION ERROR",{userId:t.id,error:X})}finally{b(!1),N.current=!1,l("🔄 USER CONNECTION FINISHED",{userId:t.id,isConnected:f})}})()},[d,t,l,f,o]),h.useEffect(()=>{const A=z;return()=>{var O;A&&(D.current=null,(O=j.current)==null||O.disconnectUser().catch(console.error))}},[z]);const k=h.useCallback(async()=>{if(l("🔄 REFRESH CONNECTION CALLED",{hasService:!!d,hasUser:!!t}),!o){if(!d||!t){l("⚠️ REFRESH CONNECTION SKIPPED","Missing service or user");return}l("🚀 STARTING CONNECTION REFRESH",{userId:t.id}),b(!0);try{l("🔌 DISCONNECTING FOR REFRESH"),await d.disconnectUser(),l("📞 RECONNECTING FOR REFRESH");const A=await d.connectUser(t);m(A),c(!0),g(null),l("✅ CONNECTION REFRESH SUCCESS",{userId:t.id})}catch(A){const O=A instanceof Error?A.message:"Refresh failed";g(O),l("❌ CONNECTION REFRESH ERROR",{userId:t.id,error:O})}finally{b(!1),l("🔄 CONNECTION REFRESH FINISHED",{userId:t.id})}}},[d,t,l,o]),T=h.useMemo(()=>(l("💫 CONTEXT VALUE MEMOIZATION",{hasService:!!d,hasClient:!!x,isConnected:f,isLoading:p,hasError:!!v,capabilitiesKeys:Object.keys(r)}),{service:o?null:d,client:o??x,isConnected:o?!0:f,isLoading:o?!1:p,error:o?null:v,capabilities:r,refreshConnection:k,debug:i}),[d,x,o,f,p,v,r,k,i,l]);return l("🔄 RENDER END",{renderCount:L.current,willRenderChat:!!z,contextValueReady:!!T}),s.jsx(Bs.Provider,{value:T,children:z?s.jsx(w.Chat,{client:z,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})},Vs=()=>We(),Xe=e=>{var a,r;const[t,n]=h.useState(!!((r=(a=e==null?void 0:e.state)==null?void 0:a.membership)!=null&&r.pinned_at));return h.useEffect(()=>{var o;if(!e){n(!1);return}n(!!((o=e.state.membership)!=null&&o.pinned_at));const i=l=>{var d;n(l!=null&&l.member?!!l.member.pinned_at:!!((d=e.state.membership)!=null&&d.pinned_at))};return e.on("member.updated",i),()=>{e.off("member.updated",i)}},[e]),t},Rt="linktree-official",Lt="linktree-official-sender";function pe(e,t,n){const a=Object.values(e||{});if(n===Rt){const r=a.find(i=>{var o;return((o=i.user)==null?void 0:o.id)===Lt});if(r)return r}return a.find(r=>{var i;return((i=r.user)==null?void 0:i.id)&&r.user.id!==t})}const Dt=/^[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 Gs(e){return Dt.test(e.trim())}function Ts(e,t){const n=e==null?void 0:e.trim();return!n||t&&n===t||t&&n===`Follower ${t}`?!1:!Gs(n)}function Te(e){return Ts(e==null?void 0:e.name,e==null?void 0:e.id)?e.name.trim():Ts(e==null?void 0:e.username,e==null?void 0:e.id)?e.username.trim():"Unknown member"}const Ms=[{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 zt(e){let t=0;for(let n=0;n<e.length;n++){const a=e.charCodeAt(n);t=(t<<5)-t+a,t=t&t}return Math.abs(t)}function Ys(e){return Ms[zt(e)%Ms.length]}function Pt(e){return Ys(e).emoji}function Ft(e){return Ys(e).bgColor}const Q=({id:e,image:t,size:n=40,className:a,starred:r=!1,shape:i="squircle",dmAgentEnabled:o=!1})=>{const l=Pt(e),d=Ft(e),u=.45,m=n<32?Math.round(n*u):n<56?14:n<120?18:36,f=n>=40?2:1,c=i==="circle"?{borderRadius:"50%"}:{borderRadius:"1rem"},p=s.jsx("div",{className:"h-full w-full overflow-hidden",style:c,children:t?s.jsx("img",{src:t,alt:"",className:"h-full w-full object-cover"}):s.jsx("div",{"aria-hidden":"true",className:S("avatar-fallback flex h-full w-full items-center justify-center font-semibold select-none transition-colors"),style:{fontSize:m,lineHeight:1},children:l})});return s.jsxs("div",{className:S("relative flex-shrink-0",a),style:{"--str-chat__avatar-size":`${n}px`,width:`${n}px`,height:`${n}px`,backgroundColor:t?void 0:d,...c},children:[r&&s.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:s.jsx(_.StarIcon,{className:"size-3 text-yellow-600",weight:"duotone"})}),s.jsx("div",{"data-testid":"avatar-ring",className:S("h-full w-full","bg-transparent"),style:{...c,...o&&{borderWidth:`${f}px`,borderStyle:"solid",borderColor:"var(--AI-Gradient, #7F22FE)",boxShadow:"inset 0 1px 2px 0 rgba(255, 255, 255, 0.5)"}},children:p})]})},Ot="https://linktr.ee/s/about/trust-center/report",$t=({channel:e,participant:t,showBlockParticipant:n=!0,enabled:a=!0,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:o,onBlockParticipantClick:l,onReportParticipantClick:d,onActionComplete:u,logLabel:x="useChannelModerationActions"})=>{var T;const{service:m,debug:f}=We(),c=(T=t==null?void 0:t.user)==null?void 0:T.id,p=!!(a&&n&&m&&c),[b,v]=h.useState(!1),[g,N]=h.useState(null),[j,E]=h.useState(!1),[P,I]=h.useState(!1),L=p&&((g==null?void 0:g.participantId)!==c||(g==null?void 0:g.service)!==m);return h.useEffect(()=>{if(!p||!m||!c){v(!1),N(null);return}let C=!1;return(async()=>{try{const M=await m.getBlockedUsers();if(C)return;v(M.some(A=>A.blocked_user_id===c))}catch(M){C||console.error(`[${x}] Failed to check blocked status:`,M)}finally{C||N({participantId:c,service:m})}})(),()=>{C=!0}},[p,m,c,x]),{isParticipantBlocked:b,isCheckingBlockedStatus:L,isLeaving:j,isUpdatingBlockStatus:P,handleLeaveConversation:async()=>{var C;if(!j){o==null||o(),f&&console.log(`[${x}] Leave conversation`,e.cid),E(!0);try{const M=((C=e._client)==null?void 0:C.userID)??null;await e.hide(M,!1),r&&await r(e),u==null||u()}catch(M){console.error(`[${x}] Failed to leave conversation`,M)}finally{E(!1)}}},handleBlockUser:async()=>{var C,M,A;if(!(P||!m)){l==null||l(),f&&console.log(`[${x}] Block member`,(C=t==null?void 0:t.user)==null?void 0:C.id),I(!0);try{await m.blockUser((M=t==null?void 0:t.user)==null?void 0:M.id),i&&await i((A=t==null?void 0:t.user)==null?void 0:A.id),u==null||u()}catch(O){console.error(`[${x}] Failed to block member`,O)}finally{I(!1)}}},handleUnblockUser:async()=>{var C,M,A;if(!(P||!m)){l==null||l(),f&&console.log(`[${x}] Unblock member`,(C=t==null?void 0:t.user)==null?void 0:C.id),I(!0);try{await m.unBlockUser((M=t==null?void 0:t.user)==null?void 0:M.id),i&&await i((A=t==null?void 0:t.user)==null?void 0:A.id),u==null||u()}catch(O){console.error(`[${x}] Failed to unblock member`,O)}finally{I(!1)}}},handleReportUser:()=>{d==null||d(),u==null||u(),window.open(Ot,"_blank","noopener,noreferrer")}}},he=({variant:e="default",className:t,children:n,...a})=>{const r=e==="danger";return s.jsx("button",{type:"button",className:S("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",t),...a,children:n})},Ve=({channel:e,participant:t,showDeleteConversation:n=!0,showBlockParticipant:a=!0,showReportParticipant:r=!0,onLeaveConversation:i,onBlockParticipant:o,onDeleteConversationClick:l,onBlockParticipantClick:d,onReportParticipantClick:u,customChannelActions:x,triggerClassName:m})=>{const[f,c]=h.useState(!1),p=h.useRef(null),b=h.useId(),v=h.useCallback(()=>c(!1),[]),{isParticipantBlocked:g,isCheckingBlockedStatus:N,isLeaving:j,isUpdatingBlockStatus:E,handleLeaveConversation:P,handleBlockUser:I,handleUnblockUser:L,handleReportUser:$}=$t({channel:e,participant:t,showBlockParticipant:a,enabled:f,onLeaveConversation:i,onBlockParticipant:o,onDeleteConversationClick:l,onBlockParticipantClick:d,onReportParticipantClick:u,onActionComplete:v,logLabel:"ChannelActionsMenu"});return h.useEffect(()=>{if(!f)return;const D=T=>{p.current&&!p.current.contains(T.target)&&c(!1)},k=T=>{T.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",D),document.addEventListener("keydown",k),()=>{document.removeEventListener("mousedown",D),document.removeEventListener("keydown",k)}},[f]),!t||!(n||a||r||!!x)?null:s.jsxs("div",{ref:p,className:"relative",children:[s.jsxs("button",{className:m,type:"button","aria-haspopup":"true","aria-expanded":f,"aria-controls":f?b:void 0,onClick:()=>c(D=>!D),children:[s.jsx(_.DotsThreeIcon,{className:"size-5 text-black/90"}),s.jsx("span",{className:"sr-only",children:"More options"})]}),f&&s.jsx("div",{id:b,"aria-label":"Conversation options",className:S("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:s.jsxs("ul",{className:"flex flex-col gap-1",children:[n&&s.jsx("li",{children:s.jsxs(he,{onClick:P,disabled:j,"aria-busy":j,children:[j?s.jsx(_.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):s.jsx(_.SignOutIcon,{className:"h-5 w-5"}),s.jsx("span",{children:"Delete Conversation"})]})}),a&&s.jsx("li",{children:N?s.jsxs(he,{disabled:!0,"aria-busy":!0,children:[s.jsx(_.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}),s.jsx("span",{children:"Block"})]}):g?s.jsxs(he,{onClick:L,disabled:E,"aria-busy":E,children:[E?s.jsx(_.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):s.jsx(_.ProhibitInsetIcon,{className:"h-5 w-5"}),s.jsx("span",{children:"Unblock"})]}):s.jsxs(he,{onClick:I,disabled:E,"aria-busy":E,children:[E?s.jsx(_.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):s.jsx(_.ProhibitInsetIcon,{className:"h-5 w-5"}),s.jsx("span",{children:"Block"})]})}),r&&s.jsx("li",{children:s.jsxs(he,{variant:"danger",onClick:$,children:[s.jsx(_.FlagIcon,{className:"h-5 w-5"}),s.jsx("span",{children:"Report"})]})}),x]})})]})},ze="flex size-10 flex-shrink-0 items-center justify-center rounded-full bg-white/65 shadow-[0px_4px_8px_0px_rgba(0,0,0,0.06),0px_0px_0px_1px_rgba(0,0,0,0.04)] backdrop-blur-[40px] transition-filter duration-150 hover:brightness-95 aria-expanded:brightness-95 focus-ring",Ut="CUSTOMER_PAID",Bt="Replies instantly with AI assistant",Vt=e=>typeof e=="string"&&e.trim().replace(/[\s-]+/g,"_").toUpperCase()===Ut,Gt=({className:e,onBack:t,showBackButton:n,showStarButton:a=!1,dmAgentEnabled:r=!1,onLeaveConversation:i,onBlockParticipant:o,showDeleteConversation:l=!0,showBlockParticipant:d=!0,showReportParticipant:u=!0,onDeleteConversationClick:x,onBlockParticipantClick:m,onReportParticipantClick:f,customChannelActions:c,renderChannelActions:p,showChannelInfo:b=!0,onParticipantNameClick:v})=>{var z,D,k,T;const{channel:g}=w.useChannelStateContext(),{client:N}=w.useChatContext(),j=h.useMemo(()=>{var C;return pe((C=g.state)==null?void 0:C.members,N==null?void 0:N.userID,g.type)},[(z=g.state)==null?void 0:z.members,N==null?void 0:N.userID,g.type]),E=Te(j==null?void 0:j.user),P=(D=j==null?void 0:j.user)==null?void 0:D.image,I=Xe(g),L=Vt((k=g.data)==null?void 0:k.customer_tag)&&(j==null?void 0:j.is_follower)===!0,$=async()=>{try{I?await g.unpin():await g.pin()}catch(C){console.error("[ChannelHeaderRedesign] Failed to update pinned status:",C)}};return s.jsx("div",{className:S("@container bg-[linear-gradient(180deg,#FBFAF9_0%,rgba(251,250,249,0.92)_58%,rgba(251,250,249,0)_100%)]",e),children:s.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:[s.jsx("div",{className:"flex items-start",children:n&&s.jsx("button",{className:S(ze,"messaging-channel-view-back-button-mobile messaging-channel-view-back-button-desktop"),onClick:t||(()=>{}),type:"button","aria-label":"Back to conversations",children:s.jsx(_.ArrowLeftIcon,{className:"size-5 text-black/90"})})}),s.jsx("div",{className:"flex min-w-0 justify-center","data-dd-privacy":"mask",children:s.jsxs("button",{type:"button",onClick:v,"aria-label":`View details for ${E}`,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:[s.jsx(Q,{id:((T=j==null?void 0:j.user)==null?void 0:T.id)||g.id||"unknown",name:E,image:P,dmAgentEnabled:r,shape:"circle",size:48,className:"-mb-2"}),s.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:[s.jsxs("span",{className:"flex max-w-full items-center justify-center",children:[s.jsx("span",{className:"min-w-0 truncate text-sm font-bold leading-[1.43] tracking-[0.28px] text-black/90",children:E}),s.jsxs("span",{className:"ml-2 flex gap-1",children:[L&&s.jsx("span",{"aria-label":"Paid customer",className:"flex size-4 shrink-0 items-center justify-center rounded-full bg-[#34C759] text-white",children:s.jsx(_.CurrencyDollarIcon,{className:"size-2.5",weight:"bold"})}),a&&I&&s.jsx("span",{"aria-label":"Starred conversation",className:"flex size-4 shrink-0 items-center justify-center rounded-full bg-[#FFD60A] text-white",children:s.jsx(_.StarIcon,{className:"size-2.5",weight:"fill"})}),s.jsx(_.CaretRightIcon,{"aria-hidden":"true",className:"size-4 shrink-0 text-black/65",weight:"bold"})]})]}),r&&s.jsxs("span",{className:"mt-1 flex items-center gap-1 px-1 pb-0.5 text-[10px] leading-3 text-black/55",children:[s.jsx(_.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),s.jsx("span",{children:Bt})]})]})]})}),s.jsxs("div",{className:"flex items-start justify-end gap-2",children:[a&&s.jsx("button",{className:ze,onClick:$,type:"button","aria-pressed":I,"aria-label":I?"Unstar conversation":"Star conversation",children:s.jsx(_.StarIcon,{className:S("size-5",{"text-[#FFD60A]":I,"text-black/90":!I}),weight:I?"fill":"regular"})}),b&&(p!==void 0?p:s.jsx(Ve,{channel:g,participant:j,showDeleteConversation:l,showBlockParticipant:d,showReportParticipant:u,onLeaveConversation:i,onBlockParticipant:o,onDeleteConversationClick:x,onBlockParticipantClick:m,onReportParticipantClick:f,customChannelActions:c,triggerClassName:ze}))]})]})})},Yt=e=>s.jsx(w.DateSeparator,{...e,position:"center"}),Ge="vote_up",Ye="vote_down";function Ht(e){return e!=null&&e.length?e.some(t=>t.type===Ye)?"down":e.some(t=>t.type===Ge)?"up":null:null}function Hs(e){const{channel:t}=w.useChannelStateContext(),{client:n}=w.useChatContext("useMessageVote"),a=h.useMemo(()=>Ht(e.own_reactions),[e.own_reactions]),r=h.useCallback(async()=>{if(n!=null&&n.userID)try{a==="up"?await t.deleteReaction(e.id,Ge):await t.sendReaction(e.id,{type:Ge},{enforce_unique:!0,skip_push:!0})}catch{}},[t,n==null?void 0:n.userID,e.id,a]),i=h.useCallback(async()=>{if(n!=null&&n.userID)try{a==="down"?await t.deleteReaction(e.id,Ye):await t.sendReaction(e.id,{type:Ye},{enforce_unique:!0,skip_push:!0})}catch{}},[t,n==null?void 0:n.userID,e.id,a]);return{selected:a,voteUp:r,voteDown:i}}function qs(e){return(e==null?void 0:e.trim().toLowerCase().split(/[-_]/)[0])||void 0}function Ke({message:e,viewerLanguage:t}){var r;const n=e==null?void 0:e.text,a=qs(t);return a?((r=e==null?void 0:e.i18n)==null?void 0:r[`${a}_text`])??n:n}const qt=["linktr.ee"],As="messaging-attachment-v1_0";function Wt(e){try{return new URL(e).hostname.toLowerCase()}catch{return null}}function Xt(e){return qt.some(t=>e===t||e.endsWith(`.${t}`))}function ae(e){const t=e==null?void 0:e.trim();if(!t)return;const n=Wt(t);if(!n||!Xt(n))return t;const a=new URL(t);return a.searchParams.get("io")==="true"&&a.searchParams.get("size")===As?t:(a.searchParams.set("io","true"),a.searchParams.set("size",As),a.toString())}const Kt=[[/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 Ws(e){const t=Kt.find(([n])=>n.test(e));return t?t[1]:"generic"}const Zt={video:_.VideoCameraIcon,audio:_.SpeakerHighIcon,image:_.ImageIcon,document:_.FileIcon},Jt={pdf:_.FilePdfIcon,doc:_.FileDocIcon,xls:_.FileXlsIcon,csv:_.FileCsvIcon,ppt:_.FilePptIcon,zip:_.FileZipIcon,text:_.FileTextIcon,markdown:_.FileMdIcon,generic:_.FileIcon};function Qt(e){const t=te(e);return t!=="document"?Zt[t]:Jt[Ws(e)]}function oe(e,t){return h.createElement(Qt(e),t)}const en=e=>{var t,n;return"touches"in e?((t=e.touches[0])==null?void 0:t.clientX)??((n=e.changedTouches[0])==null?void 0:n.clientX)??0:e.clientX},sn=({source:e,mimeType:t,poster:n,autoPlay:a=!1,playing:r,loop:i=!1,controls:o=!0,showProgress:l=!1,muted:d=!1,onContainerClick:u})=>{const x=te(t),m=h.useRef(null),f=h.useRef(null),c=h.useRef(null),p=h.useRef(r),[b,v]=h.useState(a),[g,N]=h.useState(0),[j,E]=h.useState(!1),[P,I]=h.useState(!1),[L,$]=h.useState(!1),[z,D]=h.useState(!1),[k,T]=h.useState(!0),[C,M]=h.useState(null),A=h.useCallback(()=>{$(!1),v(!0)},[]),O=h.useCallback(y=>{const R=f.current;if(!R)return 0;const G=R.getBoundingClientRect();return Math.max(0,Math.min(1,(en(y)-G.left)/G.width))},[]),U=h.useCallback(y=>{const R=m.current;R&&R.duration&&(R.currentTime=y*R.duration)},[]),V=y=>{y.stopPropagation(),E(!0);const R=O(y);N(R),U(R)};h.useEffect(()=>{r!==void 0&&r!==p.current&&(p.current=r,v(r))},[r]),h.useEffect(()=>{if(!b){c.current!==null&&(cancelAnimationFrame(c.current),c.current=null);return}const y=()=>{const R=m.current;R&&R.duration&&!j&&N(R.currentTime/R.duration),c.current=requestAnimationFrame(y)};return c.current=requestAnimationFrame(y),()=>{c.current!==null&&cancelAnimationFrame(c.current)}},[b,j]),h.useEffect(()=>{const y=m.current;y&&(b?y.play().catch(R=>{v(!1),$(!0)}):y.pause())},[b]),h.useEffect(()=>{if(!j)return;const y=G=>N(O(G)),R=G=>{E(!1),U(O(G))};return window.addEventListener("mousemove",y),window.addEventListener("mouseup",R),window.addEventListener("touchmove",y,{passive:!0}),window.addEventListener("touchend",R),()=>{window.removeEventListener("mousemove",y),window.removeEventListener("mouseup",R),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",R)}},[j,O,U]);const X=C?{aspectRatio:String(C)}:void 0,Z=C?"":" aspect-video",W=Math.round(g*100);return s.jsxs("div",{role:"button",tabIndex:0,className:`relative cursor-pointer overflow-hidden bg-black ${Z}`,style:X,onClick:y=>{if(u){u(y);return}L||o&&v(R=>!R)},onKeyDown:y=>{if(!(y.key!=="Enter"&&y.key!==" ")){if(y.preventDefault(),u){u(y);return}L||o&&v(R=>!R)}},children:[n&&(x==="audio"||k)&&s.jsx("img",{src:n,alt:"",className:"absolute inset-0 h-full w-full object-cover"}),!n&&(x==="audio"||k)&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:oe(t,{className:"size-12 text-black/20",weight:"regular"})}),s.jsx("div",{className:"absolute inset-0",children:x==="audio"?s.jsx("audio",{ref:m,src:e,loop:i,muted:d,style:{width:"100%",height:"100%"},onLoadStart:()=>D(!0),onCanPlay:()=>{D(!1),T(!1)},onWaiting:()=>D(!0),onPlay:()=>$(!1),onEnded:()=>{i||(v(!1),N(0))},children:s.jsx("track",{kind:"captions"})}):s.jsx("video",{ref:m,src:e,loop:i,muted:d,playsInline:!0,style:{width:"100%",height:"100%"},onLoadStart:()=>D(!0),onCanPlay:()=>{D(!1),T(!1)},onWaiting:()=>D(!0),onPlay:()=>$(!1),onLoadedMetadata:()=>{const y=m.current;y instanceof HTMLVideoElement&&y.videoWidth&&y.videoHeight&&M(y.videoWidth/y.videoHeight)},onEnded:()=>{i||(v(!1),N(0))},children:s.jsx("track",{kind:"captions"})})}),z&&!L&&s.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center",children:s.jsx(_.CircleNotchIcon,{className:"size-8 animate-spin text-white/80",weight:"bold"})}),L&&!o&&s.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:y=>{y.stopPropagation(),A()},onKeyDown:y=>{y.key!=="Enter"&&y.key!==" "||(y.preventDefault(),y.stopPropagation(),A())},children:s.jsx("span",{className:"flex size-16 items-center justify-center rounded-full bg-white/20 text-white backdrop-blur-sm",children:s.jsx(_.PlayIcon,{className:"size-9 translate-x-0.5",weight:"fill"})})}),l&&!o&&s.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:s.jsx("div",{role:"slider","aria-label":"Playback position","aria-valuenow":W,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,ref:f,className:"relative flex h-4 w-full cursor-pointer items-center",onMouseDown:V,onTouchStart:V,onClick:y=>y.stopPropagation(),onKeyDown:y=>{y.key==="ArrowRight"&&U(Math.min(1,g+.05)),y.key==="ArrowLeft"&&U(Math.max(0,g-.05))},children:s.jsx("div",{className:"w-full overflow-hidden rounded-full bg-white/30 h-1",children:s.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${W}%`}})})})}),o&&s.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:[s.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),v(R=>!R)},className:"shrink-0 text-white","aria-label":b?"Pause":"Play",children:b?s.jsx(_.PauseIcon,{className:"size-5",weight:"fill"}):s.jsx(_.PlayIcon,{className:"size-5 translate-x-px",weight:"fill"})}),s.jsxs("div",{role:"slider","aria-label":"Playback position","aria-valuenow":W,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,ref:f,className:"relative flex h-4 w-full cursor-pointer items-center",onMouseDown:V,onTouchStart:V,onClick:y=>y.stopPropagation(),onMouseEnter:()=>I(!0),onMouseLeave:()=>I(!1),onKeyDown:y=>{y.key==="ArrowRight"&&U(Math.min(1,g+.05)),y.key==="ArrowLeft"&&U(Math.max(0,g-.05))},children:[s.jsx("div",{className:`w-full overflow-hidden rounded-full bg-white/30 transition-all duration-200 ${P||j?"h-1.5":"h-1"}`,children:s.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${W}%`}})}),s.jsx("div",{className:`absolute size-3 -translate-x-1/2 rounded-full bg-white shadow transition-[opacity,transform] duration-200 ${P||j?"scale-100 opacity-100":"scale-0 opacity-0"}`,style:{left:`${W}%`}})]})]})]})},Rs=e=>e==="dark"?"size-12 text-white/20":"size-12 text-black/20",tn=e=>e==="dark"?"aspect-video overflow-hidden bg-white/10":"aspect-video overflow-hidden bg-black/5",Ze=({mimeType:e,sourceUrl:t,thumbnailUrl:n,title:a,variant:r,mediaPlayerProps:i,containedImage:o=!1})=>{const l=te(e),[d,u]=h.useState(!1),x=ae(t),m=ae(n);return t&&(l==="video"||l==="audio")?s.jsx(sn,{source:t,mimeType:e,poster:m,controls:!0,...i}):t&&l==="image"?o?s.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:s.jsx("img",{src:x??t,alt:a??"",className:`absolute inset-0 h-full w-full object-contain transition-opacity duration-300 ${d?"opacity-100":"opacity-0"}`,draggable:!1,onLoad:()=>u(!0)})}):s.jsx("img",{src:x??t,alt:a??"",className:"block w-full",draggable:!1}):t&&l==="document"?n?o?s.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:s.jsx("img",{src:m??n,alt:a??"",className:`absolute inset-0 h-full w-full object-contain transition-opacity duration-300 ${d?"opacity-100":"opacity-0"}`,draggable:!1,onLoad:()=>u(!0)})}):s.jsx("img",{src:m??n,alt:"",className:"block w-full",draggable:!1}):s.jsx("div",{className:`flex aspect-video w-full items-center justify-center ${r==="dark"?"bg-white/10":"bg-black/5"}`,children:oe(e,{className:Rs(r),weight:"regular"})}):n?s.jsx("div",{className:`relative ${tn(r)}`,children:s.jsx("img",{src:m??n,alt:a??"",draggable:!1,className:"absolute inset-0 h-full w-full object-cover"})}):s.jsx("div",{className:`flex aspect-video w-full items-center justify-center ${r==="dark"?"bg-white/10":"bg-black/5"}`,children:oe(e,{className:Rs(r),weight:"regular"})})},Xs=({variant:e,thumbnail:t,title:n,placeholderTitle:a="Attachment title",mimeType:r,detail:i,statusBadge:o,action:l,topLeft:d,topRight:u,rootRef:x,"data-testid":m})=>{const f=e==="dark",c=f?n??a:n??"",p=f&&!n;return s.jsxs("div",{ref:x,"data-testid":m,className:S("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)]",f?"bg-[#1e2330]":"bg-white"),children:[d?s.jsx("div",{className:"pointer-events-auto absolute left-3 top-3 z-50",children:d}):null,u?s.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-50",children:u}):null,t,s.jsxs("div",{className:"px-4 pb-3 pt-3",children:[c.trim()!==""&&s.jsx("p",{className:S("mb-0.5 truncate text-base font-medium",{"text-black":!f,"text-white/30":f&&p,"text-white":f&&!p}),children:c}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[oe(r,{className:S("size-5 shrink-0",f?"text-white/55":"text-black/55"),weight:"regular"}),i!=null&&i!==""&&s.jsx("span",{className:S("text-xs font-medium",f?"text-white/55":"text-black/55"),children:i}),o]}),l]})]})};function Ks(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Je(e){return`w-[280px] select-none overflow-hidden rounded-[24px] ${e?"bg-[#1e2330]":"bg-[#F3F3F1]"} shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]`}function nn(e){return e?"bg-white/10":"bg-black/5"}function an(e){return e?"text-white":"text-black"}function rn(e){return e?"text-white/55":"text-black/55"}function ln(e){return e?"text-white/40":"text-black/40"}function on(e){return e?"text-white/20":"text-black/20"}const Qe=({attachment:e,isMyMessage:t})=>{const{title:n,text:a,image_url:r,og_scrape_url:i,title_link:o}=e,l=i??o,d=typeof l=="string"&&l.trim()!==""?l:void 0,u=s.jsxs(h.Fragment,{children:[s.jsx("div",{className:"p-2",children:r?s.jsx("img",{src:ae(r)??r,alt:n??"",className:"aspect-video w-full rounded-[20px] object-cover"}):s.jsx("div",{className:`aspect-video w-full rounded-[20px] ${nn(t)} flex items-center justify-center`,children:s.jsx(_.LinkIcon,{className:`size-12 ${on(t)}`})})}),s.jsxs("div",{className:"px-3 pb-3",children:[n&&s.jsx("p",{className:`truncate text-[14px] font-medium leading-5 ${an(t)}`,children:n}),a&&s.jsx("p",{className:`truncate text-[12px] leading-4 ${rn(t)}`,children:a}),d&&s.jsx("p",{className:`mt-1 truncate text-[12px] leading-4 ${ln(t)}`,children:d})]})]});return d?s.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"block no-underline",children:u}):s.jsx("div",{className:"block",children:u})};function es(e){return e.type==="link"||!!e.og_scrape_url&&!e.asset_url}function Me(e){var t;return(t=e.attachments)==null?void 0:t.find(es)}async function cn(e,t){let n;try{n=t??new URL(e).pathname.split("/").pop()??"download"}catch{n=t??"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),o=document.createElement("a");o.href=i,o.download=n,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)}const dn=({url:e,filename:t})=>{const[n,a]=h.useState(!1),r=i=>{i.stopPropagation();const o=window.open("","_blank","noopener,noreferrer");a(!0),cn(e,t).then(()=>{o==null||o.close()}).catch(()=>{o&&(o.location.href=e)}).finally(()=>a(!1))};return s.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?s.jsx(_.CircleNotchIcon,{className:"size-4 animate-spin text-white",weight:"bold"}):s.jsxs(h.Fragment,{children:[s.jsx(_.DownloadSimpleIcon,{className:"size-4 text-white",weight:"bold"}),"Download"]})})};function Ae(e){var m,f,c,p;const t=(m=e.attachments)==null?void 0:m.find(b=>b.type==="video"&&b.asset_url),n=(f=e.attachments)==null?void 0:f.find(b=>b.type==="image"&&b.image_url),a=(c=e.attachments)==null?void 0:c.find(b=>b.type==="audio"&&b.asset_url),r=(p=e.attachments)==null?void 0:p.find(b=>b.type==="file"&&b.asset_url),i=t??n??a??r,o=(t==null?void 0:t.asset_url)??(n==null?void 0:n.image_url)??(a==null?void 0:a.asset_url)??(r==null?void 0:r.asset_url);if(!o)return null;const l=(i==null?void 0:i.mime_type)??((i==null?void 0:i.type)==="image"?"image/jpeg":(i==null?void 0:i.type)==="video"?"video/mp4":(i==null?void 0:i.type)==="audio"?"audio/mpeg":"application/octet-stream"),d=i==null?void 0:i.title,u=i==null?void 0:i.file_size,x=t==null?void 0:t.thumb_url;return{resolvedUrl:o,resolvedType:l,title:d,fileSize:u,thumbnailUrl:x}}const Zs=({resolvedUrl:e,resolvedType:t,title:n,fileSize:a,thumbnailUrl:r})=>{const i=a!==void 0?Ks(a):void 0;return s.jsx(Xs,{variant:"dark",title:n,placeholderTitle:"",mimeType:t,detail:i,thumbnail:s.jsx(Ze,{mimeType:t,sourceUrl:e,thumbnailUrl:r,title:n,variant:"dark"})})},Js=({resolvedUrl:e,resolvedType:t,title:n,fileSize:a,thumbnailUrl:r})=>{const i=te(t),o=a!==void 0?Ks(a):void 0;return s.jsx(Xs,{variant:"light",title:n,mimeType:t,detail:o,thumbnail:s.jsx(Ze,{mimeType:t,sourceUrl:e,thumbnailUrl:r,title:n,variant:"light",containedImage:i==="image"||i==="document"}),action:s.jsx(dn,{url:e,filename:n})})},un=({message:e,isMyMessage:t=!1})=>{const n=Me(e),a=Ae(e);if(!n&&!a)return null;const r=t?"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 s.jsxs("div",{className:r,"data-dd-privacy":"mask",children:[!t&&e.user&&s.jsx(Q,{className:"str-chat__avatar str-chat__message-sender-avatar",id:e.user.id,image:e.user.image,name:e.user.name??e.user.id}),s.jsx("div",{className:"str-chat__message-inner",style:{marginInlineEnd:0,marginInlineStart:0},children:s.jsx("div",{className:"str-chat__message-bubble-wrapper",children:s.jsx("div",{className:"str-chat__message-bubble","data-attachment-bubble":"true",style:{padding:0,borderRadius:0,overflow:"visible",background:"transparent"},children:n?s.jsx("div",{className:Je(t),children:s.jsx(Qe,{attachment:n,isMyMessage:t})}):t?s.jsx(Zs,{...a}):s.jsx(Js,{...a})})})})]})},mn=({message:e})=>{const t=Me(e);if(t)return s.jsx("div",{className:Je(!0),"data-dd-privacy":"mask",children:s.jsx(Qe,{attachment:t,isMyMessage:!0})});const n=Ae(e);return n?s.jsx("div",{style:{display:"contents"},"data-dd-privacy":"mask",children:s.jsx(Zs,{...n})}):null},hn=({message:e})=>{const t=Me(e);if(t)return s.jsx("div",{className:Je(!1),"data-dd-privacy":"mask",children:s.jsx(Qe,{attachment:t,isMyMessage:!1})});const n=Ae(e);return n?s.jsx("div",{style:{display:"contents"},"data-dd-privacy":"mask",children:s.jsx(Js,{...n})}):null},xn=Object.assign(un,{Creator:mn,Visitor:hn}),fn={dark:"bg-[#1e2330]",light:"bg-[#f2f1ef]"},gn={dark:"text-white",light:"text-[#000000]"},pn={dark:"border-white/[0.08]",light:"border-black/[0.08]"},bn=e=>e==="dark"?"sender":"receiver",vn={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]"}},be=({variant:e,text:t,bordered:n=!0,groupPosition:a="single",className:r,children:i,"data-testid":o})=>{const l=t!=null&&t!=="",d=vn[bn(e)][a];return s.jsxs("div",{"data-testid":o,"data-group-position":a,className:S("relative w-[280px] overflow-hidden px-2 py-2",d,fn[e],gn[e],n&&"border",n&&pn[e],r),children:[i,l?s.jsx("p",{className:S("whitespace-pre-wrap break-words leading-snug","pt-2","px-2"),children:t}):null]})},ve=({onClick:e,variant:t="overlay",ariaLabel:n="Dismiss attachment"})=>s.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),e()},"aria-label":n,className:S("flex size-6 items-center justify-center rounded-full text-white",t==="overlay"?"bg-[#121110]/85 backdrop-blur":"bg-white/15 hover:bg-white/25"),children:s.jsx(_.XIcon,{className:"size-3",weight:"bold"})}),je=e=>e==="received"?"light":"dark",Qs=({firstOfGroup:e,endOfGroup:t,groupedByUser:n})=>!n||e&&t?"single":e?"first":t?"end":"middle",jn=({src:e,mimeType:t,filename:n,items:a})=>a&&a.length>0?a:e?[{src:e,mimeType:t,filename:n}]:[],wn=({item:e,preload:t,trailingAction:n})=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("audio",{src:e.src,controls:!0,preload:e.preload??t,className:"block min-w-0 flex-1",children:e.mimeType?s.jsx("source",{src:e.src,type:e.mimeType}):null}),n??null]}),ss=({state:e,src:t,mimeType:n,filename:a,items:r,text:i,groupPosition:o,preload:l,onDismiss:d})=>{const u=je(e),x=e==="composer"&&!!d,m=jn({src:t,mimeType:n,filename:a,items:r});if(m.length===0)return null;const f=l??(m.length>1?"none":"metadata");return s.jsx(be,{variant:u,text:i,groupPosition:o,"data-testid":"audio-attachment",children:s.jsx("div",{className:"flex flex-col gap-2",children:m.map((c,p)=>s.jsx(wn,{item:c,preload:f,trailingAction:x&&p===0?s.jsx(ve,{onClick:d,variant:"inline"}):void 0},`${c.src}-${p}`))})})},_n=e=>s.jsx(ss,{...e,state:"composer"}),Nn=e=>s.jsx(ss,{...e,state:"sent"}),yn=e=>s.jsx(ss,{...e,state:"received"}),kn={Composer:_n,Sent:Nn,Received:yn};function et(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 Cn={pdf:"PDF",doc:"DOC",xls:"XLS",csv:"CSV",ppt:"PPT",zip:"ZIP",text:"TXT",markdown:"MD"};function st(e,t){if(t){const r=t.lastIndexOf(".");if(r>0&&r<t.length-1){const i=t.slice(r+1);if(i&&i.length<=5)return i.toUpperCase()}}if(!e)return;if(te(e)==="document"){const r=Ws(e),i=Cn[r];if(i)return i;if(e==="application/octet-stream")return}const a=e.split("/")[1];if(!(!a||a==="*"))return a.toUpperCase()}function tt(e,t,n){const a=st(e,t),r=typeof n=="number"&&n>0?et(n):void 0;return[a,r].filter(Boolean).join(" · ")||void 0}function se(e){try{const n=new URL(e).pathname.split("/").pop();return n&&n.length>0?decodeURIComponent(n):"download"}catch{return"download"}}const Sn={dark:"text-white/55",light:"text-black/65"},En={dark:"bg-white/10",light:"bg-black/5"},In={dark:"text-white/85",light:"text-black/85"},nt=({variant:e,filename:t,title:n,mimeType:a="application/octet-stream",fileSize:r,onActivate:i,activateLabel:o,trailingAction:l})=>{const d=n??t??"File",u=tt(a,t,r),x=s.jsx("div",{className:S("flex size-10 shrink-0 items-center justify-center rounded-sm",En[e]),"aria-hidden":!0,children:oe(a,{className:S("size-6",In[e]),weight:"regular"})}),m=s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col text-left",children:[s.jsx("p",{className:"truncate font-medium leading-snug",children:d}),u?s.jsx("p",{className:S("truncate text-xs leading-4",Sn[e]),children:u}):null]}),f=i?s.jsxs("button",{type:"button",onClick:i,"aria-label":o,className:S("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:[x,m]}):s.jsxs(s.Fragment,{children:[x,m]});return s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[f,l?s.jsx("div",{className:"shrink-0",children:l}):null]})};async function at(e,t){const n=t??se(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),o=document.createElement("a");o.href=i,o.download=n,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),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 Tn=({src:e,filename:t,fileSize:n,mimeType:a,title:r,items:i})=>i&&i.length>0?i:e?[{src:e,filename:t,fileSize:n,mimeType:a,title:r}]:[],Mn=({variant:e,item:t,index:n,onActivate:a,trailingAction:r})=>{const i=t.filename??se(t.src);return s.jsx(nt,{variant:e,filename:i,title:t.title,mimeType:t.mimeType??"application/octet-stream",fileSize:t.fileSize,onActivate:()=>a(n),activateLabel:`Download ${i}`,trailingAction:r})},ts=({state:e,src:t,filename:n,fileSize:a,mimeType:r,title:i,items:o,text:l,groupPosition:d,onClick:u,onDismiss:x})=>{const m=je(e),f=e==="composer"&&!!x,c=Tn({src:t,filename:n,fileSize:a,mimeType:r,title:i,items:o}),p=v=>{if((u==null?void 0:u(v))===!1)return;const g=c[v];if(!g)return;const N=g.filename??se(g.src);at(g.src,N)};if(c.length===0)return null;const b=s.jsx("span",{className:S("flex size-8 items-center justify-center rounded-full",m==="dark"?"text-white/70":"text-black/70"),"aria-hidden":!0,children:s.jsx(_.DownloadSimpleIcon,{className:"size-5",weight:"bold"})});return s.jsx(be,{variant:m,text:l,groupPosition:d,"data-testid":"file-attachment",children:s.jsx("div",{className:"flex flex-col gap-2",children:c.map((v,g)=>{const N=f&&g===0?s.jsx(ve,{onClick:x,variant:"inline"}):b;return s.jsx(Mn,{variant:m,item:v,index:g,onActivate:p,trailingAction:N},`${v.src}-${g}`)})})})},An=e=>s.jsx(ts,{...e,state:"composer"}),Rn=e=>s.jsx(ts,{...e,state:"sent"}),Ln=e=>s.jsx(ts,{...e,state:"received"}),Dn={Composer:An,Sent:Rn,Received:Ln},ns=({onPrev:e,onNext:t,prevLabel:n="Previous",nextLabel:a="Next"})=>s.jsxs(s.Fragment,{children:[s.jsx("button",{type:"button",onClick:e,"aria-label":n,className:"mes-media-viewer__nav mes-media-viewer__nav--prev",children:s.jsx(_.CaretLeftIcon,{size:20,weight:"bold","aria-hidden":!0})}),s.jsx("button",{type:"button",onClick:t,"aria-label":a,className:"mes-media-viewer__nav mes-media-viewer__nav--next",children:s.jsx(_.CaretRightIcon,{size:20,weight:"bold","aria-hidden":!0})})]}),rt=({url:e,filename:t,variant:n="pill",label:a="Download",iconOnly:r,tone:i="dark",onTriggered:o})=>{const[l,d]=h.useState(!1),u=h.useCallback(c=>{c.stopPropagation(),!l&&(d(!0),at(e,t).catch(()=>{}).finally(()=>{d(!1),o==null||o()}))},[l,e,t,o]),x=r??n!=="pill",f={className:S(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 s.jsx("button",{type:"button",onClick:u,disabled:l,"aria-label":a,className:S("flex size-8 shrink-0 items-center justify-center rounded-full transition-colors disabled:opacity-70",c[i]),children:l?s.jsx(_.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):s.jsx(_.DownloadSimpleIcon,{className:"size-5 shrink-0",weight:"bold","aria-hidden":!0})})}return n==="viewer"?s.jsx("button",{type:"button",onClick:u,disabled:l,"aria-label":a,className:"mes-media-viewer__action",children:l?s.jsx(_.CircleNotchIcon,{size:20,weight:"bold","aria-hidden":!0}):s.jsx(_.DownloadSimpleIcon,{size:20,weight:"bold","aria-hidden":!0})}):s.jsxs("button",{type:"button",onClick:u,disabled:l,"aria-label":x?a:void 0,className:S("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:[l?s.jsx(_.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):s.jsx(_.DownloadSimpleIcon,{...f,"aria-hidden":!0}),x?null:a]})},Pe=(e,t,n)=>Math.min(Math.max(e,t),n),as=({length:e,initialIndex:t,open:n})=>{const a=Pe(t,0,Math.max(e-1,0)),[r,i]=h.useState(a);h.useEffect(()=>{n&&i(Pe(t,0,Math.max(e-1,0)))},[n,t,e]),h.useEffect(()=>{i(d=>Pe(d,0,Math.max(e-1,0)))},[e]);const o=h.useCallback(()=>{e<=1||i(d=>d<=0?e-1:d-1)},[e]),l=h.useCallback(()=>{e<=1||i(d=>d>=e-1?0:d+1)},[e]);return h.useEffect(()=>{if(!n||e<=1)return;const d=u=>{if(u.key!=="ArrowLeft"&&u.key!=="ArrowRight")return;const x=document.activeElement;x&&(x.tagName==="VIDEO"||x.tagName==="AUDIO")||(u.preventDefault(),u.key==="ArrowLeft"?o():l())};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n,e,o,l]),{index:r,prev:o,next:l}},rs=({open:e,onClose:t,ariaLabel:n,counter:a,actions:r,children:i,"data-testid":o})=>{const l=h.useRef(null),d=h.useRef(null);h.useEffect(()=>{var f;const m=l.current;if(m){if(e){if(!m.open)if(typeof m.showModal=="function")try{m.showModal()}catch{m.setAttribute("open","")}else m.setAttribute("open","");const c=typeof document<"u"?document.activeElement:null;return(f=d.current)==null||f.focus(),()=>{if(m.open)if(typeof m.close=="function")try{m.close()}catch{m.removeAttribute("open")}else m.removeAttribute("open");c&&document.body.contains(c)&&c.focus()}}if(m.open)if(typeof m.close=="function")try{m.close()}catch{m.removeAttribute("open")}else m.removeAttribute("open")}},[e]);const u=()=>{t()},x=m=>{m.target===l.current&&t()};return s.jsxs("dialog",{ref:l,className:"mes-media-viewer","aria-label":n??"Attachment viewer","data-testid":o,onClose:u,onClick:x,children:[s.jsxs("div",{className:"mes-media-viewer__chrome",children:[a?s.jsx("span",{className:"mes-media-viewer__counter",children:a}):null,s.jsxs("div",{className:"mes-media-viewer__actions",children:[r,s.jsx("button",{ref:d,type:"button",onClick:t,"aria-label":"Close viewer",className:"mes-media-viewer__action",children:s.jsx(_.XIcon,{size:20,weight:"bold","aria-hidden":!0})})]})]}),s.jsx("div",{className:"mes-media-viewer__body",children:i})]})},it=({open:e,items:t,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:o}=as({length:t.length,initialIndex:n,open:e}),l=t[r],d=h.useMemo(()=>(l==null?void 0:l.filename)??(l?se(l.src):"image"),[l]);return l?s.jsxs(rs,{open:e,onClose:a,ariaLabel:d,counter:t.length>1?`${r+1} / ${t.length}`:void 0,actions:s.jsx(rt,{url:l.src,filename:d,variant:"viewer",label:`Download ${d}`}),"data-testid":"image-viewer",children:[s.jsx("img",{src:l.src,alt:l.alt??d,draggable:!1,loading:"eager",decoding:"async",className:"mes-media-viewer__image"},`${r}:${l.src}`),t.length>1?s.jsx(ns,{onPrev:i,onNext:o,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",lt=({tiles:e,onTileActivate:t,maxVisible:n=4,className:a})=>{const r=e.length;if(r===0)return null;const i=e.slice(0,Math.min(r,n)),o=r-i.length,l=(d,u,x)=>{const m=S(zn,"h-full w-full");return t?s.jsxs("button",{type:"button",onClick:()=>t(u),"aria-label":d.ariaLabel??`Open media ${u+1}`,className:S(m,"cursor-zoom-in"),children:[d.content,x]},u):s.jsxs("div",{className:m,children:[d.content,x]},u)};return i.length===1?s.jsx("div",{className:S("aspect-square w-full",a),children:l(i[0],0)}):i.length===2?s.jsx("div",{className:S("grid aspect-[16/9] w-full grid-cols-2 gap-0.5",a),children:i.map((d,u)=>l(d,u))}):i.length===3?s.jsxs("div",{className:S("grid aspect-[4/3] w-full grid-cols-2 grid-rows-2 gap-0.5",a),children:[s.jsx("div",{className:"row-span-2",children:l(i[0],0)}),l(i[1],1),l(i[2],2)]}):s.jsx("div",{className:S("grid aspect-[4/3] w-full grid-cols-2 grid-rows-2 gap-0.5",a),children:i.map((d,u)=>{const x=o>0&&u===i.length-1;return l(d,u,x?s.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-black/55 text-2xl font-semibold text-white",children:["+",o]}):null)})})},we=e=>{const[t,n]=h.useState(!1),[a,r]=h.useState(0),i=h.useCallback(l=>{(e==null?void 0:e(l))!==!1&&(r(l),n(!0))},[e]),o=h.useCallback(()=>n(!1),[]);return{viewerOpen:t,viewerIndex:a,handleActivate:i,closeViewer:o}},Pn=(e,t,n,a)=>({ariaLabel:`Open image ${t+1} of ${n}`,content:s.jsx("img",{src:ae(e.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"})}),Fn=({src:e,alt:t,items:n})=>n&&n.length>0?n:e?[{src:e,alt:t}]:[],ot=(e,t)=>e.map((n,a)=>({src:n.src,alt:n.alt,filename:t&&e.length===1?t:t?`${t} (${a+1})`:void 0})),On=({src:e,alt:t,filename:n,loading:a="lazy",onClick:r,onDismiss:i})=>{const{viewerOpen:o,viewerIndex:l,handleActivate:d,closeViewer:u}=we(r);return s.jsxs("div",{className:"relative w-fit",children:[s.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:s.jsx("img",{src:ae(e)??e,alt:t??"",draggable:!1,loading:a,decoding:"async",className:"size-full object-cover"})}),i?s.jsx("div",{className:"absolute right-2 top-2 z-10",children:s.jsx(ve,{onClick:i})}):null,s.jsx(it,{open:o,items:ot([{src:e,alt:t}],n),initialIndex:l,onClose:u})]})},ct=({state:e,src:t,alt:n,filename:a,items:r,text:i,groupPosition:o,loading:l="lazy",onClick:d})=>{const u=Fn({src:t,alt:n,items:r}),x=je(e),{viewerOpen:m,viewerIndex:f,handleActivate:c,closeViewer:p}=we(d);if(u.length===0)return null;const b=u.map((v,g)=>Pn(v,g,u.length,l));return s.jsxs(be,{variant:x,text:i,groupPosition:o,"data-testid":"image-attachment",children:[s.jsx("div",{className:"relative",children:s.jsx(lt,{tiles:b,onTileActivate:c})}),s.jsx(it,{open:m,items:ot(u,a),initialIndex:f,onClose:p})]})},$n=e=>s.jsx(On,{...e}),Un=e=>s.jsx(ct,{...e,state:"sent"}),Bn=e=>s.jsx(ct,{...e,state:"received"}),Vn={Composer:$n,Sent:Un,Received:Bn},Gn=({open:e,items:t,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:o}=as({length:t.length,initialIndex:n,open:e}),l=t[r],d=h.useMemo(()=>(l==null?void 0:l.filename)??(l?se(l.src):"document"),[l]),u=h.useMemo(()=>l?Yn(l.src):void 0,[l]);return!l||!u?null:s.jsxs(rs,{open:e,onClose:a,ariaLabel:d,counter:t.length>1?`${r+1} / ${t.length}`:void 0,"data-testid":"pdf-viewer",children:[s.jsx("iframe",{src:u,title:d,className:"mes-media-viewer__iframe",sandbox:"allow-scripts allow-forms allow-popups allow-downloads"},`${r}:${l.src}`),t.length>1?s.jsx(ns,{onPrev:i,onNext:o,prevLabel:"Previous document",nextLabel:"Next document"}):null]})},Yn=e=>{const t=e.indexOf("#"),n=t===-1?e:e.slice(0,t),a=t===-1?"":e.slice(t+1),r=new URLSearchParams(a);return r.has("toolbar")||r.set("toolbar","0"),r.has("navpanes")||r.set("navpanes","0"),`${n}#${r.toString()}`},Hn=({src:e,filename:t,fileSize:n,title:a,items:r})=>r&&r.length>0?r:e?[{src:e,filename:t,fileSize:n,title:a}]:[],qn=({variant:e,item:t,index:n,onActivate:a,trailingAction:r})=>{const i=t.filename??se(t.src);return s.jsx(nt,{variant:e,filename:i,title:t.title,mimeType:"application/pdf",fileSize:t.fileSize,onActivate:()=>a(n),activateLabel:`Open ${i}`,trailingAction:r})},is=({state:e,src:t,filename:n,fileSize:a,title:r,items:i,text:o,groupPosition:l,onClick:d,onDismiss:u})=>{const x=je(e),m=Hn({src:t,filename:n,fileSize:a,title:r,items:i}),{viewerOpen:f,viewerIndex:c,handleActivate:p,closeViewer:b}=we(d),v=e==="composer"&&!!u;if(m.length===0)return null;const g=m.map(N=>({src:N.src,filename:N.filename??se(N.src)}));return s.jsxs(be,{variant:x,text:o,groupPosition:l,"data-testid":"pdf-attachment",children:[s.jsx("div",{className:"flex flex-col gap-2",children:m.map((N,j)=>{const E=N.filename??se(N.src),P=v&&j===0?s.jsx(ve,{onClick:u,variant:"inline"}):e==="composer"?void 0:s.jsx(rt,{url:N.src,filename:E,variant:"inline",label:`Download ${E}`,tone:x});return s.jsx(qn,{variant:x,item:N,index:j,onActivate:p,trailingAction:P},`${N.src}-${j}`)})}),s.jsx(Gn,{open:f,items:g,initialIndex:c,onClose:b})]})},Wn=e=>s.jsx(is,{...e,state:"composer"}),Xn=e=>s.jsx(is,{...e,state:"sent"}),Kn=e=>s.jsx(is,{...e,state:"received"}),Zn={Composer:Wn,Sent:Xn,Received:Kn},dt=({open:e,items:t,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:o}=as({length:t.length,initialIndex:n,open:e}),l=t[r],d=h.useMemo(()=>(l==null?void 0:l.filename)??(l?se(l.src):"video"),[l]);return l?s.jsxs(rs,{open:e,onClose:a,ariaLabel:d,counter:t.length>1?`${r+1} / ${t.length}`:void 0,"data-testid":"video-viewer",children:[s.jsx("video",{src:l.src,poster:l.poster,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,preload:l.preload??"metadata",className:"mes-media-viewer__video",children:l.mimeType?s.jsx("source",{src:l.src,type:l.mimeType}):null},`${r}:${l.src}`),t.length>1?s.jsx(ns,{onPrev:i,onNext:o,prevLabel:"Previous video",nextLabel:"Next video"}):null]}):null},Jn=()=>s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:s.jsx("span",{className:"flex size-12 items-center justify-center rounded-full bg-black/55 text-white backdrop-blur",children:s.jsx(_.PlayIcon,{className:"size-6",weight:"fill","aria-hidden":!0})})}),ut=({item:e,index:t})=>s.jsxs("div",{className:"absolute inset-0 size-full bg-[#0d0d0d]",children:[e.poster?s.jsx("img",{src:e.poster,alt:`Video ${t+1} thumbnail`,draggable:!1,loading:"lazy",decoding:"async",className:"absolute inset-0 size-full rounded-md object-cover"}):s.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:s.jsx(_.VideoCameraIcon,{className:"size-16 rounded-md text-white/30",weight:"regular","aria-hidden":!0})}),s.jsx(Jn,{})]}),Qn=(e,t,n)=>({ariaLabel:`Play video ${t+1} of ${n}`,content:s.jsx(ut,{item:e,index:t})}),ea=({src:e,poster:t,mimeType:n,preload:a,items:r})=>r&&r.length>0?a?r.map(i=>({...i,preload:i.preload??a})):r:e?[{src:e,poster:t,mimeType:n,preload:a}]:[],mt=(e,t)=>e.map((n,a)=>({src:n.src,poster:n.poster,mimeType:n.mimeType,preload:n.preload,filename:t&&e.length===1?t:t?`${t} (${a+1})`:void 0})),sa=({src:e,poster:t,mimeType:n,filename:a,preload:r,onClick:i,onDismiss:o})=>{const{viewerOpen:l,viewerIndex:d,handleActivate:u,closeViewer:x}=we(i);return s.jsxs("div",{className:"relative w-fit",children:[s.jsx("button",{type:"button",onClick:()=>u(0),"aria-label":"Play video",className:"relative block size-[280px] cursor-pointer overflow-hidden rounded-md outline-none focus-visible:ring-2 focus-visible:ring-black/40",children:s.jsx(ut,{item:{src:e,poster:t,mimeType:n},index:0})}),o?s.jsx("div",{className:"absolute right-2 top-2 z-10",children:s.jsx(ve,{onClick:o})}):null,s.jsx(dt,{open:l,items:mt([{src:e,poster:t,mimeType:n,preload:r}],a),initialIndex:d,onClose:x})]})},ht=({state:e,src:t,poster:n,mimeType:a,filename:r,items:i,text:o,groupPosition:l,preload:d,onClick:u})=>{const x=ea({src:t,poster:n,mimeType:a,preload:d,items:i}),m=je(e),{viewerOpen:f,viewerIndex:c,handleActivate:p,closeViewer:b}=we(u);if(x.length===0)return null;const v=x.map((g,N)=>Qn(g,N,x.length));return s.jsxs(be,{variant:m,text:o,groupPosition:l,"data-testid":"video-attachment",children:[s.jsx("div",{className:"relative",children:s.jsx(lt,{tiles:v,onTileActivate:p,className:"overflow-hidden rounded-md"})}),s.jsx(dt,{open:f,items:mt(x,r),initialIndex:c,onClose:b})]})},ta=e=>s.jsx(sa,{...e}),na=e=>s.jsx(ht,{...e,state:"sent"}),aa=e=>s.jsx(ht,{...e,state:"received"}),ra={Composer:ta,Sent:na,Received:aa},xe={Image:Vn,Video:ra,Audio:kn,Pdf:Zn,File:Dn},ia={isUnlocking:()=>!1},la={LockedAttachment:ia},xt=h.createContext({}),oa=xt.Provider;function ft(e){return h.useContext(xt)[e]??la[e]}const ca=h.lazy(()=>Promise.resolve().then(()=>require("./Card-415OfRhw.cjs"))),da=h.lazy(()=>Promise.resolve().then(()=>require("./Card-C0aP28ZH.cjs"))),ua=()=>s.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}),fe=e=>s.jsx(h.Suspense,{fallback:s.jsx(ua,{}),children:e.contentType==="text"?s.jsx(ca,{...e}):s.jsx(da,{...e})}),ma=({size:e=15})=>s.jsx("svg",{width:e,height:e,viewBox:"0 0 15 15",fill:"none","aria-hidden":"true",children:s.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})}),ha=e=>{var t;return((t=e.metadata)==null?void 0:t.custom_type)==="MESSAGE_TIP"},xa=e=>{var t;return((t=e.metadata)==null?void 0:t.custom_type)==="MESSAGE_PAID"},ke=e=>{var t;return((t=e.metadata)==null?void 0:t.custom_type)==="MESSAGE_CHATBOT"},ls=e=>{var t;return((t=e.metadata)==null?void 0:t.custom_type)==="MESSAGE_ATTACHMENT"},fa=e=>{var t;return ls(e)&&((t=e.metadata)==null?void 0:t.attachment_content_type)==="text"},ga=e=>{var t;return ls(e)&&((t=e.metadata)==null?void 0:t.attachment_content_type)!=="text"},gt=e=>ha(e)||xa(e),pa=e=>{var t;return gt(e)&&!((t=e.text)!=null&&t.trim())},Fe=({message:e,standalone:t=!1,isMyMessage:n=!1,hasAttachment:a=!1})=>{var m;const r=gt(e),i=ke(e);if(!r&&!i)return null;if(r){const f=(m=e.metadata)==null?void 0:m.amount_text;if(!f)return null;const c=t?"message-tip-standalone":"message-tag message-tag--tip",p=t?`${f} tip`:`Delivered with ${f} tip`;return s.jsxs("div",{className:c,children:[s.jsx(_.GiftIcon,{size:t?14:12}),s.jsx("span",{children:p})]})}const o=n&&a,l=o?"Sent with AI":"Sent by AI Assistant",d=["message-chatbot-indicator",n?"message-chatbot-indicator--sender":"message-chatbot-indicator--receiver",o?"message-chatbot-indicator--attachment":"message-chatbot-indicator--text"].join(" "),u=s.jsx("span",{className:"message-chatbot-indicator__label",children:l}),x=s.jsx("span",{className:"message-chatbot-indicator__icon",children:s.jsx(ma,{size:o?12:15})});return s.jsx("div",{className:d,"data-testid":"message-chatbot-indicator",children:n&&!o?s.jsxs(s.Fragment,{children:[u,x]}):s.jsxs(s.Fragment,{children:[x,u]})})},pt=({selected:e,onVoteUp:t,onVoteDown:n})=>s.jsxs("div",{className:"message-vote-buttons",children:[s.jsx("button",{type:"button",className:S("message-vote-button focus-ring",{"message-vote-button--selected":e==="up"}),onClick:t,"aria-label":"Good response","aria-pressed":e==="up","data-tooltip":"Good response",children:s.jsx(_.ThumbsUpIcon,{size:16,weight:e==="up"?"fill":"regular"})}),s.jsx("button",{type:"button",className:S("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:s.jsx(_.ThumbsDownIcon,{size:16,weight:e==="down"?"fill":"regular"})})]}),Oe=()=>{const{message:e}=w.useMessageContext("SentMessageDeliveryStatus"),{messages:t}=w.useChannelStateContext("SentMessageDeliveryStatus"),n=(()=>{if(t)for(let a=t.length-1;a>=0;a-=1){const r=t[a];if(!(r.type==="system"||r.type==="ephemeral"||r.type==="deleted"))return r.id}})();return e.id!==n?null:s.jsxs(s.Fragment,{children:[s.jsx(_.ChecksIcon,{weight:"bold","aria-hidden":"true"}),s.jsx("span",{"data-testid":"sent-message-delivery-status",children:"Delivered"})]})},ba=()=>null,va=()=>s.jsx(w.MessageStatus,{MessageSentStatus:Oe,MessageDeliveredStatus:Oe,MessageReadStatus:Oe,MessageSendingStatus:ba}),ja=/^([a-z][a-z0-9+.-]*):/i,wa=new Set(["http","https","mailto","tel","sms"]);function os(e){if(typeof e!="string")return;const t=e.trim();if(t==="")return;const n=ja.exec(t);if(n){const a=n[1].toLowerCase();return wa.has(a)?t:void 0}return t.startsWith("//")||t.startsWith("/")?t:`https://${t}`}const _a={dark:"bg-white text-[#121110] hover:bg-white/90",light:"bg-[#121110] text-white hover:bg-[#2a2928]"},Na=({variant:e,cta:t})=>{const n=S("mt-2 inline-flex h-10 w-full items-center justify-center rounded-full px-4 text-sm font-medium leading-none transition-colors",_a[e]),a=os(t.href);return a?s.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",onClick:r=>{var i;r.stopPropagation(),(i=t.onClick)==null||i.call(t)},className:`${n} no-underline`,children:t.label}):s.jsx("button",{type:"button",onClick:r=>{var i;r.stopPropagation(),(i=t.onClick)==null||i.call(t)},className:n,children:t.label})},ya={dark:"text-white",light:"text-black/90"},ka="text-white/30",Ca={dark:"text-white/55",light:"text-black/55"},cs=({variant:e,title:t,placeholderTitle:n,description:a,url:r,appIcon:i,cta:o,trailingAction:l})=>{const d=e==="dark",u=t??(d?n:void 0)??"",x=u.trim()!=="",m=a!=null&&a.trim()!=="",f=typeof r=="string"?r.trim():"",c=f!=="",p=o!=null;if(!x&&!m&&!c&&!p)return null;const v=S("truncate text-base font-medium leading-6",d&&!t?ka:ya[e]),g=S("truncate text-xs leading-4",Ca[e]);return s.jsxs("div",{className:"px-4 py-3",children:[s.jsxs("div",{className:"flex items-end gap-3",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[x&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i?s.jsx("span",{className:"shrink-0",children:i}):null,s.jsx("p",{className:S("min-w-0",v),children:u})]}),m&&s.jsx("p",{className:g,children:a})]}),!p&&c&&s.jsx("p",{className:g,children:f})]}),l&&s.jsx("div",{className:"shrink-0",children:l})]}),o&&s.jsx(Na,{variant:e,cta:o})]})},Sa=S("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)]"),Ce=({variant:e,children:t,href:n,onClick:a,ariaLabel:r,rootRef:i,topRight:o,bgClassName:l,"data-testid":d})=>{const u=n!=null||a!=null,x=S(Sa,l??(e==="dark"?"bg-[#1e2330]":"bg-white"),u?"cursor-pointer no-underline focus-ring":null),m=o?s.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-10",children:o}):null;return n?s.jsxs("a",{ref:i,href:n,target:"_blank",rel:"noopener noreferrer",onClick:a,"data-testid":d,className:x,children:[t,m]}):a?s.jsxs("button",{ref:i,type:"button",onClick:a,"aria-label":r,"data-testid":d,className:S(x,"text-left"),children:[t,m]}):s.jsxs("div",{ref:i,"data-testid":d,className:x,children:[t,m]})},Ea={dark:"bg-white/10",light:"bg-black/5"},Ia={dark:"size-16 text-white/25",light:"size-16 text-black/25"},Re=(e,t)=>!!t&&!!e&&te(e)==="audio",ds=(e,t)=>{if(!t||!e)return!1;const n=te(e);return n==="video"||n==="audio"},us="bg-[#F2F3F4]",Se=({variant:e,thumbnailUrl:t,sourceUrl:n,title:a,mimeType:r="image/*",topLeft:i,topRight:o})=>{const l=te(r),d=!!n&&l==="video",u=ae(t);return Re(r,n)?s.jsx("div",{className:"p-3",children:s.jsx("audio",{src:n,controls:!0,preload:"metadata",className:"block w-full",children:s.jsx("track",{kind:"captions"})})}):s.jsxs("div",{className:S("relative h-[180px] w-full overflow-hidden",d&&"bg-black"),children:[d?s.jsx("video",{src:n,poster:u,controls:!0,playsInline:!0,preload:"metadata",className:"absolute inset-0 h-full w-full object-contain",children:s.jsx("track",{kind:"captions"})}):t?s.jsx("img",{src:u??t,alt:a??"",draggable:!1,className:"absolute inset-0 h-full w-full object-cover"}):s.jsx("div",{className:S("flex h-full w-full items-center justify-center",Ea[e]),children:oe(r,{className:Ia[e],weight:"regular"})}),i?s.jsx("div",{className:"pointer-events-auto absolute left-3 top-3 z-10",children:i}):null,o?s.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-10",children:o}):null]})},Ta=({title:e,placeholderTitle:t,description:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:o,layout:l="featured",appIcon:d,cta:u,onDismiss:x,onEditClick:m})=>{const f=l==="classic",c=Re(r,o),p=x?s.jsx("button",{type:"button",onClick:x,"aria-label":"Dismiss attachment",className:"flex size-6 items-center justify-center rounded-full bg-[#121110] text-white",children:s.jsx(_.XIcon,{className:"size-3",weight:"bold"})}):void 0,b=m?s.jsx("button",{type:"button",onClick:m,"aria-label":"Edit attachment",className:"flex size-10 items-center justify-center rounded-full bg-white/10 text-white hover:bg-white/15",children:s.jsx(_.PencilSimpleIcon,{className:"size-5",weight:"regular"})}):void 0;return c?s.jsx(Ce,{variant:"dark",bgClassName:us,children:s.jsxs("div",{className:"flex items-center gap-2 pr-3",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Se,{variant:"dark",sourceUrl:o,title:e,mimeType:r})}),p&&s.jsx("div",{className:"shrink-0",children:p})]})}):s.jsxs(Ce,{variant:"dark",topRight:f?p:void 0,children:[!f&&s.jsx(Se,{variant:"dark",thumbnailUrl:i,sourceUrl:o,title:e,mimeType:r,topRight:p}),s.jsx(cs,{variant:"dark",title:e,placeholderTitle:t,description:n,url:a,appIcon:d,cta:u,trailingAction:b})]})},Ma=({title:e,description:t,url:n,mimeType:a,thumbnailUrl:r,sourceUrl:i,layout:o="featured",appIcon:l,cta:d,onClick:u})=>{const x=ds(a,i),m=os(n),f=d==null&&m!=null&&!x?m:void 0,c=d==null&&!x?u:void 0,p=Re(a,i)?us:void 0,b=d&&u?{...d,onClick:()=>{var v;u(),(v=d.onClick)==null||v.call(d)}}:d;return s.jsxs(Ce,{variant:"light",href:f,onClick:c,ariaLabel:e??"Open attachment preview",bgClassName:p,"data-testid":"link-attachment",children:[o==="featured"&&s.jsx(Se,{variant:"light",thumbnailUrl:r,sourceUrl:i,title:e,mimeType:a}),s.jsx(cs,{variant:"light",title:e,description:t,url:n,appIcon:l,cta:b})]})},Aa=({title:e,placeholderTitle:t,description:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:o,layout:l="featured",appIcon:d,cta:u,onClick:x})=>{const m=ds(r,o),f=os(a),c=u==null&&f!=null&&!m?f:void 0,p=u==null&&!m&&c!=null?x:void 0;return s.jsxs(Ce,{variant:"dark",href:c,onClick:p,bgClassName:Re(r,o)?us:void 0,children:[l==="featured"&&s.jsx(Se,{variant:"dark",thumbnailUrl:i,sourceUrl:o,title:e,mimeType:r}),s.jsx(cs,{variant:"dark",title:e,placeholderTitle:t,description:n,url:a,appIcon:d,cta:u})]})},He={Composer:Ta,Sent:Aa,Received:Ma};function F(e){const t=e==null?void 0:e.trim();return t||void 0}function Ls(e){return e.trim().replace(/^https?:\/\//i,"").replace(/\/+$/,"").toLowerCase()}function Ra(e,t){if(!(e!=null&&e.trim())||!(t!=null&&t.trim()))return!1;const n=Ls(e),a=Ls(t);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 Ds(e){const t=F(e.og_scrape_url)??F(e.title_link),n=F(e.image_url)??F(e.thumb_url),a=F(e.asset_url),r=F(e.mime_type);return{title:F(e.title),description:F(e.text),url:t,thumbnailUrl:ae(n),sourceUrl:a,layout:n||ds(r,a)?"featured":"classic",mimeType:r}}function La(e){var t;return bt(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":(t=e.mime_type)!=null&&t.startsWith("audio/")?"audio":"file":null}function bt(e){const t=F(e.og_scrape_url);return e.type==="link"||!!t&&!e.asset_url}function vt(e){if(!(e!=null&&e.length))return[];const t=[],n=(r,i)=>{const o=t[t.length-1];if((o==null?void 0:o.type)==="media"&&o.kind===r){o.attachments.push(i);return}t.push({type:"media",kind:r,attachments:[i]})},a=r=>{const i=t[t.length-1];if((i==null?void 0:i.type)==="link"){i.attachments.push(r);return}t.push({type:"link",attachments:[r]})};for(const r of e){if(bt(r)){a(r);continue}const i=La(r);i&&n(i,r)}return t}function Da(e){return e.filter(t=>t.type==="media").length}function za(e,t,n){return t<=1?n:e===0?"first":e===t-1?"end":"middle"}function zs(e){return F(e.image_url)??F(e.asset_url)??""}function Pa(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,t){if(t.length>1)switch(e){case"image":return{items:t.map(a=>({src:zs(a),alt:F(a.title)}))};case"video":return{items:t.map(a=>({src:F(a.asset_url)??"",poster:F(a.thumb_url),mimeType:F(a.mime_type)}))};case"audio":return{items:t.map(a=>({src:F(a.asset_url)??"",mimeType:F(a.mime_type)??"audio/mpeg",filename:F(a.title)}))};case"pdf":return{items:t.map(a=>({src:F(a.asset_url)??"",filename:F(a.title),fileSize:a.file_size}))};case"file":return{items:t.map(a=>({src:F(a.asset_url)??"",filename:F(a.title),fileSize:a.file_size,mimeType:F(a.mime_type)??"application/octet-stream"}))}}const n=t[0];if(!n)return{};switch(e){case"image":return{src:zs(n),alt:F(n.title)};case"video":return{src:F(n.asset_url)??"",poster:F(n.thumb_url),mimeType:F(n.mime_type)};case"audio":return{src:F(n.asset_url)??"",mimeType:F(n.mime_type)??"audio/mpeg",filename:F(n.title)};case"pdf":return{src:F(n.asset_url)??"",filename:F(n.title),fileSize:n.file_size};case"file":return{src:F(n.asset_url)??"",filename:F(n.title),fileSize:n.file_size,mimeType:F(n.mime_type)??"application/octet-stream"}}}function Oa({groupPosition:e,isMyMessage:t,segment:n}){const a=Pa(n.kind),r={...Fa(n.kind,n.attachments),groupPosition:e};return t?s.jsx(a.Sent,{...r}):s.jsx(a.Received,{...r})}const $a=({groupPosition:e,isMyMessage:t,message:n,renderText:a})=>{var p;const r=vt(n.attachments);if(r.length===0)return null;const i=Da(r),o=(p=n.text)==null?void 0:p.trim(),l=r.find(b=>b.type==="link"),d=(l==null?void 0:l.type)==="link"?Ds(l.attachments[0]??{}).url:void 0,u=o&&Ra(o,d)?void 0:o;let x=0;const m=[],f=(b,v)=>{const g=t?He.Sent:He.Received;m.push(s.jsx(g,{...Ds(b)},v))},c=(b,v)=>{const g=za(x,i,e);x+=1,m.push(s.jsx(Oa,{groupPosition:g,isMyMessage:t,segment:b},v))};return r.forEach((b,v)=>{if(b.type==="link"){b.attachments.forEach((g,N)=>{f(g,`link-${v}-${N}`)});return}c(b,`media-${v}`)}),s.jsxs("div",{className:"str-chat__message-bubble-wrapper",children:[s.jsxs("div",{className:"str-chat__message-bubble","data-attachment-bubble":"true",style:{background:"transparent",borderRadius:0,overflow:"visible",padding:0},children:[m,!u&&s.jsx(w.MessageErrorIcon,{})]}),u?s.jsxs("div",{className:"str-chat__message-bubble",children:[s.jsx(w.MessageText,{message:n,renderText:a}),s.jsx(w.MessageErrorIcon,{})]}):null]})},Ua=e=>{var bs,vs,js,ws,_s,Ns,ys,ks,Cs,Ss;const{additionalMessageInputProps:t,chatbotVotingEnabled:n,editing:a,endOfGroup:r,firstOfGroup:i,groupedByUser:o,handleAction:l,handleOpenThread:d,handleRetry:u,highlighted:x,isMessageAIGenerated:m,isMyMessage:f,message:c,renderText:p,threadList:b,viewerLanguage:v}=e,{client:g}=w.useChatContext("CustomMessage"),{channel:N}=w.useChannelStateContext("CustomMessage"),{isUnlocking:j,onUnlockClick:E,onFetchSource:P,onDownloadClick:I}=ft("LockedAttachment"),[L,$]=h.useState(!1),z=w.useMessageReminder(c.id),{selected:D,voteUp:k,voteDown:T}=Hs(c),{Attachment:C=w.Attachment,EditMessageModal:M=w.EditMessageModal,MessageActions:A,MessageBlocked:O=w.MessageBlocked,MessageBouncePrompt:U=w.MessageBouncePrompt,MessageDeleted:V=w.MessageDeleted,MessageIsThreadReplyInChannelButtonIndicator:X=w.MessageIsThreadReplyInChannelButtonIndicator,MessageRepliesCountButton:Z=w.MessageRepliesCountButton,ReminderNotification:W=w.ReminderNotification,StreamedMessageText:y=w.StreamedMessageText,PinIndicator:R}=w.useComponentContext("CustomMessage"),G=w.messageHasAttachments(c),H=w.messageHasReactions(c),Y=h.useMemo(()=>m==null?void 0:m(c),[m,c]),B=h.useMemo(()=>{const le=c.attachments??[],ue=c.shared_location?[c.shared_location,...le]:le;if(!ke(c))return ue;const Es=ue.filter(Is=>!("type"in Is)||!es(Is));return Es.length===ue.length?ue:Es},[c]),q=h.useMemo(()=>vt(B),[B]),K=h.useMemo(()=>{const le=Ke({message:c,viewerLanguage:v});return le===c.text?c:{...c,text:le}},[c,v]),re=q.length>0,_e=q.reduce((le,ue)=>le+ue.attachments.length,0)===((B==null?void 0:B.length)??0),Ne=Qs({endOfGroup:r,firstOfGroup:i,groupedByUser:o});if(w.isDateSeparatorMessage(c))return null;if(c.deleted_at||c.type==="deleted")return s.jsx(V,{message:c});if(w.isMessageBlocked(c))return s.jsx(O,{});const ee=!b&&!!c.reply_count,ie=!b&&c.show_in_channel&&c.parent_id,ne=c.status==="failed"&&((bs=c.error)==null?void 0:bs.status)!==403,hs=w.isMessageBounced(c);let ce;ne?ce=()=>u(c):hs&&(ce=()=>$(!0));const J=f(),Et=S("str-chat__message str-chat__message-simple",`str-chat__message--${c.type}`,`str-chat__message--${c.status}`,J?"str-chat__message--me str-chat__message-simple--me":"str-chat__message--other",c.text?"str-chat__message--has-text":"has-no-text",{"str-chat__message--has-attachment":G,"str-chat__message--highlighted":x,"str-chat__message--pinned pinned-message":c.pinned,"str-chat__message--with-reactions":H,"str-chat__message-send-can-be-retried":(c==null?void 0:c.status)==="failed"&&((vs=c==null?void 0:c.error)==null?void 0:vs.status)!==403,"str-chat__message-with-thread-link":ee||ie,"str-chat__virtual-message__wrapper--end":r,"str-chat__virtual-message__wrapper--first":i,"str-chat__virtual-message__wrapper--group":o}),Le=c.poll_id&&g.polls.fromState(c.poll_id),xs=pa(c),de=ke(c),It=ls(c),De=!!(B!=null&&B.length&&!c.quoted_message),fs=de&&J&&De,Tt=re&&_e&&!c.quoted_message&&!Le&&!Y&&!de,gs={contentType:"text",amountText:(js=c.metadata)==null?void 0:js.amount_text,paymentStatus:(ws=c.metadata)==null?void 0:ws.payment_status,renderedText:c.text&&s.jsx(w.MessageText,{message:K,renderText:p})},ps={contentType:"media",title:(_s=c.metadata)==null?void 0:_s.attachment_title,mimeType:(Ns=c.metadata)==null?void 0:Ns.attachment_mime_type,thumbnailUrl:(ys=c.metadata)==null?void 0:ys.attachment_thumbnail,amountText:(ks=c.metadata)==null?void 0:ks.amount_text,detail:(Cs=c.metadata)==null?void 0:Cs.attachment_detail,paymentStatus:(Ss=c.metadata)==null?void 0:Ss.payment_status,onFetchSource:P?()=>P(c,N):void 0};return s.jsxs(s.Fragment,{children:[a&&s.jsx(M,{additionalMessageInputProps:t}),L&&s.jsx(w.MessageBounceModal,{MessageBouncePrompt:U,onClose:()=>$(!1),open:L}),s.jsxs("div",{className:Et,"data-message-id":c.id,"data-dd-privacy":"mask",children:[R&&s.jsx(R,{}),!!z&&s.jsx(W,{reminder:z}),c.user&&s.jsx(Q,{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:de}),s.jsx("div",{className:S("str-chat__message-inner",{"str-chat__simple-message--error-failed":ne||hs}),"data-testid":"message-inner",onClick:ce,onKeyDown:ce,role:ce?"button":void 0,tabIndex:ce?0:void 0,style:{marginInlineEnd:0,marginInlineStart:0},children:xs?s.jsx(Fe,{message:c,standalone:!0}):fa(c)?s.jsx("div",{className:"str-chat__message-bubble-wrapper",children:s.jsxs("div",{className:"flex items-center gap-2",children:[J&&A&&s.jsx(A,{}),J?s.jsx(fe,{...gs,isMine:!0}):s.jsx(fe,{...gs,isMine:!1,isUnlocking:j(c.id),onUnlockClick:()=>E==null?void 0:E(c,N)}),!J&&A&&s.jsx(A,{})]})}):ga(c)?s.jsxs("div",{className:"str-chat__message-bubble-wrapper",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[J&&A&&s.jsx(A,{}),J?s.jsx(fe,{...ps,isMine:!0,onPreviewClick:()=>E?E(c,N):void 0}):s.jsx(fe,{...ps,isMine:!1,isUnlocking:j(c.id),onUnlockClick:()=>E?E(c,N):void 0,onDownloadClick:()=>I?I(c,N):void 0}),!J&&A&&s.jsx(A,{})]}),c.text&&s.jsx("div",{className:"str-chat__message-bubble",children:s.jsx(w.MessageText,{message:K,renderText:p})})]}):Tt?s.jsx($a,{groupPosition:Ne,isMyMessage:J,message:{...K,attachments:B,i18n:void 0},renderText:p}):s.jsx("div",{className:"str-chat__message-bubble-wrapper",children:s.jsxs("div",{className:"str-chat__message-bubble",children:[de&&!fs&&s.jsx(Fe,{message:c,hasAttachment:De,isMyMessage:J}),Le&&s.jsx(w.Poll,{poll:Le}),B!=null&&B.length&&!c.quoted_message?s.jsx(C,{actionHandler:l,attachments:B}):null,Y?s.jsx(y,{message:K,renderText:p}):s.jsx(w.MessageText,{message:K,renderText:p}),s.jsx(w.MessageErrorIcon,{})]})})}),!It&&!xs&&s.jsxs("div",{className:"str-chat__message-footer",children:[(!de||fs)&&s.jsx(Fe,{message:c,hasAttachment:De,isMyMessage:J}),n&&de&&s.jsx(pt,{selected:D,onVoteUp:k,onVoteDown:T})]}),s.jsx(va,{}),ee&&s.jsx(Z,{onClick:d,reply_count:c.reply_count}),ie&&s.jsx(X,{})]},c.id)]})},Ba=h.memo(Ua,(e,t)=>e.chatbotVotingEnabled!==t.chatbotVotingEnabled||e.viewerLanguage!==t.viewerLanguage?!1:w.areMessageUIPropsEqual(e,t)),Va=e=>{const t=w.useMessageContext("CustomMessage");return s.jsx(Ba,{...t,...e})},Ga=()=>{var n;const{handleDelete:e,message:t}=w.useMessageContext("CustomMessageActions");return((n=t.metadata)==null?void 0:n.payment_status)==="paid"?null:s.jsx(qe.DefaultDropdownActionButton,{onClick:e,"aria-label":"Delete",title:"Delete",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:s.jsx(_.TrashSimpleIcon,{size:16,weight:"light","aria-hidden":!0})})},Ya=()=>{const{handleFlag:e}=w.useMessageContext("CustomMessageActions");return s.jsx(qe.DefaultDropdownActionButton,{onClick:e,"aria-label":"Report",title:"Report",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:s.jsx(_.FlagIcon,{size:16,weight:"light","aria-hidden":!0})})},Ha=()=>{var t;const{message:e}=w.useMessageContext("CustomMessageActions");return((t=e.metadata)==null?void 0:t.custom_type)!=="MESSAGE_ATTACHMENT"?null:s.jsx(qe.MessageActions,{messageActionSet:[{Component:Ga,placement:"quick",type:"delete"},{Component:Ya,placement:"quick",type:"flag"}]})},qa=({link:e,onDismiss:t})=>{const{og_scrape_url:n,title:a,image_url:r}=e,i=o=>{o.preventDefault(),t(n)};return s.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"relative block w-full rounded-[24px] bg-[#1e2330] p-2 no-underline transition-opacity hover:opacity-90",children:[r&&s.jsx("img",{src:r,alt:a||"",className:"h-[180px] w-full rounded-[20px] object-cover"}),s.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:s.jsx(_.XIcon,{className:"size-4 text-black/90"})}),s.jsxs("div",{className:"p-2",children:[a&&s.jsx("div",{className:"truncate text-[14px] font-medium leading-5 text-white",children:a}),s.jsx("div",{className:"truncate text-[12px] leading-4 text-white/55",children:n})]})]})},Wa=e=>({linkPreviews:Array.from(e.previews.values()).filter(t=>Be.LinkPreviewsManager.previewIsLoaded(t)||Be.LinkPreviewsManager.previewIsLoading(t))}),Xa=()=>{const{linkPreviewsManager:e}=w.useMessageComposer(),{linkPreviews:t}=w.useStateStore(e.state,Wa),n=r=>{e.dismissPreview(r)};return t.length>0?s.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:t.map(r=>s.jsx("div",{className:"w-full shrink-0",children:s.jsx(qa,{link:r,onDismiss:n})},r.og_scrape_url))}):null},Ee=h.createContext(!1),Ka=()=>h.useContext(Ee),Za=({sendMessage:e,disabled:t,...n})=>s.jsx("button",{...n,type:"button","aria-label":"Send",disabled:t,onClick:e,children:s.jsx(_.ArrowUpIcon,{weight:"bold",className:"size-4"})}),Ps=()=>{const e=h.useContext(Ee),{handleSubmit:t}=w.useMessageInputContext(),n=w.useMessageComposerHasSendableData(),a=e||!n,{SendButton:r=Za,AttachmentPreviewList:i=w.AttachmentPreviewList}=w.useComponentContext("CustomMessageInput");return s.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:[s.jsx(w.QuotedMessagePreview,{}),s.jsx(Xa,{}),s.jsx(i,{}),s.jsxs("div",{className:"flex shrink-0",children:[s.jsx("div",{className:"w-full ml-2 mr-4 self-center leading-[0]",children:s.jsx(w.TextareaComposer,{"aria-disabled":e||void 0,className:"w-full resize-none outline-none leading-5 placeholder:text-black/30 text-sm",autoFocus:!e,enterKeyHint:"send",maxRows:4,readOnly:e,tabIndex:e?-1:void 0})}),s.jsx(r,{sendMessage:t,"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"})]})]})},Fs=({renderActions:e,renderHeader:t,renderFooter:n,disabled:a=!1,disabledReason:r,composerInput:i})=>{var x;const{channel:o}=w.useChannelStateContext(),l=((x=o==null?void 0:o.data)==null?void 0:x.frozen)===!0,d=!!i,u=h.useRef(null);return h.useEffect(()=>{if(!d)return;const m=u.current,f=m==null?void 0:m.parentElement;if(!m||!f)return;const c=()=>{f.style.setProperty("--messaging-composer-height",`${m.offsetHeight+16}px`)};if(c(),typeof ResizeObserver>"u")return;const p=new ResizeObserver(c);return p.observe(m),()=>{p.disconnect(),f.style.removeProperty("--messaging-composer-height")}},[d]),a?d?s.jsxs("div",{ref:u,className:"messaging-composer-chrome messaging-composer-chrome--floating",children:[s.jsxs("div",{className:"messaging-composer-backdrop","aria-hidden":"true",children:[s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-gradient"})]}),s.jsxs("div",{className:"relative z-10 flex flex-col",children:[t==null?void 0:t(),s.jsx("div",{className:"messaging-composer-locked-panel flex w-full flex-col items-center justify-center gap-3 px-6 py-4",children:r?s.jsx("p",{className:"max-w-[345px] text-center text-xs font-normal leading-[1.3] tracking-[0.12px] text-black/40",children:r}):null}),n==null?void 0:n()]})]}):s.jsxs(s.Fragment,{children:[t==null?void 0:t(),s.jsx("div",{className:"messaging-composer-locked-panel flex w-full flex-col items-center justify-center gap-3 px-6 py-4",children:r?s.jsx("p",{className:"max-w-[345px] text-center text-xs font-normal leading-[1.3] tracking-[0.12px] text-black/40",children:r}):null}),n==null?void 0:n()]}):d?s.jsxs("div",{ref:u,className:"messaging-composer-chrome messaging-composer-chrome--floating",children:[s.jsxs("div",{className:"messaging-composer-backdrop","aria-hidden":"true",children:[s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-blur"}),s.jsx("div",{className:"messaging-composer-backdrop-gradient"})]}),s.jsxs("div",{className:"relative z-10 flex min-h-0 flex-col",children:[t==null?void 0:t(),s.jsxs("div",{className:"flex min-h-0 flex-col gap-4 p-4",children:[s.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&&s.jsx("div",{className:"flex h-12 shrink-0 items-center justify-center",children:e()}),s.jsx(Ee.Provider,{value:l,children:s.jsx(w.MessageInput,{Input:i??Ps})})]}),n==null?void 0:n()]})]})]}):s.jsxs("div",{className:"flex min-h-0 flex-col gap-4 p-4",children:[t==null?void 0:t(),s.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&&s.jsx("div",{className:"flex h-12 shrink-0 items-center justify-center",children:e()}),s.jsx(Ee.Provider,{value:l,children:s.jsx(w.MessageInput,{Input:Ps})})]}),n==null?void 0:n()]})},Ja=["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"],sr=["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."},$e="age safety guidelines.",nr="https://linktr.ee/s/about/contact",Os=e=>Ja.includes(e),ar=e=>er.includes(e),rr=e=>sr.includes(e),ir=e=>{var t;return rr((t=e.metadata)==null?void 0:t.custom_type)},lr=e=>{var a;const t=(a=e.metadata)==null?void 0:a.custom_type;if(Os(t))return{kind:"dm-agent",type:t};if(ar(t))return{kind:"age-safety",type:t};const n=e.dm_agent_system_type;if(Os(n))return{kind:"dm-agent",type:n}},or=e=>{const t=e.indexOf($e);if(t===-1)return e;const n=t+$e.length;return s.jsxs(s.Fragment,{children:[e.slice(0,t),s.jsx("a",{href:nr,target:"_blank",rel:"noopener noreferrer",className:"mes-age-safety-system-message__emphasis font-medium text-inherit underline",children:$e}),e.slice(n)]})},cr=e=>{var a,r;const t=!ir(e.message),n=lr(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 s.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[s.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:[s.jsx(_.SparkleIcon,{size:16,weight:"regular","aria-hidden":!0,className:"mes-dm-agent-system-message__sparkle shrink-0"}),s.jsx("p",{className:"mes-dm-agent-system-message__text m-0 text-center text-[14px] font-normal leading-5 tracking-[0.21px]",children:i})]}),!t&&s.jsx(w.MessageTimestamp,{message:e.message})]})}if((n==null?void 0:n.kind)==="age-safety"){const i=((r=e.message.text)==null?void 0:r.trim())||tr[n.type];return s.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[s.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:[s.jsx(_.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"}),s.jsx("div",{className:"mes-age-safety-system-message__content min-w-0 flex-[1_0_0]",children:s.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:or(i)})})]}),!t&&s.jsx(w.MessageTimestamp,{message:e.message})]})}return s.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[s.jsxs("div",{className:"str-chat__message--system__text",children:[s.jsx("div",{className:"str-chat__message--system__line"}),s.jsx("p",{children:e.message.text}),s.jsx("div",{className:"str-chat__message--system__line"})]}),!t&&s.jsx(w.MessageTimestamp,{message:e.message})]})},jt=h.createContext(!1),Ue=({cx:e,index:t})=>s.jsx("circle",{cx:e,cy:"6.15",r:"3.9",fill:"#A0A0A0",children:s.jsx("animateTransform",{attributeName:"transform",type:"translate",values:"0 0; 0 -2.25; 0 0;",dur:"900ms",begin:`${120*t}ms`,repeatCount:"indefinite"})}),dr=new Set([w.AIStates.Thinking,w.AIStates.Generating,w.AIStates.ExternalSources]),ur=({threadList:e})=>{var p,b;const{channel:t,channelConfig:n,thread:a}=w.useChannelStateContext(),{client:r}=w.useChatContext(),{typing:i={}}=w.useTypingContext(),{aiState:o}=w.useAIState(t),l=h.useContext(jt);if(!e&&l&&dr.has(o)){const v=mr(t,(p=r.user)==null?void 0:p.id);return s.jsx($s,{avatarId:(v==null?void 0:v.id)??"ai-agent",avatarName:(v==null?void 0:v.name)??(v==null?void 0:v.id)??"Agent",avatarImage:v==null?void 0:v.image,testId:"typing-indicator-ai"})}if((n==null?void 0:n.typing_events)===!1)return null;const u=e?[]:Object.values(i).filter(({parent_id:v,user:g})=>{var N;return(g==null?void 0:g.id)!==((N=r.user)==null?void 0:N.id)&&!v}),x=e?Object.values(i).filter(({parent_id:v,user:g})=>{var N;return(g==null?void 0:g.id)!==((N=r.user)==null?void 0:N.id)&&v===(a==null?void 0:a.id)}):[],m=e?x:u;if(!m.length)return null;const f=(b=m[0])==null?void 0:b.user,c=f!=null&&f.id&&t.state.members[f.id]?t.state.members[f.id].user:void 0;return s.jsx($s,{avatarId:(f==null?void 0:f.id)??(c==null?void 0:c.id)??"typing-user",avatarName:(f==null?void 0:f.name)??(c==null?void 0:c.name)??(f==null?void 0:f.id)??"Typing user",avatarImage:(f==null?void 0:f.image)??(c==null?void 0:c.image),testId:"typing-indicator"})},$s=({avatarId:e,avatarName:t,avatarImage:n,testId:a})=>s.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:s.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:[s.jsx(Q,{className:"str-chat__avatar str-chat__message-sender-avatar",id:e,name:t,image:n??void 0,size:24,shape:"circle"}),s.jsx("div",{className:"str-chat__message-inner mx-0",children:s.jsx("div",{className:"str-chat__message-bubble-wrapper",children:s.jsx("div",{className:"str-chat__message-bubble",children:s.jsx("div",{className:"str-chat__message-text min-h-11 flex items-center",children:s.jsx("div",{className:"str-chat__message-text-inner str-chat__message-simple-text-inner",children:s.jsxs("svg",{"aria-hidden":"true",className:"block overflow-visible",viewBox:"0 0 32 12.3",width:"32",height:"13",overflow:"visible",children:[s.jsx(Ue,{cx:"4",index:0}),s.jsx(Ue,{cx:"16",index:1}),s.jsx(Ue,{cx:"28",index:2})]})})})})})})]})});function mr(e,t){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!==t)return i}}const wt=()=>null,hr=({className:e,message:t})=>s.jsxs("div",{className:S("flex items-center justify-center h-full",e),children:[s.jsxs("svg",{viewBox:"0 0 100 100",className:"size-8 fill-pebble",stroke:"none",children:[s.jsx("circle",{cx:"6",cy:"50",r:"6",children:s.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 15 ; 0 -15; 0 15",repeatCount:"indefinite",begin:"0.1"})}),s.jsx("circle",{cx:"30",cy:"50",r:"6",children:s.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 10 ; 0 -10; 0 10",repeatCount:"indefinite",begin:"0.2"})}),s.jsx("circle",{cx:"54",cy:"50",r:"6",children:s.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 5 ; 0 -5; 0 5",repeatCount:"indefinite",begin:"0.3"})})]}),t&&s.jsx("span",{className:"text-stone",children:t})]}),Ie=h.memo(()=>s.jsx("div",{className:"messaging-loading-state flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex items-center",children:[s.jsx(hr,{className:"w-6 h-6"}),s.jsx("span",{className:"text-sm text-stone",children:"Loading messages"})]})}));Ie.displayName="LoadingState";const me="size-10 rounded-full hover:bg-[#E5E4E1] flex items-center justify-center transition-colors duration-150 focus-ring",ye="Replies instantly with AI assistant",xr=({onBack:e,showBackButton:t,showStarButton:n=!1,dmAgentEnabled:a=!1,onLeaveConversation:r,onBlockParticipant:i,showDeleteConversation:o=!0,showBlockParticipant:l=!0,showReportParticipant:d=!0,onDeleteConversationClick:u,onBlockParticipantClick:x,onReportParticipantClick:m,customChannelActions:f,renderChannelActions:c,showChannelInfo:p=!0,onParticipantNameClick:b,renderHeaderTitleBadges:v})=>{var T,C,M,A,O,U;const{channel:g}=w.useChannelStateContext(),{client:N}=w.useChatContext(),j=h.useMemo(()=>{var V;return pe((V=g.state)==null?void 0:V.members,N==null?void 0:N.userID,g.type)},[(T=g.state)==null?void 0:T.members,N==null?void 0:N.userID,g.type]),E=Te(j==null?void 0:j.user),P=(C=j==null?void 0:j.user)==null?void 0:C.image,I=Xe(g),L=v==null?void 0:v({channel:g,participant:j}),$="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",z="flex min-w-0 max-w-full items-center gap-4 rounded-[12px] px-1 py-0.5 text-left text-black/90",D=s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate",children:E}),L&&s.jsx("span",{className:"shrink-0",children:L})]}),k=async()=>{try{I?await g.unpin():await g.pin()}catch(V){console.error("[CustomChannelHeader] Failed to update pinned status:",V)}};return s.jsxs("div",{className:"@container",children:[s.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] w-full items-center @lg:hidden px-6 py-3",children:[s.jsx("div",{className:"flex items-center gap-2",children:t&&s.jsx("button",{className:S(me,"messaging-channel-view-back-button-mobile bg-[#F1F0EE]"),onClick:e||(()=>{}),type:"button","aria-label":"Back to conversations",children:s.jsx(_.ArrowLeftIcon,{className:"size-5 text-black/90"})})}),s.jsx("div",{className:"flex flex-col gap-1 items-center","data-dd-privacy":"mask",children:b?s.jsxs("button",{type:"button",onClick:b,"aria-label":`View details for ${E}`,className:S($,"appearance-none border-0 bg-transparent transition-opacity hover:opacity-70 focus-ring focus-visible:outline-none"),children:[s.jsx(Q,{id:((M=j==null?void 0:j.user)==null?void 0:M.id)||g.id||"unknown",name:E,image:P,starred:n&&I,dmAgentEnabled:a,size:48}),s.jsxs("span",{className:"flex max-w-full items-center gap-0.5",children:[D,s.jsx(_.CaretRightIcon,{className:"size-3 shrink-0",weight:"bold"})]}),a&&s.jsxs("div",{className:"flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[s.jsx(_.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),s.jsx("span",{children:ye})]})]}):s.jsxs("div",{className:$,children:[s.jsx(Q,{id:((A=j==null?void 0:j.user)==null?void 0:A.id)||g.id||"unknown",name:E,image:P,starred:n&&I,dmAgentEnabled:a,size:48}),s.jsxs("p",{className:"flex max-w-full items-center justify-center gap-0.5",children:[D,s.jsx(_.CaretRightIcon,{className:"invisible size-3 shrink-0",weight:"bold"})]}),a&&s.jsxs("div",{className:"flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[s.jsx(_.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),s.jsx("span",{children:ye})]})]})}),s.jsxs("div",{className:"flex justify-end items-center gap-2",children:[n&&s.jsx("button",{className:me,onClick:k,type:"button","aria-label":I?"Unstar conversation":"Star conversation",children:s.jsx(_.StarIcon,{className:S("size-5",{"text-yellow-600":I,"text-black/90":!I}),weight:I?"duotone":"regular"})}),p&&(c!==void 0?c:s.jsx(Ve,{channel:g,participant:j,showDeleteConversation:o,showBlockParticipant:l,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:u,onBlockParticipantClick:x,onReportParticipantClick:m,customChannelActions:f,triggerClassName:S(me,"bg-[#F1F0EE]")}))]})]}),s.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:[s.jsxs("div",{className:"flex items-center gap-4 min-w-0","data-dd-privacy":"mask",children:[t&&e&&s.jsx("button",{className:S(me,"messaging-channel-view-back-button-desktop"),type:"button",onClick:e,"aria-label":"Back to conversations",children:s.jsx(_.ArrowLeftIcon,{className:"size-5 text-black/90"})}),b?s.jsxs("button",{type:"button",onClick:b,"aria-label":`View details for ${E}`,className:S(z,"appearance-none border-0 bg-transparent transition-opacity hover:opacity-70 focus-ring focus-visible:outline-none"),children:[s.jsx(Q,{id:((O=j==null?void 0:j.user)==null?void 0:O.id)||g.id||"unknown",name:E,image:P,starred:n&&I,dmAgentEnabled:a,size:48}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("h1",{className:"flex min-w-0 items-center gap-1 font-medium text-black/90",children:[D,s.jsx(_.CaretRightIcon,{className:"size-4 shrink-0",weight:"bold"})]}),a&&s.jsxs("div",{className:"mt-0.5 flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[s.jsx(_.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),s.jsx("span",{className:"truncate",children:ye})]})]})]}):s.jsxs("div",{className:z,children:[s.jsx(Q,{id:((U=j==null?void 0:j.user)==null?void 0:U.id)||g.id||"unknown",name:E,image:P,starred:n&&I,dmAgentEnabled:a,size:48}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("h1",{className:"flex min-w-0 items-center gap-1 font-medium text-black/90",children:[D,s.jsx(_.CaretRightIcon,{className:"invisible size-4 shrink-0",weight:"bold"})]}),a&&s.jsxs("div",{className:"mt-0.5 flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[s.jsx(_.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),s.jsx("span",{className:"truncate",children:ye})]})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[n&&s.jsx("button",{className:me,onClick:k,type:"button","aria-label":I?"Unstar conversation":"Star conversation",children:s.jsx(_.StarIcon,{className:S("size-6",{"text-yellow-600":I,"text-black/90":!I}),weight:I?"duotone":"regular"})}),p&&(c!==void 0?c:s.jsx(Ve,{channel:g,participant:j,showDeleteConversation:o,showBlockParticipant:l,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:u,onBlockParticipantClick:x,onReportParticipantClick:m,customChannelActions:f,triggerClassName:me}))]})]})]})},fr=({onBack:e,showBackButton:t,renderMessageInputActions:n,renderMessageInputFooter:a,renderConversationFooter:r,onLeaveConversation:i,onBlockParticipant:o,showDeleteConversation:l=!0,onDeleteConversationClick:d,onBlockParticipantClick:u,onReportParticipantClick:x,showBlockParticipant:m=!0,showReportParticipant:f=!0,composerDisabled:c=!1,composerDisabledReason:p,showStarButton:b=!1,chatbotVotingEnabled:v=!1,renderChannelBanner:g,renderHeaderTitleBadges:N,customChannelActions:j,renderChannelActions:E,renderMessage:P,dmAgentEnabled:I=!1,viewerLanguage:L,showChannelInfo:$=!0,onParticipantNameClick:z,composerInput:D})=>{var y,R,G,H;const{channel:k}=w.useChannelStateContext(),{client:T}=w.useChatContext(),C=h.useMemo(()=>{var Y;return pe((Y=k.state)==null?void 0:Y.members,T==null?void 0:T.userID,k.type)},[(y=k.state)==null?void 0:y.members,T==null?void 0:T.userID,k.type]),M=h.useMemo(()=>{var q;const Y=T==null?void 0:T.userID;return Y?Object.values(((q=k.state)==null?void 0:q.members)||{}).find(K=>{var re;return((re=K.user)==null?void 0:re.id)===Y}):void 0},[T==null?void 0:T.userID,(R=k.state)==null?void 0:R.members]),A=((G=M==null?void 0:M.user)==null?void 0:G.is_account)??(M==null?void 0:M.is_account),O=((H=C==null?void 0:C.user)==null?void 0:H.is_account)??(C==null?void 0:C.is_account),U=I&&A===!1&&O===!0,V=k.state.messages.some(Y=>Y.type!=="deleted"),X=g?s.jsx(h.Fragment,{children:g()},"lt-channel-banner"):null,Z=z?s.jsx(Gt,{className:"-mx-[var(--str-chat\\_\\_spacing-2)] px-[var(--str-chat\\_\\_spacing-2)] md:-mx-[min(var(--str-chat\\_\\_spacing-10),4%)] md:px-[min(var(--str-chat\\_\\_spacing-10),4%)]",onBack:e,showBackButton:t,showChannelInfo:$,showStarButton:b,dmAgentEnabled:U,onLeaveConversation:i,onBlockParticipant:o,showDeleteConversation:l,showBlockParticipant:m,showReportParticipant:f,onDeleteConversationClick:d,onBlockParticipantClick:u,onReportParticipantClick:x,customChannelActions:j,renderChannelActions:E,onParticipantNameClick:z}):null,W=h.useCallback(Y=>{const{message:B}=w.useMessageContext("ChannelView"),q=s.jsx(Va,{...Y,chatbotVotingEnabled:v,viewerLanguage:L});return!P||!B?q:P(q,B)},[v,P,L]);return s.jsx(s.Fragment,{children:s.jsx(w.WithComponents,{overrides:{Message:W,MessageActions:Ha,UnreadMessagesNotification:()=>null,UnreadMessagesSeparator:()=>null},children:s.jsxs(w.Window,{children:[!z&&s.jsxs(s.Fragment,{children:[s.jsx("div",{children:s.jsx(xr,{onBack:e,showBackButton:t,showChannelInfo:$,showStarButton:b,dmAgentEnabled:U,onLeaveConversation:i,onBlockParticipant:o,showDeleteConversation:l,showBlockParticipant:m,showReportParticipant:f,onDeleteConversationClick:d,onBlockParticipantClick:u,onReportParticipantClick:x,customChannelActions:j,renderChannelActions:E,renderHeaderTitleBadges:N})},"lt-channel-header"),X]}),D?s.jsxs("div",{className:"messaging-channel-layout relative flex min-h-0 flex-1 flex-col",children:[s.jsxs("div",{className:"messaging-channel-message-list messaging-channel-message-list--floating relative min-h-0 flex-1 overflow-hidden",children:[z&&!V&&s.jsx("div",{className:"str-chat__list",children:s.jsxs("div",{className:"str-chat__message-list-scroll",children:[Z,X]})}),s.jsx(w.MessageList,{head:z&&V?s.jsxs("div",{className:"sticky top-0 z-10",children:[Z,X]}):void 0,hideDeletedMessages:!0,hideNewMessageSeparator:!1})]},"lt-channel-message-list"),s.jsx(Fs,{...n&&{renderActions:()=>n==null?void 0:n(k)},...r&&{renderHeader:()=>r(k)},renderFooter:()=>a==null?void 0:a(k),disabled:c,disabledReason:p,composerInput:D},"lt-channel-message-input")]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[z&&!V&&s.jsx("div",{className:"str-chat__list",children:s.jsxs("div",{className:"str-chat__message-list-scroll",children:[Z,X]})}),s.jsx(w.MessageList,{head:z&&V?s.jsxs("div",{className:"sticky top-0 z-10",children:[Z,X]}):void 0,hideDeletedMessages:!0,hideNewMessageSeparator:!1})]},"lt-channel-message-list"),r?s.jsx(h.Fragment,{children:r(k)},"lt-channel-conversation-footer"):null,s.jsx(Fs,{...n&&{renderActions:()=>n==null?void 0:n(k)},renderFooter:()=>a==null?void 0:a(k),disabled:c,disabledReason:p,composerInput:D},"lt-channel-message-input")]})]})})})},ms=h.memo(({channel:e,onBack:t,showBackButton:n=!1,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:o,onBlockParticipant:l,className:d,CustomChannelEmptyState:u=wt,showDeleteConversation:x=!0,onDeleteConversationClick:m,onBlockParticipantClick:f,onReportParticipantClick:c,showBlockParticipant:p=!0,showReportParticipant:b=!0,composerDisabled:v=!1,composerDisabledReason:g,dmAgentEnabled:N,messageMetadata:j,onMessageSent:E,showStarButton:P=!1,chatbotVotingEnabled:I=!1,renderChannelBanner:L,renderHeaderTitleBadges:$,customChannelActions:z,renderChannelActions:D,renderMessage:k,onMessageLinkClick:T,sendButton:C,attachmentPreviewList:M,viewerLanguage:A,showChannelInfo:O=!0,onParticipantNameClick:U,composerInput:V})=>{const X=h.useCallback(async(W,y,R)=>{var K;const G=((K=e.data)==null?void 0:K.chatbot_paused)===!0,H=N&&!G,Y={...y,...H&&{silent:!0},...j&&{metadata:{...y.metadata??{},...j}}},B={...R,...H&&{skip_push:!0}},q=await e.sendMessage(Y,B);return E==null||E(q),q},[e,N,j,E]),Z=h.useRef(null);return h.useEffect(()=>{if(!T)return;const W=Z.current;if(!W)return;const y=R=>{const G=R.target,H=G==null?void 0:G.closest("a[href]"),Y=H==null?void 0:H.getAttribute("href");if(!Y)return;const B=H==null?void 0:H.closest("[data-message-id]"),q=B==null?void 0:B.getAttribute("data-message-id"),K=q?e.state.messages.find(re=>re.id===q):void 0;T(Y,K)};return W.addEventListener("click",y),()=>W.removeEventListener("click",y)},[T,e]),s.jsx("div",{ref:Z,className:S("messaging-channel-view h-full flex flex-col",d),children:s.jsx(jt.Provider,{value:N??!1,children:s.jsx(w.Channel,{channel:e,MessageSystem:cr,EmptyStateIndicator:u,LoadingIndicator:Ie,DateSeparator:Yt,TypingIndicator:ur,doSendMessageRequest:X,...C?{SendButton:C}:{},...M?{AttachmentPreviewList:M}:{},children:s.jsx(fr,{onBack:t,showBackButton:n,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:o,onBlockParticipant:l,CustomChannelEmptyState:u,showDeleteConversation:x,onDeleteConversationClick:m,onBlockParticipantClick:f,onReportParticipantClick:c,showBlockParticipant:p,showReportParticipant:b,composerDisabled:v,composerDisabledReason:g,showStarButton:P,dmAgentEnabled:N,chatbotVotingEnabled:I,renderChannelBanner:L,renderHeaderTitleBadges:$,customChannelActions:z,renderChannelActions:D,renderMessage:k,viewerLanguage:A,showChannelInfo:O,onParticipantNameClick:U,composerInput:V})})})})});ms.displayName="ChannelView";const ge=h.memo(({message:e,onBack:t})=>s.jsx("div",{className:"messaging-error-state flex items-center justify-center h-full p-8",children:s.jsxs("div",{className:"text-center max-w-sm",children:[s.jsx("div",{className:"w-24 h-24 bg-danger-alt/20 rounded-full flex items-center justify-center mx-auto mb-6",children:s.jsx("span",{className:"text-4xl",children:"⚠️"})}),s.jsx("h2",{className:"font-semibold text-charcoal mb-2",children:"Oops!"}),s.jsx("p",{className:"text-stone text-sm mb-6",children:e}),t&&s.jsx("button",{type:"button",onClick:t,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"})]})}));ge.displayName="ErrorState";const gr=({capabilities:e={},renderMessageInputActions:t,renderConversationFooter:n,onChannelSelect:a,onExitConversation:r,initialParticipantFilter:i,initialParticipantData:o,CustomChannelEmptyState:l,onBlockParticipantClick:d,onReportParticipantClick:u,dmAgentEnabled:x,onMessageSent:m,chatbotVotingEnabled:f=!1,viewerLanguage:c,renderHeaderTitleBadges:p,renderChannelBanner:b,customChannelActions:v,renderChannelActions:g,onParticipantNameClick:N,renderMessage:j,onMessageLinkClick:E,showChannelInfo:P,composerInput:I})=>{const{client:L,isConnected:$,isLoading:z,error:D,refreshConnection:k,service:T,debug:C}=Vs(),[M,A]=h.useState(null),[O,U]=h.useState(null),[V,X]=h.useState(!1),{showDeleteConversation:Z=!0}=e,W=h.useRef(o);W.current=o;const y=h.useRef(a);y.current=a;const R=h.useRef(null),G=h.useRef(null);h.useEffect(()=>{G.current=M},[M]),h.useEffect(()=>{if(!L||!$)return;const B=L.userID;if(!B)return;const q=`${B}::${i}`;if(R.current===q)return;R.current=q;const K=()=>{R.current===q&&(R.current=null)};(async()=>{var _e,Ne;try{C&&console.log("[MessagingShell] Loading initial conversation with:",i);const ee=await L.queryChannels({type:"messaging",members:{$eq:[B,i]}},{},{limit:1});if(ee.length>0){A(ee[0]),U(null),(_e=y.current)==null||_e.call(y,ee[0]),C&&console.log("[MessagingShell] Initial conversation loaded:",ee[0].id);return}const ie=W.current;if(!ie||!T){K(),U("No conversation found with this account"),C&&console.log("[MessagingShell] No conversation found for:",i);return}try{const ne=await T.startChannelWithParticipant({id:ie.id,name:ie.name,phone:ie.phone});A(ne),U(null),(Ne=y.current)==null||Ne.call(y,ne),C&&console.log("[MessagingShell] Channel created and loaded:",ne.id)}catch(ne){console.error("[MessagingShell] Failed to create conversation:",ne),K(),U("Failed to create conversation")}}catch(ee){console.error("[MessagingShell] Failed to load initial conversation:",ee),K(),G.current||U("Failed to load conversation")}})()},[i,L,$,T,C]);const H=h.useRef(r);H.current=r;const Y=h.useCallback(()=>{var B;A(null),X(!0),(B=H.current)==null||B.call(H)},[]);return z?s.jsx(Ie,{}):D?s.jsx(ge,{message:D,onBack:k}):!$||!L?s.jsx(ge,{message:"Not connected to messaging service",onBack:k}):O?s.jsx(ge,{message:O}):V&&!M?s.jsx(ge,{message:"Conversation ended"}):M?s.jsx("div",{className:"messaging-shell h-full bg-background-primary overflow-hidden",children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(ms,{channel:M,renderMessageInputActions:t,renderConversationFooter:n,renderChannelBanner:b,onLeaveConversation:Y,onBlockParticipant:Y,CustomChannelEmptyState:l,showDeleteConversation:Z,onBlockParticipantClick:d,onReportParticipantClick:u,dmAgentEnabled:x,onMessageSent:m,chatbotVotingEnabled:f,viewerLanguage:c,renderHeaderTitleBadges:p,customChannelActions:v,renderChannelActions:g,onParticipantNameClick:N,renderMessage:j,onMessageLinkClick:E,showChannelInfo:P,composerInput:I},M.id)})}):s.jsx(Ie,{})};function pr(e){const t=e.state.pending_messages;if(t!=null&&t.length)for(const n of t)e.state.addMessageSorted(n.message)}const _t=h.createContext({selectedChannel:void 0,onChannelSelect:()=>{},debug:!1,renderMessagePreview:void 0,channelPreview:void 0,viewerLanguage:void 0}),br=_t.Provider,vr=()=>h.useContext(_t),jr=(e,t)=>{const n=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())),r=new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())).getTime()-n.getTime();return Math.floor(r/(1e3*60*60*24))},Nt=e=>{const t=new Date;if(Math.floor((t.getTime()-e.getTime())/1e3)<60)return"Just now";const a=jr(e,t);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"})},yt=h.memo(e=>{var $,z,D;const{channel:t,unread:n}=e,{selectedChannel:a,onChannelSelect:r,debug:i,channelPreview:o,renderMessagePreview:l,viewerLanguage:d}=vr(),{client:u}=w.useChatContext(),x=(a==null?void 0:a.id)===(t==null?void 0:t.id),m=Xe(t);if(o){const k=o;return s.jsx(k,{...e,active:x,selectedChannel:a,onChannelSelect:r,viewerLanguage:d})}const f=()=>{t&&r(t)},c=k=>{const T=k.key==="Enter"||k.key===" ",C=k.repeat;!T||C||(k.preventDefault(),f())},p=pe(($=t==null?void 0:t.state)==null?void 0:$.members,u==null?void 0:u.userID,t==null?void 0:t.type),b=Te(p==null?void 0:p.user),v=(z=p==null?void 0:p.user)==null?void 0:z.image,g=(()=>{var T;const k=(T=t==null?void 0:t.state)==null?void 0:T.messages;if(k!=null&&k.length){for(let C=k.length-1;C>=0;C--)if(k[C].type!=="system")return k[C]}})(),j=(()=>{var A;const k=Ke({message:g,viewerLanguage:d}),{custom_type:T,attachment_content_type:C}=(g==null?void 0:g.metadata)||{};if(T==="MESSAGE_TIP")return k||"Sent a tip";if(T==="MESSAGE_PAID")return k||"Sent a message";if(T==="MESSAGE_ATTACHMENT"){if(C==="text")return"🔒 Sent a locked message";if(C==="media")return"🔒 Sent a locked attachment"}if(k)return k;const M=(A=g==null?void 0:g.attachments)==null?void 0:A[0];return M?M.og_scrape_url?M.og_scrape_url:M.type==="image"?"📷 Sent an image":M.type==="video"?"🎥 Sent a video":M.type==="audio"?"🎵 Sent audio":M.type==="file"?"📎 Sent a file":"📎 Sent an attachment":"No messages yet"})(),E=g!=null&&g.created_at?Nt(new Date(g.created_at)):"",P=g?ke(g):!1,I=l?l(g,j):`${P?"✨ ":""}${j}`,L=n??0;return i&&console.log("📺 [ChannelList] 📋 CHANNEL PREVIEW RENDER",{channelId:t==null?void 0:t.id,isSelected:x,participantName:b,unreadCount:L,hasTimestamp:!!E}),s.jsx("div",{role:"button",tabIndex:0,onClick:f,onKeyDown:c,className:S("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]":x,"hover:bg-black/[0.02]":!x}),"data-dd-privacy":"mask",children:s.jsxs("div",{className:"flex items-start gap-4",children:[s.jsx(Q,{id:((D=p==null?void 0:p.user)==null?void 0:D.id)||t.id||"unknown",name:b,image:v,size:48,starred:m}),s.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("h3",{className:S("text-sm font-medium truncate text-[#191918]"),children:[m&&s.jsx("span",{className:"sr-only",children:"Starred conversation. "}),b]}),E&&s.jsx("span",{className:"text-xs text-[#717070] flex-shrink-0",children:E})]}),s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[s.jsx("p",{className:"text-sm text-[#717070] flex-1 line-clamp-1",children:I}),L>0&&s.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:L>99?"99+":L})]})]})]})})});yt.displayName="CustomChannelPreview";const wr={last_message_at:-1},kt=h.memo(({onChannelSelect:e,selectedChannel:t,filters:n,allowNewMessagesFromUnfilteredChannels:a=!1,channelRenderFilterFn:r,sort:i=wr,className:o,customEmptyStateIndicator:l,channelListPaginator:d=w.InfiniteScroll,channelPreview:u,renderMessagePreview:x,viewerLanguage:m,lockChannelOrder:f,onMessageNewHandler:c,onMessageNew:p,onChannelVisible:b,onAddedToChannel:v,onChannelUpdated:g})=>{const N=h.useRef(0);N.current++;const{debug:j=!1}=We(),E=h.useCallback(I=>{for(const L of I)pr(L);return r?r(I):I},[r]);j&&console.log("📺 [ChannelList] 🔄 RENDER START",{renderCount:N.current,selectedChannelId:t==null?void 0:t.id,filters:n});const P=h.useMemo(()=>({selectedChannel:t,onChannelSelect:e,debug:j,channelPreview:u,renderMessagePreview:x,viewerLanguage:m}),[t,e,j,u,x,m]);return s.jsx("div",{className:S("messaging-channel-list h-full flex flex-col min-w-0 overflow-hidden",o),children:s.jsx("div",{className:"flex-1 overflow-hidden min-w-0",children:s.jsx(br,{value:P,children:s.jsx(w.ChannelList,{filters:n,sort:i,options:{limit:30},allowNewMessagesFromUnfilteredChannels:a,channelRenderFilterFn:E,lockChannelOrder:f,onMessageNewHandler:c,onMessageNew:p,onChannelVisible:b,onAddedToChannel:v,onChannelUpdated:g,Paginator:d,Preview:yt,EmptyStateIndicator:l},`${JSON.stringify(n)}:${JSON.stringify(i)}`)})})})});kt.displayName="ChannelList";const Us=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='23' fill='none'%3E%3Cpath fill='black' d='M0 0H15C15 10.1934 15.859 15.2345 19.168 21.4893C19.527 22.168 19.039 22.9917 18.274 22.9178C5.176 21.6506 0.32 6.0737 0 0Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%`,_r={sent:"var(--str-chat__own-message-bubble-background-color, #1e2330)",received:"var(--str-chat__message-bubble-background-color, #f1f0ee)"},Nr=({variant:e})=>s.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute bottom-0 z-[-1] h-[1.4375rem] w-5",style:{insetInlineEnd:e==="sent"?"calc(-1 * 0.25rem)":void 0,insetInlineStart:e==="received"?"calc(-1 * 0.25rem)":void 0,transform:e==="received"?"scaleX(-1)":void 0,transformOrigin:"center",backgroundColor:_r[e],WebkitMask:Us,mask:Us}}),yr={sent:{backgroundColor:"var(--str-chat__own-message-bubble-background-color, #1e2330)",color:"var(--str-chat__own-message-bubble-color, #fff)"},received:{backgroundColor:"var(--str-chat__message-bubble-background-color, #f1f0ee)",color:"var(--str-chat__message-bubble-color, #000000)"}},Ct=({variant:e,text:t,tail:n=!0,header:a,className:r})=>s.jsxs("div",{"data-dd-privacy":"mask",className:S("relative px-4 py-3","text-[0.875rem] leading-[1.3125rem] tracking-[0.14px]",r),style:{...yr[e],borderRadius:"var(--str-chat__message-bubble-border-radius, 1.5rem)",isolation:"isolate"},children:[a!=null&&s.jsx("div",{className:"mb-1 font-medium","data-testid":"message-bubble-header",children:a}),s.jsx("p",{className:"m-0 whitespace-pre-wrap break-words",children:t}),n&&s.jsx(Nr,{variant:e})]}),kr=({text:e,tail:t,header:n,className:a})=>s.jsx(Ct,{variant:"received",text:e,tail:t,header:n,className:a}),Cr=({text:e,tail:t,className:n})=>s.jsx(Ct,{variant:"sent",text:e,tail:t,className:n}),Sr={Sent:Cr,Received:kr},St=({question:e,onClick:t,loading:n=!1,className:a})=>s.jsx("button",{type:"button",onClick:t,disabled:n,style:{backgroundColor:"#E6E5E3"},className:S("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}),Er=({faqs:e,onFaqClick:t,loadingFaqId:n,headerText:a,className:r,avatarImage:i,avatarName:o})=>{const l=e.filter(d=>d.enabled).sort((d,u)=>(d.order??0)-(u.order??0));return l.length===0?null:s.jsx("div",{className:r,children:s.jsxs("div",{className:"flex gap-3 items-end",children:[(i||o)&&s.jsx("div",{className:"flex-none",children:s.jsx(Q,{id:o||"account",name:o||"Account",image:i,size:24,shape:"circle"})}),s.jsxs("div",{className:"flex-1 flex flex-col gap-3 rounded-lg p-4",style:{backgroundColor:"#F1F0EE"},children:[a&&s.jsx("p",{className:"text-md text-charcoal mb-4",children:a}),l.map(d=>s.jsx(St,{question:d.question,onClick:()=>t(d.id),loading:n===d.id},d.id))]})]})})};exports.ActionButton=he;exports.AttachmentThumbnail=Ze;exports.Avatar=Q;exports.ChannelEmptyState=wt;exports.ChannelList=kt;exports.ChannelView=ms;exports.CustomMessageProvider=oa;exports.FaqList=Er;exports.FaqListItem=St;exports.LinkAttachment=He;exports.LockedAttachment=fe;exports.MediaMessage=xn;exports.MessageAttachment=xe;exports.MessageBubble=Sr;exports.MessageVoteButtons=pt;exports.MessagingProvider=At;exports.MessagingShell=gr;exports.bubbleGroupPositionFromStream=Qs;exports.buildCompactMetaLabel=tt;exports.formatFileSize=et;exports.formatRelativeTime=Nt;exports.getFileExtensionLabel=st;exports.getMessageDisplayText=Ke;exports.getSourceType=te;exports.isLinkAttachment=es;exports.isUuidLike=Gs;exports.normalizeLanguageCode=qs;exports.optimizeMessagingAttachmentUrl=ae;exports.renderTypeIcon=oe;exports.resolveConversationParticipant=pe;exports.resolveLinkAttachment=Me;exports.resolveMediaFromMessage=Ae;exports.resolveParticipantDisplayName=Te;exports.useComposerLocked=Ka;exports.useCustomMessage=ft;exports.useMessageVote=Hs;exports.useMessaging=Vs;
|
|
2
|
-
//# sourceMappingURL=index-34_jzKSz.cjs.map
|