@linktr.ee/messaging-react 3.4.2-rc-1782454787 → 3.4.2-rc-1782480798

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/{Card-BQZcPeQn.js → Card-BKi2g6x-.js} +2 -2
  2. package/dist/{Card-BQZcPeQn.js.map → Card-BKi2g6x-.js.map} +1 -1
  3. package/dist/{Card-CSqZXHCM.cjs → Card-BMmrCMqJ.cjs} +2 -2
  4. package/dist/{Card-CSqZXHCM.cjs.map → Card-BMmrCMqJ.cjs.map} +1 -1
  5. package/dist/{Card-U9LAeCEA.js → Card-BYu6OBuX.js} +2 -2
  6. package/dist/{Card-U9LAeCEA.js.map → Card-BYu6OBuX.js.map} +1 -1
  7. package/dist/{Card-Cp0Ioui8.cjs → Card-DtIjtWy6.cjs} +2 -2
  8. package/dist/{Card-Cp0Ioui8.cjs.map → Card-DtIjtWy6.cjs.map} +1 -1
  9. package/dist/{Card-DFaRAFV1.js → Card-DvE5BCPf.js} +3 -3
  10. package/dist/{Card-DFaRAFV1.js.map → Card-DvE5BCPf.js.map} +1 -1
  11. package/dist/{Card-DWmbH7oz.cjs → Card-VO-i6CuV.cjs} +2 -2
  12. package/dist/{Card-DWmbH7oz.cjs.map → Card-VO-i6CuV.cjs.map} +1 -1
  13. package/dist/{LockedThumbnail-nLWi4Kxt.cjs → LockedThumbnail-Cl8uwCxM.cjs} +2 -2
  14. package/dist/{LockedThumbnail-nLWi4Kxt.cjs.map → LockedThumbnail-Cl8uwCxM.cjs.map} +1 -1
  15. package/dist/{LockedThumbnail-JOZFwdjw.js → LockedThumbnail-DTkd_kEt.js} +2 -2
  16. package/dist/{LockedThumbnail-JOZFwdjw.js.map → LockedThumbnail-DTkd_kEt.js.map} +1 -1
  17. package/dist/index-CSSe9eu7.cjs +2 -0
  18. package/dist/index-CSSe9eu7.cjs.map +1 -0
  19. package/dist/{index-DyG_ZuPp.js → index-IzhF38yj.js} +3440 -3205
  20. package/dist/index-IzhF38yj.js.map +1 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.ts +25 -13
  23. package/dist/index.js +14 -13
  24. package/package.json +2 -2
  25. package/src/components/ChannelList/CustomChannelPreview.stories.tsx +0 -63
  26. package/src/components/ChannelList/CustomChannelPreview.test.tsx +8 -58
  27. package/src/components/ChannelList/CustomChannelPreview.tsx +12 -7
  28. package/src/components/ChannelView.stories.tsx +7 -38
  29. package/src/components/ChannelView.test.tsx +27 -44
  30. package/src/components/ChannelView.tsx +9 -19
  31. package/src/components/CustomMessage/StreamAttachmentMessage.test.tsx +109 -0
  32. package/src/components/CustomMessage/StreamAttachmentMessage.tsx +408 -0
  33. package/src/components/CustomMessage/index.tsx +42 -0
  34. package/src/components/CustomMessageInput/CustomMessageInput.test.tsx +34 -0
  35. package/src/components/CustomMessageInput/index.tsx +23 -1
  36. package/src/components/MessagingShell/index.tsx +2 -0
  37. package/src/hooks/useChannelStar.ts +6 -9
  38. package/src/index.ts +1 -0
  39. package/src/stream-custom-data.ts +1 -16
  40. package/src/types.ts +18 -0
  41. package/dist/index-BSQPos2Q.cjs +0 -2
  42. package/dist/index-BSQPos2Q.cjs.map +0 -1
  43. package/dist/index-DyG_ZuPp.js.map +0 -1
  44. package/src/components/ParticipantBadges.tsx +0 -42
@@ -204,6 +204,40 @@ describe('CustomMessageInput', () => {
204
204
  ).toBeInTheDocument()
205
205
  })
206
206
 
207
+ it('renders a custom composerInput in place of the default composer', () => {
208
+ mockChannelData = {}
209
+
210
+ renderWithProviders(
211
+ <CustomMessageInput
212
+ composerInput={() => (
213
+ <div data-testid="custom-composer">custom composer</div>
214
+ )}
215
+ />
216
+ )
217
+
218
+ // The host-owned composer renders instead of the built-in textarea/send.
219
+ expect(screen.getByTestId('custom-composer')).toBeInTheDocument()
220
+ expect(screen.queryByTestId('textarea-composer')).not.toBeInTheDocument()
221
+ // It is still mounted inside Stream's <MessageInput> so it keeps the
222
+ // message-input context (send pipeline, attachments, previews).
223
+ expect(screen.getByTestId('stream-message-input')).toBeInTheDocument()
224
+ })
225
+
226
+ it('keeps the frozen wrapper around a custom composerInput', () => {
227
+ mockChannelData = { frozen: true }
228
+
229
+ const { container } = renderWithProviders(
230
+ <CustomMessageInput
231
+ composerInput={() => <div data-testid="custom-composer" />}
232
+ />
233
+ )
234
+
235
+ const messageInput = container.querySelector('.message-input')
236
+ expect(messageInput).toHaveAttribute('aria-disabled', 'true')
237
+ expect(messageInput).toHaveAttribute('inert')
238
+ expect(screen.getByTestId('custom-composer')).toBeInTheDocument()
239
+ })
240
+
207
241
  it('does not render the locked panel when the composer is not disabled', () => {
208
242
  mockChannelData = {}
209
243
 
@@ -23,6 +23,15 @@ import { CustomLinkPreviewList } from '../CustomLinkPreviewList'
23
23
  */
24
24
  const ComposerLockedContext = React.createContext(false)
25
25
 
26
+ /**
27
+ * Read the composer's locked (frozen-channel) state from inside a custom
28
+ * composer supplied via `composerInput`. Returns true when the channel is
29
+ * frozen; mirror the default composer by rendering the textarea read-only and
30
+ * disabling the send control.
31
+ */
32
+ export const useComposerLocked = (): boolean =>
33
+ useContext(ComposerLockedContext)
34
+
26
35
  const DefaultSendButton: React.FC<{
27
36
  sendMessage: () => void
28
37
  disabled?: boolean
@@ -101,6 +110,18 @@ export interface CustomMessageInputProps {
101
110
  * `disabled` is true.
102
111
  */
103
112
  disabledReason?: string
113
+ /**
114
+ * Replace the inner composer — the textarea + send arrangement rendered
115
+ * inside Stream's `<MessageInput>` — with a host-owned component. When
116
+ * provided it is passed to Stream as the `Input` component, so it runs inside
117
+ * the message-input context and can drive sending, attachments, and previews
118
+ * via the Stream hooks (`useMessageInputContext`,
119
+ * `useMessageComposerHasSendableData`, `TextareaComposer`, …). The outer
120
+ * frozen/`renderActions`/`renderFooter` wrapper is unchanged; read
121
+ * `useComposerLocked()` to honour the frozen state. Defaults to the built-in
122
+ * composer.
123
+ */
124
+ composerInput?: React.ComponentType
104
125
  }
105
126
 
106
127
  export const CustomMessageInput: React.FC<CustomMessageInputProps> = ({
@@ -108,6 +129,7 @@ export const CustomMessageInput: React.FC<CustomMessageInputProps> = ({
108
129
  renderFooter,
109
130
  disabled = false,
110
131
  disabledReason,
132
+ composerInput,
111
133
  }) => {
112
134
  const { channel } = useChannelStateContext()
113
135
  const isFrozen = channel?.data?.frozen === true
@@ -143,7 +165,7 @@ export const CustomMessageInput: React.FC<CustomMessageInputProps> = ({
143
165
  </div>
144
166
  )}
145
167
  <ComposerLockedContext.Provider value={isFrozen}>
146
- <MessageInput Input={CustomMessageInputInner} />
168
+ <MessageInput Input={composerInput ?? CustomMessageInputInner} />
147
169
  </ComposerLockedContext.Provider>
148
170
  </div>
149
171
  {renderFooter?.()}
@@ -39,6 +39,7 @@ export const MessagingShell: React.FC<MessagingShellProps> = ({
39
39
  renderMessage,
40
40
  onMessageLinkClick,
41
41
  showChannelInfo,
42
+ composerInput,
42
43
  }) => {
43
44
  const {
44
45
  client,
@@ -264,6 +265,7 @@ export const MessagingShell: React.FC<MessagingShellProps> = ({
264
265
  renderMessage={renderMessage}
265
266
  onMessageLinkClick={onMessageLinkClick}
266
267
  showChannelInfo={showChannelInfo}
268
+ composerInput={composerInput}
267
269
  />
268
270
  </div>
269
271
  </div>
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from 'react'
2
- import type { Channel, Event } from 'stream-chat'
2
+ import { Channel, Event } from 'stream-chat'
3
3
 
4
4
  export const useChannelStar = (channel?: Channel) => {
5
5
  const [isChannelStarred, setIsChannelStarred] = useState(
@@ -15,18 +15,15 @@ export const useChannelStar = (channel?: Channel) => {
15
15
  setIsChannelStarred(!!channel.state.membership?.pinned_at)
16
16
 
17
17
  const handleMemberUpdate = (event: Event) => {
18
- const currentUserId = channel._client?.userID
19
- const memberUserId = event.member?.user_id ?? event.member?.user?.id
20
-
21
- if (!currentUserId || memberUserId !== currentUserId) return
22
-
23
- setIsChannelStarred(!!event.member?.pinned_at)
18
+ setIsChannelStarred(
19
+ event?.member ? !!event.member.pinned_at : !!channel.state.membership?.pinned_at
20
+ )
24
21
  }
25
22
 
26
- const subscription = channel.on('member.updated', handleMemberUpdate)
23
+ channel.on('member.updated', handleMemberUpdate)
27
24
 
28
25
  return () => {
29
- subscription.unsubscribe()
26
+ channel.off('member.updated', handleMemberUpdate)
30
27
  }
31
28
  }, [channel])
32
29
 
package/src/index.ts CHANGED
@@ -30,6 +30,7 @@ export { MessagingProvider } from './providers/MessagingProvider'
30
30
  export { CustomMessageProvider } from './components/CustomMessage/context'
31
31
 
32
32
  // Hooks
33
+ export { useComposerLocked } from './components/CustomMessageInput'
33
34
  export { useMessaging } from './hooks/useMessaging'
34
35
  export { useMessageVote } from './hooks/useMessageVote'
35
36
  export { useCustomMessage } from './components/CustomMessage/context'
@@ -2,8 +2,7 @@
2
2
  * Stream Chat custom data type augmentation.
3
3
  *
4
4
  * This file extends Stream Chat's type system by augmenting their empty
5
- * CustomMessageData, CustomChannelData, CustomMemberData, and CustomUserData
6
- * interfaces with our custom properties.
5
+ * CustomMessageData and CustomChannelData interfaces with our custom properties.
7
6
  *
8
7
  * @see https://getstream.io/chat/docs/sdk/react/guides/typescript_and_custom_data_types/
9
8
  *
@@ -99,14 +98,6 @@ declare module 'stream-chat' {
99
98
  chatbot_paused?: boolean
100
99
  }
101
100
 
102
- interface CustomMemberData {
103
- /**
104
- * Whether the member should be identified as a customer in participant UI.
105
- * Stored on the channel member so it is scoped to this conversation.
106
- */
107
- customer?: boolean
108
- }
109
-
110
101
  interface CustomMessageData {
111
102
  /**
112
103
  * When true, hides the date timestamp in system messages.
@@ -124,10 +115,4 @@ declare module 'stream-chat' {
124
115
  */
125
116
  dm_agent_system_type?: DmAgentSystemType
126
117
  }
127
-
128
- interface CustomUserData {
129
- is_account?: boolean
130
- is_follower?: boolean
131
- username?: string
132
- }
133
118
  }
package/src/types.ts CHANGED
@@ -324,6 +324,23 @@ export interface ChannelViewProps {
324
324
  */
325
325
  attachmentPreviewList?: ComponentType
326
326
 
327
+ /**
328
+ * Replace the entire inner composer — the textarea + send arrangement — with
329
+ * a host-owned component. Passed to Stream's `<MessageInput>` as the `Input`
330
+ * component, so it runs inside the message-input context and reuses the
331
+ * library's send pipeline (`doSendMessageRequest`, message metadata, DM-agent
332
+ * suppression), attachments, and previews via the Stream hooks
333
+ * (`useMessageInputContext`, `useMessageComposerHasSendableData`,
334
+ * `TextareaComposer`, …). Use it when a surface needs a different composer
335
+ * layout (e.g. a full-width textarea above a toolbar row) than the default.
336
+ *
337
+ * The outer wrapper — frozen handling and the `renderMessageInputActions` /
338
+ * `renderMessageInputFooter` slots — is unchanged. Read the exported
339
+ * `useComposerLocked()` hook to honour the frozen state. Defaults to the
340
+ * built-in composer when omitted.
341
+ */
342
+ composerInput?: ComponentType
343
+
327
344
  /**
328
345
  * Fired when the participant's name in the channel header is clicked. When
329
346
  * provided, the name renders as a button with a trailing caret (an affordance
@@ -359,6 +376,7 @@ export type ChannelViewPassthroughProps = Pick<
359
376
  | 'renderMessage'
360
377
  | 'onMessageLinkClick'
361
378
  | 'showChannelInfo'
379
+ | 'composerInput'
362
380
  >
363
381
 
364
382
  /**
@@ -1,2 +0,0 @@
1
- "use strict";const t=require("react/jsx-runtime"),m=require("react"),ms=require("@linktr.ee/messaging-core"),Ee=require("stream-chat"),_=require("stream-chat-react"),w=require("@phosphor-icons/react"),C=require("classnames"),Re=require("stream-chat-react/experimental"),Ct=m.createContext({service:null,client:null,isConnected:!1,isLoading:!1,error:null,capabilities:{},refreshConnection:async()=>{},debug:!1}),Le=()=>m.useContext(Ct),hs=({children:e,user:s,serviceConfig:n,apiKey:a,capabilities:r={},debug:i=!1})=>{var M,A;const o=m.useCallback((E,...R)=>{i&&console.log(`🔥 [MessagingProvider] ${E}`,...R)},[i]);o("🔄 RENDER START",{userId:s==null?void 0:s.id,apiKey:(a==null?void 0:a.substring(0,8))+"...",serviceConfig:!!n,capabilities:Object.keys(r)});const[l,d]=m.useState(null),[h,f]=m.useState(null),[u,x]=m.useState(!1),[c,g]=m.useState(!1),[N,v]=m.useState(null),b=m.useRef(!1),p=m.useRef(null),L=m.useRef(n);L.current=n;const T=m.useRef(i);T.current=i;const I=m.useRef({userId:s==null?void 0:s.id,apiKey:a,serviceConfig:n,capabilities:r}),D=m.useRef(0);D.current++,o("📊 RENDER INFO",{renderCount:D.current,currentProps:{userId:s==null?void 0:s.id,apiKey:(a==null?void 0:a.substring(0,8))+"..."},propChanges:{userChanged:I.current.userId!==(s==null?void 0:s.id),apiKeyChanged:I.current.apiKey!==a,serviceConfigChanged:I.current.serviceConfig!==n,capabilitiesChanged:I.current.capabilities!==r}}),I.current={userId:s==null?void 0:s.id,apiKey:a,serviceConfig:n,capabilities:r};const z=m.useRef(null);a&&((M=z.current)==null?void 0:M.apiKey)!==a&&(z.current={apiKey:a,client:new Ee.StreamChat(a)});const y=a?((A=z.current)==null?void 0:A.client)??null:null;m.useEffect(()=>{const E=D.current,R=L.current;if(!a||!y||!R){o("⚠️ SERVICE INIT SKIPPED",{renderCount:E,reason:"Missing apiKey, client, or serviceConfig"});return}o("🚀 CREATING SERVICE",{renderCount:E,apiKey:(a==null?void 0:a.substring(0,8))+"..."});const P=new ms.StreamChatService({...R,apiKey:a,debug:T.current,client:y});p.current=P,d(P),o("✅ SERVICE SET",{renderCount:E,serviceInstance:!!P})},[a,y]);const O=m.useRef(null);m.useEffect(()=>{var R,P;if(o("🔗 USER CONNECTION EFFECT TRIGGERED",{hasService:!!l,hasUser:!!s,userId:s==null?void 0:s.id,isConnecting:b.current,isConnected:u,dependencies:{service:!!l,userId:s==null?void 0:s.id}}),!l||!s){o("⚠️ USER CONNECTION SKIPPED","Missing service or user");return}if(b.current){o("⚠️ USER CONNECTION SKIPPED","Already connecting");return}if(((R=O.current)==null?void 0:R.serviceId)===l&&((P=O.current)==null?void 0:P.userId)===s.id){o("⚠️ USER CONNECTION SKIPPED","Already connected this user with this service");return}(async()=>{o("🚀 STARTING USER CONNECTION",{userId:s.id}),b.current=!0,g(!0),v(null);try{o("📞 CALLING SERVICE.CONNECTUSER",{userId:s.id});const B=await l.connectUser(s);f(B),x(!0),O.current={serviceId:l,userId:s.id},o("✅ USER CONNECTION SUCCESS",{userId:s.id,clientId:B.userID})}catch(B){const H=B instanceof Error?B.message:"Connection failed";v(H),o("❌ USER CONNECTION ERROR",{userId:s.id,error:H})}finally{g(!1),b.current=!1,o("🔄 USER CONNECTION FINISHED",{userId:s.id,isConnected:u})}})()},[l,s,o,u]),m.useEffect(()=>{const E=y;return()=>{var R;E&&(O.current=null,(R=p.current)==null||R.disconnectUser().catch(console.error))}},[y]);const k=m.useCallback(async()=>{if(o("🔄 REFRESH CONNECTION CALLED",{hasService:!!l,hasUser:!!s}),!l||!s){o("⚠️ REFRESH CONNECTION SKIPPED","Missing service or user");return}o("🚀 STARTING CONNECTION REFRESH",{userId:s.id}),g(!0);try{o("🔌 DISCONNECTING FOR REFRESH"),await l.disconnectUser(),o("📞 RECONNECTING FOR REFRESH");const E=await l.connectUser(s);f(E),x(!0),v(null),o("✅ CONNECTION REFRESH SUCCESS",{userId:s.id})}catch(E){const R=E instanceof Error?E.message:"Refresh failed";v(R),o("❌ CONNECTION REFRESH ERROR",{userId:s.id,error:R})}finally{g(!1),o("🔄 CONNECTION REFRESH FINISHED",{userId:s.id})}},[l,s,o]),F=m.useMemo(()=>(o("💫 CONTEXT VALUE MEMOIZATION",{hasService:!!l,hasClient:!!h,isConnected:u,isLoading:c,hasError:!!N,capabilitiesKeys:Object.keys(r)}),{service:l,client:h,isConnected:u,isLoading:c,error:N,capabilities:r,refreshConnection:k,debug:i}),[l,h,u,c,N,r,k,i,o]);return o("🔄 RENDER END",{renderCount:D.current,willRenderChat:!!y,contextValueReady:!!F}),t.jsx(Ct.Provider,{value:F,children:y?t.jsx(_.Chat,{client:y,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})},kt=()=>Le(),St=e=>{var a,r;const[s,n]=m.useState(!!((r=(a=e==null?void 0:e.state)==null?void 0:a.membership)!=null&&r.pinned_at));return m.useEffect(()=>{var l;if(!e){n(!1);return}n(!!((l=e.state.membership)!=null&&l.pinned_at));const i=d=>{var u,x,c,g,N;const h=(u=e._client)==null?void 0:u.userID,f=((x=d.member)==null?void 0:x.user_id)??((g=(c=d.member)==null?void 0:c.user)==null?void 0:g.id);!h||f!==h||n(!!((N=d.member)!=null&&N.pinned_at))},o=e.on("member.updated",i);return()=>{o.unsubscribe()}},[e]),s},xs=/^[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 It(e){return xs.test(e.trim())}function pt(e,s){const n=e==null?void 0:e.trim();return!n||s&&n===s?!1:!It(n)}function De(e){return pt(e==null?void 0:e.name,e==null?void 0:e.id)?e.name.trim():pt(e==null?void 0:e.username,e==null?void 0:e.id)?e.username.trim():"Unknown member"}const vt=["🍎","🍌","🍇","🍊","🍓","🥥","🍒","🥭","🍉","🍋","🥝","🫒","🍈"];function fs(e){let s=0;for(let n=0;n<e.length;n++){const a=e.charCodeAt(n);s=(s<<5)-s+a,s=s&s}return Math.abs(s)}function gs(e){const n=fs(e)%vt.length;return vt[n]}const te=({id:e,image:s,size:n=40,className:a,starred:r=!1,shape:i="squircle",dmAgentEnabled:o=!1})=>{const l=gs(e),h=n<32?"text-xs":n<56?"text-sm":n<120?"text-lg":"text-4xl",f=n>=40?2:1,u=i==="circle"?{borderRadius:"50%"}:{borderRadius:"1rem"},x=t.jsx("div",{className:"h-full w-full overflow-hidden",style:u,children:s?t.jsx("img",{src:s,alt:"",className:"h-full w-full object-cover"}):t.jsx("div",{"aria-hidden":"true",className:C("avatar-fallback flex h-full w-full items-center justify-center bg-[#E6E5E3] font-semibold select-none transition-colors",h),children:l})});return t.jsxs("div",{className:C("relative flex-shrink-0 !bg-transparent",a),style:{"--str-chat__avatar-size":`${n}px`,width:`${n}px`,height:`${n}px`},children:[r&&t.jsx("div",{"aria-hidden":"true",className:"absolute -left-1.5 -top-1.5 z-10 flex size-5 items-center justify-center rounded-full bg-white shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]",children:t.jsx(w.StarIcon,{className:"size-3 text-yellow-600",weight:"duotone"})}),t.jsx("div",{"data-testid":"avatar-ring",className:C("h-full w-full","bg-transparent"),style:{...u,...o&&{borderWidth:`${f}px`,borderStyle:"solid",borderColor:"var(--AI-Gradient, #7F22FE)",boxShadow:"inset 0 1px 2px 0 rgba(255, 255, 255, 0.5)"}},children:x})]})},bs="https://linktr.ee/s/about/trust-center/report",ps=({channel:e,participant:s,showBlockParticipant:n=!0,enabled:a=!0,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:o,onBlockParticipantClick:l,onReportParticipantClick:d,onActionComplete:h,logLabel:f="useChannelModerationActions"})=>{var M;const{service:u,debug:x}=Le(),c=(M=s==null?void 0:s.user)==null?void 0:M.id,g=!!(a&&n&&u&&c),[N,v]=m.useState(!1),[b,p]=m.useState(null),[L,T]=m.useState(!1),[I,D]=m.useState(!1),z=g&&((b==null?void 0:b.participantId)!==c||(b==null?void 0:b.service)!==u);return m.useEffect(()=>{if(!g||!u||!c){v(!1),p(null);return}let A=!1;return(async()=>{try{const E=await u.getBlockedUsers();if(A)return;v(E.some(R=>R.blocked_user_id===c))}catch(E){A||console.error(`[${f}] Failed to check blocked status:`,E)}finally{A||p({participantId:c,service:u})}})(),()=>{A=!0}},[g,u,c,f]),{isParticipantBlocked:N,isCheckingBlockedStatus:z,isLeaving:L,isUpdatingBlockStatus:I,handleLeaveConversation:async()=>{var A;if(!L){o==null||o(),x&&console.log(`[${f}] Leave conversation`,e.cid),T(!0);try{const E=((A=e._client)==null?void 0:A.userID)??null;await e.hide(E,!1),r&&await r(e),h==null||h()}catch(E){console.error(`[${f}] Failed to leave conversation`,E)}finally{T(!1)}}},handleBlockUser:async()=>{var A,E,R;if(!(I||!u)){l==null||l(),x&&console.log(`[${f}] Block member`,(A=s==null?void 0:s.user)==null?void 0:A.id),D(!0);try{await u.blockUser((E=s==null?void 0:s.user)==null?void 0:E.id),i&&await i((R=s==null?void 0:s.user)==null?void 0:R.id),h==null||h()}catch(P){console.error(`[${f}] Failed to block member`,P)}finally{D(!1)}}},handleUnblockUser:async()=>{var A,E,R;if(!(I||!u)){l==null||l(),x&&console.log(`[${f}] Unblock member`,(A=s==null?void 0:s.user)==null?void 0:A.id),D(!0);try{await u.unBlockUser((E=s==null?void 0:s.user)==null?void 0:E.id),i&&await i((R=s==null?void 0:s.user)==null?void 0:R.id),h==null||h()}catch(P){console.error(`[${f}] Failed to unblock member`,P)}finally{D(!1)}}},handleReportUser:()=>{d==null||d(),h==null||h(),window.open(bs,"_blank","noopener,noreferrer")}}},ae=({variant:e="default",className:s,children:n,...a})=>{const r=e==="danger";return t.jsx("button",{type:"button",className:C("flex w-full items-center gap-3 rounded-lg px-4 py-3 text-left text-sm transition-colors focus-ring disabled:cursor-not-allowed disabled:opacity-60",r?"text-danger hover:bg-danger/50":"text-charcoal hover:bg-sand",s),...a,children:n})},jt=({channel:e,participant:s,showDeleteConversation:n=!0,showBlockParticipant:a=!0,showReportParticipant:r=!0,onLeaveConversation:i,onBlockParticipant:o,onDeleteConversationClick:l,onBlockParticipantClick:d,onReportParticipantClick:h,customChannelActions:f,triggerClassName:u})=>{const[x,c]=m.useState(!1),g=m.useRef(null),N=m.useId(),v=m.useCallback(()=>c(!1),[]),{isParticipantBlocked:b,isCheckingBlockedStatus:p,isLeaving:L,isUpdatingBlockStatus:T,handleLeaveConversation:I,handleBlockUser:D,handleUnblockUser:z,handleReportUser:y}=ps({channel:e,participant:s,showBlockParticipant:a,enabled:x,onLeaveConversation:i,onBlockParticipant:o,onDeleteConversationClick:l,onBlockParticipantClick:d,onReportParticipantClick:h,onActionComplete:v,logLabel:"ChannelActionsMenu"});return m.useEffect(()=>{if(!x)return;const k=M=>{g.current&&!g.current.contains(M.target)&&c(!1)},F=M=>{M.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",k),document.addEventListener("keydown",F),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",F)}},[x]),!s||!(n||a||r||!!f)?null:t.jsxs("div",{ref:g,className:"relative",children:[t.jsxs("button",{className:u,type:"button","aria-haspopup":"true","aria-expanded":x,"aria-controls":x?N:void 0,onClick:()=>c(k=>!k),children:[t.jsx(w.DotsThreeIcon,{className:"size-5 text-black/90"}),t.jsx("span",{className:"sr-only",children:"More options"})]}),x&&t.jsx("div",{id:N,"aria-label":"Conversation options",className:C("absolute right-0 top-full z-50 mt-2 w-56 overflow-hidden","rounded-lg border border-sand bg-white p-1 shadow-max-elevation-light"),children:t.jsxs("ul",{className:"flex flex-col gap-1",children:[n&&t.jsx("li",{children:t.jsxs(ae,{onClick:I,disabled:L,"aria-busy":L,children:[L?t.jsx(w.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(w.SignOutIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Delete Conversation"})]})}),a&&t.jsx("li",{children:p?t.jsxs(ae,{disabled:!0,"aria-busy":!0,children:[t.jsx(w.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}),t.jsx("span",{children:"Block"})]}):b?t.jsxs(ae,{onClick:z,disabled:T,"aria-busy":T,children:[T?t.jsx(w.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(w.ProhibitInsetIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Unblock"})]}):t.jsxs(ae,{onClick:D,disabled:T,"aria-busy":T,children:[T?t.jsx(w.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(w.ProhibitInsetIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Block"})]})}),r&&t.jsx("li",{children:t.jsxs(ae,{variant:"danger",onClick:y,children:[t.jsx(w.FlagIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Report"})]})}),f]})})]})},vs=e=>t.jsx(_.DateSeparator,{...e,position:"center"}),Te="vote_up",Me="vote_down";function js(e){return e!=null&&e.length?e.some(s=>s.type===Me)?"down":e.some(s=>s.type===Te)?"up":null:null}function Et(e){const{channel:s}=_.useChannelStateContext(),{client:n}=_.useChatContext("useMessageVote"),a=m.useMemo(()=>js(e.own_reactions),[e.own_reactions]),r=m.useCallback(async()=>{if(n!=null&&n.userID)try{a==="up"?await s.deleteReaction(e.id,Te):await s.sendReaction(e.id,{type:Te},{enforce_unique:!0,skip_push:!0})}catch{}},[s,n==null?void 0:n.userID,e.id,a]),i=m.useCallback(async()=>{if(n!=null&&n.userID)try{a==="down"?await s.deleteReaction(e.id,Me):await s.sendReaction(e.id,{type:Me},{enforce_unique:!0,skip_push:!0})}catch{}},[s,n==null?void 0:n.userID,e.id,a]);return{selected:a,voteUp:r,voteDown:i}}function Tt(e){return(e==null?void 0:e.trim().toLowerCase().split(/[-_]/)[0])||void 0}function Pe({message:e,viewerLanguage:s}){var r;const n=e==null?void 0:e.text,a=Tt(s);return a?((r=e==null?void 0:e.i18n)==null?void 0:r[`${a}_text`])??n:n}const ws=m.lazy(()=>Promise.resolve().then(()=>require("./Card-Cp0Ioui8.cjs"))),Ns=m.lazy(()=>Promise.resolve().then(()=>require("./Card-DWmbH7oz.cjs"))),_s=m.lazy(()=>Promise.resolve().then(()=>require("./Card-CSqZXHCM.cjs"))),ze=()=>t.jsx("div",{className:"w-[280px] min-h-[200px] animate-pulse rounded-md bg-black/[0.06] shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_1px_2px_rgba(0,0,0,0.04),0_8px_32px_rgba(0,0,0,0.1)]","aria-hidden":!0}),ys=e=>t.jsx(m.Suspense,{fallback:t.jsx(ze,{}),children:t.jsx(ws,{...e})}),Mt=e=>t.jsx(m.Suspense,{fallback:t.jsx(ze,{}),children:t.jsx(Ns,{...e})}),At=e=>t.jsx(m.Suspense,{fallback:t.jsx(ze,{}),children:t.jsx(_s,{...e})}),Cs=Mt,ks=At,Ae={Composer:ys,Sent:Mt,Received:At,Creator:Cs,Visitor:ks},Ss=[[/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 ee(e){return e.startsWith("video/")?"video":e.startsWith("audio/")?"audio":e.startsWith("image/")?"image":"document"}function Rt(e){const s=Ss.find(([n])=>n.test(e));return s?s[1]:"generic"}const Is={video:w.VideoCameraIcon,audio:w.SpeakerHighIcon,image:w.ImageIcon,document:w.FileIcon},Es={pdf:w.FilePdfIcon,doc:w.FileDocIcon,xls:w.FileXlsIcon,csv:w.FileCsvIcon,ppt:w.FilePptIcon,zip:w.FileZipIcon,text:w.FileTextIcon,markdown:w.FileMdIcon,generic:w.FileIcon};function Ts(e){const s=ee(e);return s!=="document"?Is[s]:Es[Rt(e)]}function se(e,s){return m.createElement(Ts(e),s)}const Ms=e=>{var s,n;return"touches"in e?((s=e.touches[0])==null?void 0:s.clientX)??((n=e.changedTouches[0])==null?void 0:n.clientX)??0:e.clientX},As=({source:e,mimeType:s,poster:n,autoPlay:a=!1,playing:r,loop:i=!1,controls:o=!0,showProgress:l=!1,muted:d=!1,onContainerClick:h})=>{const f=ee(s),u=m.useRef(null),x=m.useRef(null),c=m.useRef(null),g=m.useRef(r),[N,v]=m.useState(a),[b,p]=m.useState(0),[L,T]=m.useState(!1),[I,D]=m.useState(!1),[z,y]=m.useState(!1),[O,k]=m.useState(!1),[F,M]=m.useState(!0),[A,E]=m.useState(null),R=m.useCallback(()=>{y(!1),v(!0)},[]),P=m.useCallback(j=>{const S=x.current;if(!S)return 0;const $=S.getBoundingClientRect();return Math.max(0,Math.min(1,(Ms(j)-$.left)/$.width))},[]),B=m.useCallback(j=>{const S=u.current;S&&S.duration&&(S.currentTime=j*S.duration)},[]),H=j=>{j.stopPropagation(),T(!0);const S=P(j);p(S),B(S)};m.useEffect(()=>{r!==void 0&&r!==g.current&&(g.current=r,v(r))},[r]),m.useEffect(()=>{if(!N){c.current!==null&&(cancelAnimationFrame(c.current),c.current=null);return}const j=()=>{const S=u.current;S&&S.duration&&!L&&p(S.currentTime/S.duration),c.current=requestAnimationFrame(j)};return c.current=requestAnimationFrame(j),()=>{c.current!==null&&cancelAnimationFrame(c.current)}},[N,L]),m.useEffect(()=>{const j=u.current;j&&(N?j.play().catch(S=>{v(!1),y(!0)}):j.pause())},[N]),m.useEffect(()=>{if(!L)return;const j=$=>p(P($)),S=$=>{T(!1),B(P($))};return window.addEventListener("mousemove",j),window.addEventListener("mouseup",S),window.addEventListener("touchmove",j,{passive:!0}),window.addEventListener("touchend",S),()=>{window.removeEventListener("mousemove",j),window.removeEventListener("mouseup",S),window.removeEventListener("touchmove",j),window.removeEventListener("touchend",S)}},[L,P,B]);const W=A?{aspectRatio:String(A)}:void 0,X=A?"":" aspect-video",U=Math.round(b*100);return t.jsxs("div",{role:"button",tabIndex:0,className:`relative cursor-pointer overflow-hidden bg-black ${X}`,style:W,onClick:j=>{if(h){h(j);return}z||o&&v(S=>!S)},onKeyDown:j=>{if(!(j.key!=="Enter"&&j.key!==" ")){if(j.preventDefault(),h){h(j);return}z||o&&v(S=>!S)}},children:[n&&(f==="audio"||F)&&t.jsx("img",{src:n,alt:"",className:"absolute inset-0 h-full w-full object-cover"}),!n&&(f==="audio"||F)&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:se(s,{className:"size-12 text-black/20",weight:"regular"})}),t.jsx("div",{className:"absolute inset-0",children:f==="audio"?t.jsx("audio",{ref:u,src:e,loop:i,muted:d,style:{width:"100%",height:"100%"},onLoadStart:()=>k(!0),onCanPlay:()=>{k(!1),M(!1)},onWaiting:()=>k(!0),onPlay:()=>y(!1),onEnded:()=>{i||(v(!1),p(0))},children:t.jsx("track",{kind:"captions"})}):t.jsx("video",{ref:u,src:e,loop:i,muted:d,playsInline:!0,style:{width:"100%",height:"100%"},onLoadStart:()=>k(!0),onCanPlay:()=>{k(!1),M(!1)},onWaiting:()=>k(!0),onPlay:()=>y(!1),onLoadedMetadata:()=>{const j=u.current;j instanceof HTMLVideoElement&&j.videoWidth&&j.videoHeight&&E(j.videoWidth/j.videoHeight)},onEnded:()=>{i||(v(!1),p(0))},children:t.jsx("track",{kind:"captions"})})}),O&&!z&&t.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center",children:t.jsx(w.CircleNotchIcon,{className:"size-8 animate-spin text-white/80",weight:"bold"})}),z&&!o&&t.jsx("div",{className:"absolute inset-0 z-30 flex cursor-pointer items-center justify-center bg-black/35",role:"button",tabIndex:0,"aria-label":"Play preview",onClick:j=>{j.stopPropagation(),R()},onKeyDown:j=>{j.key!=="Enter"&&j.key!==" "||(j.preventDefault(),j.stopPropagation(),R())},children:t.jsx("span",{className:"flex size-16 items-center justify-center rounded-full bg-white/20 text-white backdrop-blur-sm",children:t.jsx(w.PlayIcon,{className:"size-9 translate-x-0.5",weight:"fill"})})}),l&&!o&&t.jsx("div",{className:"absolute inset-x-0 bottom-0 px-3 pb-2.5 pt-6 bg-gradient-to-t from-black/40 to-transparent",children:t.jsx("div",{role:"slider","aria-label":"Playback position","aria-valuenow":U,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,ref:x,className:"relative flex h-4 w-full cursor-pointer items-center",onMouseDown:H,onTouchStart:H,onClick:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="ArrowRight"&&B(Math.min(1,b+.05)),j.key==="ArrowLeft"&&B(Math.max(0,b-.05))},children:t.jsx("div",{className:"w-full overflow-hidden rounded-full bg-white/30 h-1",children:t.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${U}%`}})})})}),o&&t.jsxs("div",{className:"absolute inset-x-0 bottom-0 flex items-center gap-2 bg-gradient-to-t from-black/60 to-transparent px-3 pb-2.5 pt-6 transition-all duration-200",children:[t.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),v(S=>!S)},className:"shrink-0 text-white","aria-label":N?"Pause":"Play",children:N?t.jsx(w.PauseIcon,{className:"size-5",weight:"fill"}):t.jsx(w.PlayIcon,{className:"size-5 translate-x-px",weight:"fill"})}),t.jsxs("div",{role:"slider","aria-label":"Playback position","aria-valuenow":U,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,ref:x,className:"relative flex h-4 w-full cursor-pointer items-center",onMouseDown:H,onTouchStart:H,onClick:j=>j.stopPropagation(),onMouseEnter:()=>D(!0),onMouseLeave:()=>D(!1),onKeyDown:j=>{j.key==="ArrowRight"&&B(Math.min(1,b+.05)),j.key==="ArrowLeft"&&B(Math.max(0,b-.05))},children:[t.jsx("div",{className:`w-full overflow-hidden rounded-full bg-white/30 transition-all duration-200 ${I||L?"h-1.5":"h-1"}`,children:t.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${U}%`}})}),t.jsx("div",{className:`absolute size-3 -translate-x-1/2 rounded-full bg-white shadow transition-[opacity,transform] duration-200 ${I||L?"scale-100 opacity-100":"scale-0 opacity-0"}`,style:{left:`${U}%`}})]})]})]})},wt=e=>e==="dark"?"size-12 text-white/20":"size-12 text-black/20",Rs=e=>e==="dark"?"aspect-video overflow-hidden bg-white/10":"aspect-video overflow-hidden bg-black/5",Oe=({mimeType:e,sourceUrl:s,thumbnailUrl:n,title:a,variant:r,mediaPlayerProps:i,containedImage:o=!1})=>{const l=ee(e),[d,h]=m.useState(!1);return s&&(l==="video"||l==="audio")?t.jsx(As,{source:s,mimeType:e,poster:n,controls:!0,...i}):s&&l==="image"?o?t.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:t.jsx("img",{src:s,alt:a??"",className:`absolute inset-0 h-full w-full object-contain transition-opacity duration-300 ${d?"opacity-100":"opacity-0"}`,draggable:!1,onLoad:()=>h(!0)})}):t.jsx("img",{src:s,alt:a??"",className:"block w-full",draggable:!1}):s&&l==="document"?n?o?t.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:t.jsx("img",{src:n,alt:a??"",className:`absolute inset-0 h-full w-full object-contain transition-opacity duration-300 ${d?"opacity-100":"opacity-0"}`,draggable:!1,onLoad:()=>h(!0)})}):t.jsx("img",{src:n,alt:"",className:"block w-full",draggable:!1}):t.jsx("div",{className:`flex aspect-video w-full items-center justify-center ${r==="dark"?"bg-white/10":"bg-black/5"}`,children:se(e,{className:wt(r),weight:"regular"})}):n?t.jsx("div",{className:`relative ${Rs(r)}`,children:t.jsx("img",{src:n,alt:a??"",draggable:!1,className:"absolute inset-0 h-full w-full object-cover"})}):t.jsx("div",{className:`flex aspect-video w-full items-center justify-center ${r==="dark"?"bg-white/10":"bg-black/5"}`,children:se(e,{className:wt(r),weight:"regular"})})},Lt=({variant:e,thumbnail:s,title:n,placeholderTitle:a="Attachment title",mimeType:r,detail:i,statusBadge:o,action:l,topLeft:d,topRight:h,rootRef:f,"data-testid":u})=>{const x=e==="dark",c=x?n??a:n??"",g=x&&!n;return t.jsxs("div",{ref:f,"data-testid":u,className:C("relative w-[280px] select-none overflow-hidden rounded-[24px] shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]",x?"bg-[#121110]":"bg-white"),children:[d?t.jsx("div",{className:"pointer-events-auto absolute left-3 top-3 z-50",children:d}):null,h?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-50",children:h}):null,s,t.jsxs("div",{className:"px-4 pb-3 pt-3",children:[c.trim()!==""&&t.jsx("p",{className:C("mb-0.5 truncate text-base font-medium",{"text-black":!x,"text-white/30":x&&g,"text-white":x&&!g}),children:c}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[se(r,{className:C("size-5 shrink-0",x?"text-white/55":"text-black/55"),weight:"regular"}),i!=null&&i!==""&&t.jsx("span",{className:C("text-xs font-medium",x?"text-white/55":"text-black/55"),children:i}),o]}),l]})]})};function Dt(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Fe(e){return`w-[280px] select-none overflow-hidden rounded-[24px] ${e?"bg-[#121110]":"bg-[#F3F3F1]"} shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]`}function Ls(e){return e?"bg-white/10":"bg-black/5"}function Ds(e){return e?"text-white":"text-black"}function Ps(e){return e?"text-white/55":"text-black/55"}function zs(e){return e?"text-white/40":"text-black/40"}function Os(e){return e?"text-white/20":"text-black/20"}const $e=({attachment:e,isMyMessage:s})=>{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,h=t.jsxs(m.Fragment,{children:[t.jsx("div",{className:"p-2",children:r?t.jsx("img",{src:r,alt:n??"",className:"aspect-video w-full rounded-[20px] object-cover"}):t.jsx("div",{className:`aspect-video w-full rounded-[20px] ${Ls(s)} flex items-center justify-center`,children:t.jsx(w.LinkIcon,{className:`size-12 ${Os(s)}`})})}),t.jsxs("div",{className:"px-3 pb-3",children:[n&&t.jsx("p",{className:`truncate text-[14px] font-medium leading-5 ${Ds(s)}`,children:n}),a&&t.jsx("p",{className:`truncate text-[12px] leading-4 ${Ps(s)}`,children:a}),d&&t.jsx("p",{className:`mt-1 truncate text-[12px] leading-4 ${zs(s)}`,children:d})]})]});return d?t.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"block no-underline",children:h}):t.jsx("div",{className:"block",children:h})};function Be(e){return e.type==="link"||!!e.og_scrape_url&&!e.asset_url}function we(e){var s;return(s=e.attachments)==null?void 0:s.find(Be)}async function Fs(e,s){let n;try{n=s??new URL(e).pathname.split("/").pop()??"download"}catch{n=s??"download"}const a=await fetch(e,{mode:"cors"});if(!a.ok)throw new Error(`HTTP ${a.status}`);const r=await a.blob(),i=URL.createObjectURL(r),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 $s=({url:e,filename:s})=>{const[n,a]=m.useState(!1),r=i=>{i.stopPropagation();const o=window.open("","_blank","noopener,noreferrer");a(!0),Fs(e,s).then(()=>{o==null||o.close()}).catch(()=>{o&&(o.location.href=e)}).finally(()=>a(!1))};return t.jsx("button",{type:"button",onClick:r,disabled:n,className:"mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full bg-[#121110] px-4 text-sm font-medium leading-none text-white hover:bg-[#2a2928] disabled:opacity-70",children:n?t.jsx(w.CircleNotchIcon,{className:"size-4 animate-spin text-white",weight:"bold"}):t.jsxs(m.Fragment,{children:[t.jsx(w.DownloadSimpleIcon,{className:"size-4 text-white",weight:"bold"}),"Download"]})})};function Ne(e){var u,x,c,g;const s=(u=e.attachments)==null?void 0:u.find(N=>N.type==="video"&&N.asset_url),n=(x=e.attachments)==null?void 0:x.find(N=>N.type==="image"&&N.image_url),a=(c=e.attachments)==null?void 0:c.find(N=>N.type==="audio"&&N.asset_url),r=(g=e.attachments)==null?void 0:g.find(N=>N.type==="file"&&N.asset_url),i=s??n??a??r,o=(s==null?void 0:s.asset_url)??(n==null?void 0:n.image_url)??(a==null?void 0:a.asset_url)??(r==null?void 0:r.asset_url);if(!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,h=i==null?void 0:i.file_size,f=s==null?void 0:s.thumb_url;return{resolvedUrl:o,resolvedType:l,title:d,fileSize:h,thumbnailUrl:f}}const Pt=({resolvedUrl:e,resolvedType:s,title:n,fileSize:a,thumbnailUrl:r})=>{const i=a!==void 0?Dt(a):void 0;return t.jsx(Lt,{variant:"dark",title:n,placeholderTitle:"",mimeType:s,detail:i,thumbnail:t.jsx(Oe,{mimeType:s,sourceUrl:e,thumbnailUrl:r,title:n,variant:"dark"})})},zt=({resolvedUrl:e,resolvedType:s,title:n,fileSize:a,thumbnailUrl:r})=>{const i=ee(s),o=a!==void 0?Dt(a):void 0;return t.jsx(Lt,{variant:"light",title:n,mimeType:s,detail:o,thumbnail:t.jsx(Oe,{mimeType:s,sourceUrl:e,thumbnailUrl:r,title:n,variant:"light",containedImage:i==="image"||i==="document"}),action:t.jsx($s,{url:e,filename:n})})},Bs=({message:e,isMyMessage:s=!1})=>{const n=we(e),a=Ne(e);if(!n&&!a)return null;const r=s?"str-chat__message str-chat__message-simple str-chat__message--me str-chat__message-simple--me":"str-chat__message str-chat__message-simple str-chat__message--other";return t.jsxs("div",{className:r,children:[!s&&e.user&&t.jsx(te,{className:"str-chat__avatar str-chat__message-sender-avatar",id:e.user.id,image:e.user.image,name:e.user.name??e.user.id}),t.jsx("div",{className:"str-chat__message-inner",style:{marginInlineEnd:0,marginInlineStart:0},children:t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsx("div",{className:"str-chat__message-bubble",style:{padding:0,borderRadius:0,overflow:"visible",background:"transparent"},children:n?t.jsx("div",{className:Fe(s),children:t.jsx($e,{attachment:n,isMyMessage:s})}):s?t.jsx(Pt,{...a}):t.jsx(zt,{...a})})})})]})},Us=({message:e})=>{const s=we(e);if(s)return t.jsx("div",{className:Fe(!0),children:t.jsx($e,{attachment:s,isMyMessage:!0})});const n=Ne(e);return n?t.jsx(Pt,{...n}):null},Vs=({message:e})=>{const s=we(e);if(s)return t.jsx("div",{className:Fe(!1),children:t.jsx($e,{attachment:s,isMyMessage:!1})});const n=Ne(e);return n?t.jsx(zt,{...n}):null},Gs=Object.assign(Bs,{Creator:Us,Visitor:Vs}),Hs={isUnlocking:()=>!1},Ys={LockedAttachment:Hs},Ot=m.createContext({}),qs=Ot.Provider;function Ft(e){return m.useContext(Ot)[e]??Ys[e]}const Xs=({size:e=15})=>t.jsx("svg",{width:e,height:e,viewBox:"0 0 15 15",fill:"none","aria-hidden":"true",children:t.jsx("path",{d:"M12.003 9a.985.985 0 0 1-.652.934l-3.223 1.191-1.188 3.226a.995.995 0 0 1-1.867 0l-1.195-3.226L.65 9.937a.995.995 0 0 1 0-1.867l3.227-1.195 1.187-3.226a.995.995 0 0 1 1.868 0l1.195 3.226 3.226 1.187a.99.99 0 0 1 .649.938m3-5.83a.52.52 0 0 1-.344.492l-1.702.63-.627 1.703a.525.525 0 0 1-.986 0l-.63-1.704-1.704-.627a.525.525 0 0 1 0-.986l1.703-.63.627-1.704a.526.526 0 0 1 .986 0l.631 1.703 1.704.627a.52.52 0 0 1 .342.495",fill:"currentColor",fillOpacity:.55})}),Ws=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)==="MESSAGE_TIP"},Ks=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)==="MESSAGE_PAID"},be=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)==="MESSAGE_CHATBOT"},Js=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)==="MESSAGE_ATTACHMENT"},$t=e=>Ws(e)||Ks(e),Zs=e=>{var s;return $t(e)&&!((s=e.text)!=null&&s.trim())},Ce=({message:e,standalone:s=!1,isMyMessage:n=!1,hasAttachment:a=!1})=>{var u;const r=$t(e),i=be(e);if(!r&&!i)return null;if(r){const x=(u=e.metadata)==null?void 0:u.amount_text;if(!x)return null;const c=s?"message-tip-standalone":"message-tag message-tag--tip",g=s?`${x} tip`:`Delivered with ${x} tip`;return t.jsxs("div",{className:c,children:[t.jsx(w.GiftIcon,{size:s?14:12}),t.jsx("span",{children:g})]})}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(" "),h=t.jsx("span",{className:"message-chatbot-indicator__label",children:l}),f=t.jsx("span",{className:"message-chatbot-indicator__icon",children:t.jsx(Xs,{size:o?12:15})});return t.jsx("div",{className:d,"data-testid":"message-chatbot-indicator",children:n&&!o?t.jsxs(t.Fragment,{children:[h,f]}):t.jsxs(t.Fragment,{children:[f,h]})})},Bt=({selected:e,onVoteUp:s,onVoteDown:n})=>t.jsxs("div",{className:"message-vote-buttons",children:[t.jsx("button",{type:"button",className:C("message-vote-button focus-ring",{"message-vote-button--selected":e==="up"}),onClick:s,"aria-label":"Good response","aria-pressed":e==="up","data-tooltip":"Good response",children:t.jsx(w.ThumbsUpIcon,{size:16,weight:e==="up"?"fill":"regular"})}),t.jsx("button",{type:"button",className:C("message-vote-button focus-ring",{"message-vote-button--selected":e==="down"}),onClick:n,"aria-label":"Bad response","aria-pressed":e==="down","data-tooltip":"Bad response",children:t.jsx(w.ThumbsDownIcon,{size:16,weight:e==="down"?"fill":"regular"})})]}),Qs=e=>{var st,nt,at,rt,it,ot,lt,ct,dt,ut,mt,ht,xt,ft;const{additionalMessageInputProps:s,chatbotVotingEnabled:n,editing:a,endOfGroup:r,firstOfGroup:i,groupedByUser:o,handleAction:l,handleOpenThread:d,handleRetry:h,highlighted:f,isMessageAIGenerated:u,isMyMessage:x,message:c,renderText:g,threadList:N,viewerLanguage:v}=e,{client:b}=_.useChatContext("CustomMessage"),{channel:p}=_.useChannelStateContext("CustomMessage"),{isUnlocking:L,onUnlockClick:T,onFetchSource:I,onDownloadClick:D}=Ft("LockedAttachment"),[z,y]=m.useState(!1),O=_.useMessageReminder(c.id),{selected:k,voteUp:F,voteDown:M}=Et(c),{Attachment:A=_.Attachment,EditMessageModal:E=_.EditMessageModal,MessageActions:R,MessageBlocked:P=_.MessageBlocked,MessageBouncePrompt:B=_.MessageBouncePrompt,MessageDeleted:H=_.MessageDeleted,MessageIsThreadReplyInChannelButtonIndicator:W=_.MessageIsThreadReplyInChannelButtonIndicator,MessageRepliesCountButton:X=_.MessageRepliesCountButton,ReminderNotification:U=_.ReminderNotification,StreamedMessageText:j=_.StreamedMessageText,PinIndicator:S}=_.useComponentContext("CustomMessage"),$=_.messageHasAttachments(c),Y=_.messageHasReactions(c),G=m.useMemo(()=>u==null?void 0:u(c),[u,c]),V=m.useMemo(()=>{const ce=c.attachments??[],ge=c.shared_location?[c.shared_location,...ce]:ce;if(!be(c))return ge;const gt=ge.filter(bt=>!("type"in bt)||!Be(bt));return gt.length===ge.length?ge:gt},[c]),q=m.useMemo(()=>{const ce=Pe({message:c,viewerLanguage:v});return ce===c.text?c:{...c,text:ce}},[c,v]);if(_.isDateSeparatorMessage(c))return null;if(c.deleted_at||c.type==="deleted")return t.jsx(H,{message:c});if(_.isMessageBlocked(c))return t.jsx(P,{});const re=!N&&!!c.reply_count,ie=!N&&c.show_in_channel&&c.parent_id,oe=c.status==="failed"&&((st=c.error)==null?void 0:st.status)!==403,Z=_.isMessageBounced(c);let K;oe?K=()=>h(c):Z&&(K=()=>y(!0));const J=x(),us=C("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":$,"str-chat__message--highlighted":f,"str-chat__message--pinned pinned-message":c.pinned,"str-chat__message--with-reactions":Y,"str-chat__message-send-can-be-retried":(c==null?void 0:c.status)==="failed"&&((nt=c==null?void 0:c.error)==null?void 0:nt.status)!==403,"str-chat__message-with-thread-link":re||ie,"str-chat__virtual-message__wrapper--end":r,"str-chat__virtual-message__wrapper--first":i,"str-chat__virtual-message__wrapper--group":o}),Ze=c.poll_id&&b.polls.fromState(c.poll_id),Qe=Zs(c),le=be(c),et=Js(c),ye=!!(V!=null&&V.length&&!c.quoted_message),tt=le&&J&&ye;return t.jsxs(t.Fragment,{children:[a&&t.jsx(E,{additionalMessageInputProps:s}),z&&t.jsx(_.MessageBounceModal,{MessageBouncePrompt:B,onClose:()=>y(!1),open:z}),t.jsxs("div",{className:us,"data-message-id":c.id,children:[S&&t.jsx(S,{}),!!O&&t.jsx(U,{reminder:O}),c.user&&t.jsx(te,{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:le}),t.jsx("div",{className:C("str-chat__message-inner",{"str-chat__simple-message--error-failed":oe||Z}),"data-testid":"message-inner",onClick:K,onKeyDown:K,role:K?"button":void 0,tabIndex:K?0:void 0,style:{marginInlineEnd:0,marginInlineStart:0},children:et?t.jsxs("div",{className:"str-chat__message-bubble-wrapper",children:[J?t.jsxs("div",{className:"flex items-center gap-2",children:[R&&t.jsx(R,{}),t.jsx(Ae.Sent,{title:(at=c.metadata)==null?void 0:at.attachment_title,mimeType:(rt=c.metadata)==null?void 0:rt.attachment_mime_type,thumbnailUrl:(it=c.metadata)==null?void 0:it.attachment_thumbnail,amountText:(ot=c.metadata)==null?void 0:ot.amount_text,detail:(lt=c.metadata)==null?void 0:lt.attachment_detail,paymentStatus:(ct=c.metadata)==null?void 0:ct.payment_status,onPreviewClick:()=>T==null?void 0:T(c,p),onFetchSource:async()=>await(I==null?void 0:I(c,p))})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ae.Received,{title:(dt=c.metadata)==null?void 0:dt.attachment_title,mimeType:(ut=c.metadata)==null?void 0:ut.attachment_mime_type,thumbnailUrl:(mt=c.metadata)==null?void 0:mt.attachment_thumbnail,amountText:(ht=c.metadata)==null?void 0:ht.amount_text,detail:(xt=c.metadata)==null?void 0:xt.attachment_detail,paymentStatus:(ft=c.metadata)==null?void 0:ft.payment_status,isUnlocking:L(c.id),onUnlockClick:()=>T==null?void 0:T(c,p),onFetchSource:async()=>await(I==null?void 0:I(c,p)),onDownloadClick:()=>D==null?void 0:D(c,p)}),R&&t.jsx(R,{})]}),c.text&&t.jsx("div",{className:"str-chat__message-bubble",children:t.jsx(_.MessageText,{message:q,renderText:g})})]}):Qe?t.jsx(Ce,{message:c,standalone:!0}):t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsxs("div",{className:"str-chat__message-bubble",children:[le&&!tt&&t.jsx(Ce,{message:c,hasAttachment:ye,isMyMessage:J}),Ze&&t.jsx(_.Poll,{poll:Ze}),V!=null&&V.length&&!c.quoted_message?t.jsx(A,{actionHandler:l,attachments:V}):null,G?t.jsx(j,{message:q,renderText:g}):t.jsx(_.MessageText,{message:q,renderText:g}),t.jsx(_.MessageErrorIcon,{})]})})}),!et&&!Qe&&t.jsxs("div",{className:"str-chat__message-footer",children:[(!le||tt)&&t.jsx(Ce,{message:c,hasAttachment:ye,isMyMessage:J}),n&&le&&t.jsx(Bt,{selected:k,onVoteUp:F,onVoteDown:M})]}),re&&t.jsx(X,{onClick:d,reply_count:c.reply_count}),ie&&t.jsx(W,{})]},c.id)]})},en=m.memo(Qs,(e,s)=>e.chatbotVotingEnabled!==s.chatbotVotingEnabled||e.viewerLanguage!==s.viewerLanguage?!1:_.areMessageUIPropsEqual(e,s)),tn=e=>{const s=_.useMessageContext("CustomMessage");return t.jsx(en,{...s,...e})},sn=()=>{var n;const{handleDelete:e,message:s}=_.useMessageContext("CustomMessageActions");return((n=s.metadata)==null?void 0:n.payment_status)==="paid"?null:t.jsx(Re.DefaultDropdownActionButton,{onClick:e,"aria-label":"Delete",title:"Delete",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:t.jsx(w.TrashSimpleIcon,{size:16,weight:"light","aria-hidden":!0})})},nn=()=>{const{handleFlag:e}=_.useMessageContext("CustomMessageActions");return t.jsx(Re.DefaultDropdownActionButton,{onClick:e,"aria-label":"Report",title:"Report",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:t.jsx(w.FlagIcon,{size:16,weight:"light","aria-hidden":!0})})},an=()=>{var s;const{message:e}=_.useMessageContext("CustomMessageActions");return((s=e.metadata)==null?void 0:s.custom_type)!=="MESSAGE_ATTACHMENT"?null:t.jsx(Re.MessageActions,{messageActionSet:[{Component:sn,placement:"quick",type:"delete"},{Component:nn,placement:"quick",type:"flag"}]})},rn=({link:e,onDismiss:s})=>{const{og_scrape_url:n,title:a,image_url:r}=e,i=o=>{o.preventDefault(),s(n)};return t.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"relative block w-full rounded-[24px] bg-[#121110] p-2 no-underline transition-opacity hover:opacity-90",children:[r&&t.jsx("img",{src:r,alt:a||"",className:"h-[180px] w-full rounded-[20px] object-cover"}),t.jsx("button",{type:"button",onClick:i,className:"absolute right-4 top-4 flex size-6 items-center justify-center rounded-full border border-white/40 bg-white/70 backdrop-blur-2xl focus-ring","aria-label":"Close link preview",children:t.jsx(w.XIcon,{className:"size-4 text-black/90"})}),t.jsxs("div",{className:"p-2",children:[a&&t.jsx("div",{className:"truncate text-[14px] font-medium leading-5 text-white",children:a}),t.jsx("div",{className:"truncate text-[12px] leading-4 text-white/55",children:n})]})]})},on=e=>({linkPreviews:Array.from(e.previews.values()).filter(s=>Ee.LinkPreviewsManager.previewIsLoaded(s)||Ee.LinkPreviewsManager.previewIsLoading(s))}),ln=()=>{const{linkPreviewsManager:e}=_.useMessageComposer(),{linkPreviews:s}=_.useStateStore(e.state,on),n=r=>{e.dismissPreview(r)};return s.length>0?t.jsx("div",{className:"flex flex-col items-stretch w-full gap-2 mb-4",children:s.map(r=>t.jsx(rn,{link:r,onDismiss:n},r.og_scrape_url))}):null},Ut=m.createContext(!1),cn=({sendMessage:e,disabled:s,...n})=>t.jsx("button",{...n,type:"button","aria-label":"Send",disabled:s,onClick:e,children:t.jsx(w.ArrowUpIcon,{weight:"bold",className:"size-4"})}),dn=()=>{const e=m.useContext(Ut),{handleSubmit:s}=_.useMessageInputContext(),n=_.useMessageComposerHasSendableData(),a=e||!n,{SendButton:r=cn,AttachmentPreviewList:i=_.AttachmentPreviewList}=_.useComponentContext("CustomMessageInput");return t.jsxs("div",{className:"central-container flex flex-col gap-2 min-w-0 w-full 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)]",children:[t.jsx(_.QuotedMessagePreview,{}),t.jsx(ln,{}),t.jsx(i,{}),t.jsxs("div",{className:"flex",children:[t.jsx("div",{className:"w-full ml-2 mr-4 self-center leading-[0]",children:t.jsx(_.TextareaComposer,{"aria-disabled":e||void 0,className:"w-full resize-none outline-none leading-5 placeholder:text-black/30 text-sm",autoFocus:!e,maxRows:4,readOnly:e,tabIndex:e?-1:void 0})}),t.jsx(r,{sendMessage:s,"aria-label":"Send",className:"str-chat__send-button mt-auto flex justify-center items-center flex-shrink-0 rounded-full size-8 bg-[#121110] disabled:bg-[#F1F0EE] disabled:text-black/20 text-white focus-ring","data-testid":"send-button",disabled:a,type:"button"})]})]})},un=({renderActions:e,renderFooter:s,disabled:n=!1,disabledReason:a})=>{var o;const{channel:r}=_.useChannelStateContext(),i=((o=r==null?void 0:r.data)==null?void 0:o.frozen)===!0;return n?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"messaging-composer-locked-panel flex w-full flex-col items-center justify-center gap-3 px-6 py-4",children:a?t.jsx("p",{className:"max-w-[345px] text-center text-xs font-normal leading-[1.3] tracking-[0.12px] text-black/40",children:a}):null}),s==null?void 0:s()]}):t.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[t.jsxs("div",{inert:i?"":void 0,"aria-disabled":i||void 0,className:"message-input flex items-end gap-4 aria-disabled:opacity-40",children:[e&&t.jsx("div",{className:"flex h-12 shrink-0 items-center justify-center",children:e()}),t.jsx(Ut.Provider,{value:i,children:t.jsx(_.MessageInput,{Input:dn})})]}),s==null?void 0:s()]})},mn=["SYSTEM_DM_AGENT_PAUSED","SYSTEM_DM_AGENT_RESUMED"],hn={SYSTEM_DM_AGENT_PAUSED:"DM Agent has left the conversation",SYSTEM_DM_AGENT_RESUMED:"DM Agent has rejoined the conversation"},xn=["SYSTEM_AGE_SAFETY_BLOCKED"],fn={SYSTEM_AGE_SAFETY_BLOCKED:"This user isn’t able to reply because they don’t meet our age safety guidelines."},ke="age safety guidelines.",gn="https://linktr.ee/s/about/contact",Nt=e=>mn.includes(e),bn=e=>xn.includes(e),pn=e=>{var a;const s=(a=e.metadata)==null?void 0:a.custom_type;if(Nt(s))return{kind:"dm-agent",type:s};if(bn(s))return{kind:"age-safety",type:s};const n=e.dm_agent_system_type;if(Nt(n))return{kind:"dm-agent",type:n}},vn=e=>{const s=e.indexOf(ke);if(s===-1)return e;const n=s+ke.length;return t.jsxs(t.Fragment,{children:[e.slice(0,s),t.jsx("a",{href:gn,target:"_blank",rel:"noopener noreferrer",className:"mes-age-safety-system-message__emphasis font-medium text-inherit underline",children:ke}),e.slice(n)]})},jn=e=>{var a,r;const s=e.message.hide_date===!0,n=pn(e.message);if((n==null?void 0:n.kind)==="dm-agent"){const i=((a=e.message.text)==null?void 0:a.trim())||hn[n.type];return t.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[t.jsxs("div",{className:"mes-dm-agent-system-message mx-auto mb-2 inline-flex w-fit max-w-[min(100%,480px)] items-center justify-center gap-[10px] rounded-[12px] border border-[rgba(0,0,0,0.08)] p-3 text-[rgba(0,0,0,0.55)]","data-testid":"dm-agent-system-message","data-dm-agent-system-type":n.type,children:[t.jsx(w.SparkleIcon,{size:16,weight:"regular","aria-hidden":!0,className:"mes-dm-agent-system-message__sparkle shrink-0"}),t.jsx("p",{className:"mes-dm-agent-system-message__text m-0 text-center text-[14px] font-normal leading-5 tracking-[0.21px]",children:i})]}),!s&&t.jsx(_.MessageTimestamp,{message:e.message})]})}if((n==null?void 0:n.kind)==="age-safety"){const i=((r=e.message.text)==null?void 0:r.trim())||fn[n.type];return t.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[t.jsxs("div",{className:"mes-age-safety-system-message box-border mx-auto mb-2 flex w-full max-w-[329px] items-start justify-center gap-3 rounded-[12px] border border-[var(--border-secondary,rgba(0,0,0,0.08))] bg-[var(--bg-warning-subtle,#fef3c6)] px-2 py-4 pl-5 text-[color:var(--text-warning-on-warning,#894b00)]","data-testid":"age-safety-system-message","data-age-safety-system-type":n.type,children:[t.jsx(w.ProhibitIcon,{size:24,weight:"duotone","aria-hidden":!0,className:"mes-age-safety-system-message__icon shrink-0 text-[color:var(--text-warning-on-warning,#894b00)]","data-testid":"age-safety-system-message-icon"}),t.jsx("div",{className:"mes-age-safety-system-message__content min-w-0 flex-[1_0_0]",children:t.jsx("p",{className:"m-0 text-balance text-left text-[12px] font-normal leading-4 tracking-[0.21px] text-[color:var(--text-warning-on-warning,#894b00)]",children:vn(i)})})]}),!s&&t.jsx(_.MessageTimestamp,{message:e.message})]})}return t.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[t.jsxs("div",{className:"str-chat__message--system__text",children:[t.jsx("div",{className:"str-chat__message--system__line"}),t.jsx("p",{children:e.message.text}),t.jsx("div",{className:"str-chat__message--system__line"})]}),!s&&t.jsx(_.MessageTimestamp,{message:e.message})]})},Vt=m.createContext(!1),Se=({cx:e,index:s})=>t.jsx("circle",{cx:e,cy:"6.15",r:"3.9",fill:"#A0A0A0",children:t.jsx("animateTransform",{attributeName:"transform",type:"translate",values:"0 0; 0 -2.25; 0 0;",dur:"900ms",begin:`${120*s}ms`,repeatCount:"indefinite"})}),wn=new Set([_.AIStates.Thinking,_.AIStates.Generating,_.AIStates.ExternalSources]),Nn=({threadList:e})=>{var g,N;const{channel:s,channelConfig:n,thread:a}=_.useChannelStateContext(),{client:r}=_.useChatContext(),{typing:i={}}=_.useTypingContext(),{aiState:o}=_.useAIState(s),l=m.useContext(Vt);if(!e&&l&&wn.has(o)){const v=_n(s,(g=r.user)==null?void 0:g.id);return t.jsx(_t,{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 h=e?[]:Object.values(i).filter(({parent_id:v,user:b})=>{var p;return(b==null?void 0:b.id)!==((p=r.user)==null?void 0:p.id)&&!v}),f=e?Object.values(i).filter(({parent_id:v,user:b})=>{var p;return(b==null?void 0:b.id)!==((p=r.user)==null?void 0:p.id)&&v===(a==null?void 0:a.id)}):[],u=e?f:h;if(!u.length)return null;const x=(N=u[0])==null?void 0:N.user,c=x!=null&&x.id&&s.state.members[x.id]?s.state.members[x.id].user:void 0;return t.jsx(_t,{avatarId:(x==null?void 0:x.id)??(c==null?void 0:c.id)??"typing-user",avatarName:(x==null?void 0:x.name)??(c==null?void 0:c.name)??(x==null?void 0:x.id)??"Typing user",avatarImage:(x==null?void 0:x.image)??(c==null?void 0:c.image),testId:"typing-indicator"})},_t=({avatarId:e,avatarName:s,avatarImage:n,testId:a})=>t.jsx("div",{className:"str-chat__li str-chat__li--single str-chat__typing-indicator !static","data-testid":a,style:{marginBottom:"var(--messaging-channel-input-spacer-height, 80px)"},children:t.jsxs("div",{className:"str-chat__message str-chat__message-simple str-chat__message--regular str-chat__message--received str-chat__message--other str-chat__message--has-text",children:[t.jsx(te,{className:"str-chat__avatar str-chat__message-sender-avatar",id:e,name:s,image:n??void 0,size:24,shape:"circle"}),t.jsx("div",{className:"str-chat__message-inner mx-0",children:t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsx("div",{className:"str-chat__message-bubble",children:t.jsx("div",{className:"str-chat__message-text min-h-11 flex items-center",children:t.jsx("div",{className:"str-chat__message-text-inner str-chat__message-simple-text-inner",children:t.jsxs("svg",{"aria-hidden":"true",className:"block overflow-visible",viewBox:"0 0 32 12.3",width:"32",height:"13",overflow:"visible",children:[t.jsx(Se,{cx:"4",index:0}),t.jsx(Se,{cx:"16",index:1}),t.jsx(Se,{cx:"28",index:2})]})})})})})})]})});function _n(e,s){var a;const n=((a=e==null?void 0:e.state)==null?void 0:a.members)??{};for(const r of Object.values(n)){const i=r==null?void 0:r.user;if(i&&i.id!==s)return i}}const Gt=()=>null,yn=({className:e,message:s})=>t.jsxs("div",{className:C("flex items-center justify-center h-full",e),children:[t.jsxs("svg",{viewBox:"0 0 100 100",className:"size-8 fill-pebble",stroke:"none",children:[t.jsx("circle",{cx:"6",cy:"50",r:"6",children:t.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 15 ; 0 -15; 0 15",repeatCount:"indefinite",begin:"0.1"})}),t.jsx("circle",{cx:"30",cy:"50",r:"6",children:t.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 10 ; 0 -10; 0 10",repeatCount:"indefinite",begin:"0.2"})}),t.jsx("circle",{cx:"54",cy:"50",r:"6",children:t.jsx("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 5 ; 0 -5; 0 5",repeatCount:"indefinite",begin:"0.3"})})]}),s&&t.jsx("span",{className:"text-stone",children:s})]}),pe=m.memo(()=>t.jsx("div",{className:"messaging-loading-state flex items-center justify-center h-full",children:t.jsxs("div",{className:"flex items-center",children:[t.jsx(yn,{className:"w-6 h-6"}),t.jsx("span",{className:"text-sm text-stone",children:"Loading messages"})]})}));pe.displayName="LoadingState";const de=({channel:e,participant:s})=>{const n=(s==null?void 0:s.customer)===!0,a=St(e);return!n&&!a?null:t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",children:[n&&t.jsx("span",{role:"img","aria-label":"Customer",className:"inline-flex size-4 items-center justify-center rounded-full bg-[#22C55E] text-white",children:t.jsx(w.CurrencyDollarIcon,{"aria-hidden":"true",className:"size-3",weight:"bold"})}),a&&t.jsx("span",{role:"img","aria-label":"Starred conversation",className:"inline-flex size-4 items-center justify-center rounded-full bg-[#F6C343] text-white",children:t.jsx(w.StarIcon,{"aria-hidden":"true",className:"size-3",weight:"fill"})})]})},ne="size-10 rounded-full hover:bg-[#E5E4E1] flex items-center justify-center transition-colors duration-150 focus-ring",yt="Replies instantly with AI assistant",Cn=({onBack:e,showBackButton:s,showStarButton:n=!1,dmAgentEnabled:a=!1,onLeaveConversation:r,onBlockParticipant:i,showDeleteConversation:o=!0,showBlockParticipant:l=!0,showReportParticipant:d=!0,onDeleteConversationClick:h,onBlockParticipantClick:f,onReportParticipantClick:u,customChannelActions:x,renderChannelActions:c,showChannelInfo:g=!0,onParticipantNameClick:N,renderHeaderTitleBadges:v})=>{var y,O,k,F,M;const{channel:b}=_.useChannelStateContext(),p=m.useMemo(()=>{var R,P;const A=(R=b._client)==null?void 0:R.userID;return A?Object.values(((P=b.state)==null?void 0:P.members)||{}).find(B=>{var H;return((H=B.user)==null?void 0:H.id)&&B.user.id!==A}):void 0},[(y=b._client)==null?void 0:y.userID,(O=b.state)==null?void 0:O.members]),L=De(p==null?void 0:p.user),T=(k=p==null?void 0:p.user)==null?void 0:k.image,I=St(b),D=v==null?void 0:v({channel:b,participant:p}),z=async()=>{try{I?await b.unpin():await b.pin()}catch(A){console.error("[CustomChannelHeader] Failed to update pinned status:",A)}};return t.jsxs("div",{className:"@container",children:[t.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] w-full items-center @lg:hidden px-6 py-3",children:[t.jsx("div",{className:"flex items-center gap-2",children:s&&t.jsx("button",{className:C(ne,"messaging-channel-view-back-button-mobile bg-[#F1F0EE]"),onClick:e||(()=>{}),type:"button","aria-label":"Back to conversations",children:t.jsx(w.ArrowLeftIcon,{className:"size-5 text-black/90"})})}),t.jsxs("div",{className:"flex flex-col gap-1 items-center",children:[t.jsx(te,{id:((F=p==null?void 0:p.user)==null?void 0:F.id)||b.id||"unknown",name:L,image:T,dmAgentEnabled:a,size:48}),N?t.jsxs("button",{type:"button",onClick:N,"aria-label":`View details for ${L}`,className:"flex max-w-full items-center gap-0.5 rounded text-center text-xs font-medium text-black/90 transition-opacity hover:opacity-70",children:[t.jsx("span",{className:"min-w-0 truncate",children:L}),t.jsx(de,{channel:b,participant:p}),D&&t.jsx("span",{className:"shrink-0",children:D}),t.jsx(w.CaretRightIcon,{className:"size-3 shrink-0",weight:"bold"})]}):t.jsxs("p",{className:"flex max-w-full items-center justify-center gap-1 text-center text-xs font-medium text-black/90",children:[t.jsx("span",{className:"min-w-0 truncate",children:L}),t.jsx(de,{channel:b,participant:p}),D&&t.jsx("span",{className:"shrink-0",children:D})]}),a&&t.jsxs("div",{className:"flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[t.jsx(w.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),t.jsx("span",{children:yt})]})]}),t.jsxs("div",{className:"flex justify-end items-center gap-2",children:[n&&t.jsx("button",{className:ne,onClick:z,type:"button","aria-label":I?"Unstar conversation":"Star conversation",children:t.jsx(w.StarIcon,{className:C("size-5",{"text-yellow-600":I,"text-black/90":!I}),weight:I?"duotone":"regular"})}),g&&(c!==void 0?c:t.jsx(jt,{channel:b,participant:p,showDeleteConversation:o,showBlockParticipant:l,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:h,onBlockParticipantClick:f,onReportParticipantClick:u,customChannelActions:x,triggerClassName:C(ne,"bg-[#F1F0EE]")}))]})]}),t.jsxs("div",{className:"px-6 py-3 hidden @lg:flex items-center justify-between gap-3 min-h-12 border-b border-b-black/[0.08]",children:[t.jsxs("div",{className:"flex items-center gap-4 min-w-0",children:[s&&e&&t.jsx("button",{className:C(ne,"messaging-channel-view-back-button-desktop"),type:"button",onClick:e,"aria-label":"Back to conversations",children:t.jsx(w.ArrowLeftIcon,{className:"size-5 text-black/90"})}),t.jsx(te,{id:((M=p==null?void 0:p.user)==null?void 0:M.id)||b.id||"unknown",name:L,image:T,dmAgentEnabled:a,size:48}),t.jsxs("div",{className:"min-w-0",children:[N?t.jsxs("button",{type:"button",onClick:N,"aria-label":`View details for ${L}`,className:"flex min-w-0 max-w-full items-center gap-1 rounded font-medium text-black/90 transition-opacity hover:opacity-70",children:[t.jsx("span",{className:"min-w-0 truncate",children:L}),t.jsx(de,{channel:b,participant:p}),D&&t.jsx("span",{className:"shrink-0",children:D}),t.jsx(w.CaretRightIcon,{className:"size-4 shrink-0",weight:"bold"})]}):t.jsxs("h1",{className:"flex min-w-0 items-center gap-1 font-medium text-black/90",children:[t.jsx("span",{className:"min-w-0 truncate",children:L}),t.jsx(de,{channel:b,participant:p}),D&&t.jsx("span",{className:"shrink-0",children:D})]}),a&&t.jsxs("div",{className:"mt-0.5 flex items-center gap-1 text-[10px] leading-3 text-black/55",children:[t.jsx(w.SparkleIcon,{className:"size-3 shrink-0 text-black/55"}),t.jsx("span",{className:"truncate",children:yt})]})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[n&&t.jsx("button",{className:ne,onClick:z,type:"button","aria-label":I?"Unstar conversation":"Star conversation",children:t.jsx(w.StarIcon,{className:C("size-6",{"text-yellow-600":I,"text-black/90":!I}),weight:I?"duotone":"regular"})}),g&&(c!==void 0?c:t.jsx(jt,{channel:b,participant:p,showDeleteConversation:o,showBlockParticipant:l,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:h,onBlockParticipantClick:f,onReportParticipantClick:u,customChannelActions:x,triggerClassName:ne}))]})]})]})},kn=({onBack:e,showBackButton:s,renderMessageInputActions:n,renderMessageInputFooter:a,renderConversationFooter:r,onLeaveConversation:i,onBlockParticipant:o,showDeleteConversation:l=!0,onDeleteConversationClick:d,onBlockParticipantClick:h,onReportParticipantClick:f,showBlockParticipant:u=!0,showReportParticipant:x=!0,composerDisabled:c=!1,composerDisabledReason:g,showStarButton:N=!1,chatbotVotingEnabled:v=!1,renderChannelBanner:b,renderHeaderTitleBadges:p,customChannelActions:L,renderChannelActions:T,renderMessage:I,dmAgentEnabled:D=!1,viewerLanguage:z,showChannelInfo:y=!0,onParticipantNameClick:O})=>{var B,H,W,X,U,j;const{channel:k}=_.useChannelStateContext(),F=m.useMemo(()=>{var Y,G;const S=(Y=k._client)==null?void 0:Y.userID;return S?Object.values(((G=k.state)==null?void 0:G.members)||{}).find(V=>{var q;return((q=V.user)==null?void 0:q.id)&&V.user.id!==S}):void 0},[(B=k._client)==null?void 0:B.userID,(H=k.state)==null?void 0:H.members]),M=m.useMemo(()=>{var Y,G;const S=(Y=k._client)==null?void 0:Y.userID;return S?Object.values(((G=k.state)==null?void 0:G.members)||{}).find(V=>{var q;return((q=V.user)==null?void 0:q.id)===S}):void 0},[(W=k._client)==null?void 0:W.userID,(X=k.state)==null?void 0:X.members]),A=((U=M==null?void 0:M.user)==null?void 0:U.is_account)??(M==null?void 0:M.is_account),E=((j=F==null?void 0:F.user)==null?void 0:j.is_account)??(F==null?void 0:F.is_account),R=D&&A===!1&&E===!0,P=m.useCallback(S=>{const{message:$}=_.useMessageContext("ChannelView"),Y=t.jsx(tn,{...S,chatbotVotingEnabled:v,viewerLanguage:z});return!I||!$?Y:I(Y,$)},[v,I,z]);return t.jsx(t.Fragment,{children:t.jsx(_.WithComponents,{overrides:{Message:P,MessageActions:an},children:t.jsxs(_.Window,{children:[t.jsx("div",{children:t.jsx(Cn,{onBack:e,showBackButton:s,showChannelInfo:y,showStarButton:N,dmAgentEnabled:R,onLeaveConversation:i,onBlockParticipant:o,showDeleteConversation:l,showBlockParticipant:u,showReportParticipant:x,onDeleteConversationClick:d,onBlockParticipantClick:h,onReportParticipantClick:f,customChannelActions:L,renderChannelActions:T,onParticipantNameClick:O,renderHeaderTitleBadges:p})},"lt-channel-header"),b?t.jsx(m.Fragment,{children:b()},"lt-channel-banner"):null,t.jsx("div",{className:"flex-1 overflow-hidden relative",children:t.jsx(_.MessageList,{hideDeletedMessages:!0,hideNewMessageSeparator:!1})},"lt-channel-message-list"),r?t.jsx(m.Fragment,{children:r(k)},"lt-channel-conversation-footer"):null,t.jsx(un,{...n&&{renderActions:()=>n==null?void 0:n(k)},renderFooter:()=>a==null?void 0:a(k),disabled:c,disabledReason:g},"lt-channel-message-input")]})})})},Ue=m.memo(({channel:e,onBack:s,showBackButton:n=!1,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:o,onBlockParticipant:l,className:d,CustomChannelEmptyState:h=Gt,showDeleteConversation:f=!0,onDeleteConversationClick:u,onBlockParticipantClick:x,onReportParticipantClick:c,showBlockParticipant:g=!0,showReportParticipant:N=!0,composerDisabled:v=!1,composerDisabledReason:b,dmAgentEnabled:p,messageMetadata:L,onMessageSent:T,showStarButton:I=!1,chatbotVotingEnabled:D=!1,renderChannelBanner:z,renderHeaderTitleBadges:y,customChannelActions:O,renderChannelActions:k,renderMessage:F,onMessageLinkClick:M,sendButton:A,attachmentPreviewList:E,viewerLanguage:R,showChannelInfo:P=!0,onParticipantNameClick:B})=>{const H=m.useCallback(async(X,U,j)=>{var q;const S=((q=e.data)==null?void 0:q.chatbot_paused)===!0,$=p&&!S,Y={...U,...$&&{silent:!0},...L&&{metadata:{...U.metadata??{},...L}}},G={...j,...$&&{skip_push:!0}},V=await e.sendMessage(Y,G);return T==null||T(V),V},[e,p,L,T]),W=m.useRef(null);return m.useEffect(()=>{if(!M)return;const X=W.current;if(!X)return;const U=j=>{const S=j.target,$=S==null?void 0:S.closest("a[href]"),Y=$==null?void 0:$.getAttribute("href");if(!Y)return;const G=$==null?void 0:$.closest("[data-message-id]"),V=G==null?void 0:G.getAttribute("data-message-id"),q=V?e.state.messages.find(re=>re.id===V):void 0;M(Y,q)};return X.addEventListener("click",U),()=>X.removeEventListener("click",U)},[M,e]),t.jsx("div",{ref:W,className:C("messaging-channel-view h-full flex flex-col",d),children:t.jsx(Vt.Provider,{value:p??!1,children:t.jsx(_.Channel,{channel:e,MessageSystem:jn,EmptyStateIndicator:h,LoadingIndicator:pe,DateSeparator:vs,TypingIndicator:Nn,doSendMessageRequest:H,...A?{SendButton:A}:{},...E?{AttachmentPreviewList:E}:{},children:t.jsx(kn,{onBack:s,showBackButton:n,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:o,onBlockParticipant:l,CustomChannelEmptyState:h,showDeleteConversation:f,onDeleteConversationClick:u,onBlockParticipantClick:x,onReportParticipantClick:c,showBlockParticipant:g,showReportParticipant:N,composerDisabled:v,composerDisabledReason:b,showStarButton:I,dmAgentEnabled:p,chatbotVotingEnabled:D,renderChannelBanner:z,renderHeaderTitleBadges:y,customChannelActions:O,renderChannelActions:k,renderMessage:F,viewerLanguage:R,showChannelInfo:P,onParticipantNameClick:B})})})})});Ue.displayName="ChannelView";const ue=m.memo(({message:e,onBack:s})=>t.jsx("div",{className:"messaging-error-state flex items-center justify-center h-full p-8",children:t.jsxs("div",{className:"text-center max-w-sm",children:[t.jsx("div",{className:"w-24 h-24 bg-danger-alt/20 rounded-full flex items-center justify-center mx-auto mb-6",children:t.jsx("span",{className:"text-4xl",children:"⚠️"})}),t.jsx("h2",{className:"font-semibold text-charcoal mb-2",children:"Oops!"}),t.jsx("p",{className:"text-stone text-sm mb-6",children:e}),s&&t.jsx("button",{type:"button",onClick:s,className:"inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-[#7f22fe] hover:bg-primary-alt rounded-lg transition-colors focus-ring",children:"Go Back"})]})}));ue.displayName="ErrorState";const Sn=({capabilities:e={},renderMessageInputActions:s,renderConversationFooter:n,onChannelSelect:a,onExitConversation:r,initialParticipantFilter:i,initialParticipantData:o,CustomChannelEmptyState:l,onBlockParticipantClick:d,onReportParticipantClick:h,dmAgentEnabled:f,onMessageSent:u,chatbotVotingEnabled:x=!1,viewerLanguage:c,renderHeaderTitleBadges:g,renderChannelBanner:N,customChannelActions:v,renderChannelActions:b,onParticipantNameClick:p,renderMessage:L,onMessageLinkClick:T,showChannelInfo:I})=>{const{client:D,isConnected:z,isLoading:y,error:O,refreshConnection:k,service:F,debug:M}=kt(),[A,E]=m.useState(null),[R,P]=m.useState(null),[B,H]=m.useState(!1),{showDeleteConversation:W=!0}=e,X=m.useRef(o);X.current=o;const U=m.useRef(a);U.current=a;const j=m.useRef(null),S=m.useRef(null);m.useEffect(()=>{S.current=A},[A]),m.useEffect(()=>{if(!D||!z)return;const G=D.userID;if(!G)return;const V=`${G}::${i}`;if(j.current===V)return;j.current=V;const q=()=>{j.current===V&&(j.current=null)};(async()=>{var ie,oe;try{M&&console.log("[MessagingShell] Loading initial conversation with:",i);const Z=await D.queryChannels({type:"messaging",members:{$eq:[G,i]}},{},{limit:1});if(Z.length>0){E(Z[0]),P(null),(ie=U.current)==null||ie.call(U,Z[0]),M&&console.log("[MessagingShell] Initial conversation loaded:",Z[0].id);return}const K=X.current;if(!K||!F){q(),P("No conversation found with this account"),M&&console.log("[MessagingShell] No conversation found for:",i);return}try{const J=await F.startChannelWithParticipant({id:K.id,name:K.name,phone:K.phone});E(J),P(null),(oe=U.current)==null||oe.call(U,J),M&&console.log("[MessagingShell] Channel created and loaded:",J.id)}catch(J){console.error("[MessagingShell] Failed to create conversation:",J),q(),P("Failed to create conversation")}}catch(Z){console.error("[MessagingShell] Failed to load initial conversation:",Z),q(),S.current||P("Failed to load conversation")}})()},[i,D,z,F,M]);const $=m.useRef(r);$.current=r;const Y=m.useCallback(()=>{var G;E(null),H(!0),(G=$.current)==null||G.call($)},[]);return y?t.jsx(pe,{}):O?t.jsx(ue,{message:O,onBack:k}):!z||!D?t.jsx(ue,{message:"Not connected to messaging service",onBack:k}):R?t.jsx(ue,{message:R}):B&&!A?t.jsx(ue,{message:"Conversation ended"}):A?t.jsx("div",{className:"messaging-shell h-full bg-background-primary overflow-hidden",children:t.jsx("div",{className:"flex h-full min-h-0 flex-col",children:t.jsx(Ue,{channel:A,renderMessageInputActions:s,renderConversationFooter:n,renderChannelBanner:N,onLeaveConversation:Y,onBlockParticipant:Y,CustomChannelEmptyState:l,showDeleteConversation:W,onBlockParticipantClick:d,onReportParticipantClick:h,dmAgentEnabled:f,onMessageSent:u,chatbotVotingEnabled:x,viewerLanguage:c,renderHeaderTitleBadges:g,customChannelActions:v,renderChannelActions:b,onParticipantNameClick:p,renderMessage:L,onMessageLinkClick:T,showChannelInfo:I},A.id)})}):t.jsx(pe,{})};function In(e){const s=e.state.pending_messages;if(s!=null&&s.length)for(const n of s)e.state.addMessageSorted(n.message)}const Ht=m.createContext({selectedChannel:void 0,onChannelSelect:()=>{},debug:!1,renderMessagePreview:void 0,viewerLanguage:void 0}),En=Ht.Provider,Tn=()=>m.useContext(Ht),Mn=(e,s)=>{const n=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())),r=new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth(),s.getUTCDate())).getTime()-n.getTime();return Math.floor(r/(1e3*60*60*24))},Yt=e=>{const s=new Date;if(Math.floor((s.getTime()-e.getTime())/1e3)<60)return"Just now";const a=Mn(e,s);return a===0?e.toLocaleTimeString([],{hour:"numeric",minute:"2-digit",hour12:!0}):a===1?"Yesterday":a<7?`${a}d`:a<28?`${Math.floor(a/7)}w`:e.toLocaleDateString("en-US",{month:"numeric",day:"numeric",year:"2-digit"})},qt=m.memo(({channel:e,unread:s})=>{var I,D,z;const{selectedChannel:n,onChannelSelect:a,debug:r,renderMessagePreview:i,viewerLanguage:o}=Tn(),l=(n==null?void 0:n.id)===(e==null?void 0:e.id),d=()=>{e&&a(e)},h=y=>{const O=y.key==="Enter"||y.key===" ",k=y.repeat;!O||k||(y.preventDefault(),d())},u=Object.values(((I=e==null?void 0:e.state)==null?void 0:I.members)||{}).find(y=>{var O,k;return((O=y.user)==null?void 0:O.id)&&y.user.id!==((k=e==null?void 0:e._client)==null?void 0:k.userID)}),x=De(u==null?void 0:u.user),c=(D=u==null?void 0:u.user)==null?void 0:D.image,g=(()=>{var O;const y=(O=e==null?void 0:e.state)==null?void 0:O.messages;if(y!=null&&y.length){for(let k=y.length-1;k>=0;k--)if(y[k].type!=="system")return y[k]}})(),v=(()=>{var A,E,R,P;const y=Pe({message:g,viewerLanguage:o});if(((A=g==null?void 0:g.metadata)==null?void 0:A.custom_type)==="MESSAGE_TIP")return y?`💵 ${y}`:"💵 Sent a tip";if(((E=g==null?void 0:g.metadata)==null?void 0:E.custom_type)==="MESSAGE_PAID")return y?`💰 ${y}`:"💰 Sent a message";if(((R=g==null?void 0:g.metadata)==null?void 0:R.custom_type)==="MESSAGE_ATTACHMENT")return y?`📎 ${y}`:"📎 Sent an attachment";if(y)return y;const M=(P=g==null?void 0:g.attachments)==null?void 0:P[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"})(),b=g!=null&&g.created_at?Yt(new Date(g.created_at)):"",p=g?be(g):!1,L=i?i(g,v):`${p?"✨ ":""}${v}`,T=s??0;return r&&console.log("📺 [ChannelList] 📋 CHANNEL PREVIEW RENDER",{channelId:e==null?void 0:e.id,isSelected:l,participantName:x,unreadCount:T,hasTimestamp:!!b}),t.jsx("div",{role:"button",tabIndex:0,onClick:d,onKeyDown:h,className:C("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]":l,"hover:bg-black/[0.02]":!l}),children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx(te,{id:((z=u==null?void 0:u.user)==null?void 0:z.id)||e.id||"unknown",name:x,image:c,size:48}),t.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsxs("h3",{className:"flex min-w-0 items-center gap-1 text-sm font-medium text-[#191918]",children:[t.jsx("span",{className:"min-w-0 truncate",children:x}),t.jsx(de,{channel:e,participant:u})]}),b&&t.jsx("span",{className:"text-xs text-[#717070] flex-shrink-0",children:b})]}),t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[t.jsx("p",{className:"text-sm text-[#717070] flex-1 line-clamp-1",children:L}),T>0&&t.jsx("span",{className:"bg-[#7f22fe] text-white text-[10px] rounded-full h-4 flex items-center justify-center p-1 min-w-4 text-center flex-shrink-0",children:T>99?"99+":T})]})]})]})})});qt.displayName="CustomChannelPreview";const An={last_message_at:-1},Xt=m.memo(({onChannelSelect:e,selectedChannel:s,filters:n,allowNewMessagesFromUnfilteredChannels:a=!1,channelRenderFilterFn:r,sort:i=An,className:o,customEmptyStateIndicator:l,renderMessagePreview:d,viewerLanguage:h})=>{const f=m.useRef(0);f.current++;const{debug:u=!1}=Le(),x=m.useCallback(g=>{for(const N of g)In(N);return r?r(g):g},[r]);u&&console.log("📺 [ChannelList] 🔄 RENDER START",{renderCount:f.current,selectedChannelId:s==null?void 0:s.id,filters:n});const c=m.useMemo(()=>({selectedChannel:s,onChannelSelect:e,debug:u,renderMessagePreview:d,viewerLanguage:h}),[s,e,u,d,h]);return t.jsx("div",{className:C("messaging-channel-list h-full flex flex-col min-w-0 overflow-hidden",o),children:t.jsx("div",{className:"flex-1 overflow-hidden min-w-0",children:t.jsx(En,{value:c,children:t.jsx(_.ChannelList,{filters:n,sort:i,options:{limit:30},allowNewMessagesFromUnfilteredChannels:a,channelRenderFilterFn:x,Paginator:_.InfiniteScroll,Preview:qt,EmptyStateIndicator:l},`${JSON.stringify(n)}:${JSON.stringify(i)}`)})})})});Xt.displayName="ChannelList";const Rn=/^([a-z][a-z0-9+.-]*):/i,Ln=new Set(["http","https","mailto","tel","sms"]);function Ve(e){if(typeof e!="string")return;const s=e.trim();if(s==="")return;const n=Rn.exec(s);if(n){const a=n[1].toLowerCase();return Ln.has(a)?s:void 0}return s.startsWith("//")||s.startsWith("/")?s:`https://${s}`}const Dn={dark:"bg-white text-[#121110] hover:bg-white/90",light:"bg-[#121110] text-white hover:bg-[#2a2928]"},Pn=({variant:e,cta:s})=>{const n=C("mt-2 inline-flex h-10 w-full items-center justify-center rounded-full px-4 text-sm font-medium leading-none transition-colors",Dn[e]),a=Ve(s.href);return a?t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",onClick:r=>{var i;r.stopPropagation(),(i=s.onClick)==null||i.call(s)},className:`${n} no-underline`,children:s.label}):t.jsx("button",{type:"button",onClick:r=>{var i;r.stopPropagation(),(i=s.onClick)==null||i.call(s)},className:n,children:s.label})},zn={dark:"text-white",light:"text-black/90"},On="text-white/30",Fn={dark:"text-white/55",light:"text-black/55"},Ge=({variant:e,title:s,placeholderTitle:n,description:a,url:r,appIcon:i,cta:o,trailingAction:l})=>{const d=e==="dark",h=s??(d?n:void 0)??"",f=h.trim()!=="",u=a!=null&&a.trim()!=="",x=typeof r=="string"?r.trim():"",c=x!=="",g=o!=null;if(!f&&!u&&!c&&!g)return null;const v=C("truncate text-base font-medium leading-6",d&&!s?On:zn[e]),b=C("truncate text-xs leading-4",Fn[e]);return t.jsxs("div",{className:"px-4 py-3",children:[t.jsxs("div",{className:"flex items-end gap-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[t.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[f&&t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i?t.jsx("span",{className:"shrink-0",children:i}):null,t.jsx("p",{className:C("min-w-0",v),children:h})]}),u&&t.jsx("p",{className:b,children:a})]}),!g&&c&&t.jsx("p",{className:b,children:x})]}),l&&t.jsx("div",{className:"shrink-0",children:l})]}),o&&t.jsx(Pn,{variant:e,cta:o})]})},$n=C("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)]"),ve=({variant:e,children:s,href:n,onClick:a,ariaLabel:r,rootRef:i,topRight:o,bgClassName:l,"data-testid":d})=>{const h=n!=null||a!=null,f=C($n,l??(e==="dark"?"bg-[#121110]":"bg-white"),h?"cursor-pointer no-underline focus-ring":null),u=o?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-10",children:o}):null;return n?t.jsxs("a",{ref:i,href:n,target:"_blank",rel:"noopener noreferrer",onClick:a,"data-testid":d,className:f,children:[s,u]}):a?t.jsxs("button",{ref:i,type:"button",onClick:a,"aria-label":r,"data-testid":d,className:C(f,"text-left"),children:[s,u]}):t.jsxs("div",{ref:i,"data-testid":d,className:f,children:[s,u]})},Bn={dark:"bg-white/10",light:"bg-black/5"},Un={dark:"size-16 text-white/25",light:"size-16 text-black/25"},_e=(e,s)=>!!s&&!!e&&ee(e)==="audio",Wt=(e,s)=>{if(!s||!e)return!1;const n=ee(e);return n==="video"||n==="audio"},He="bg-[#F2F3F4]",je=({variant:e,thumbnailUrl:s,sourceUrl:n,title:a,mimeType:r="image/*",topLeft:i,topRight:o})=>{const l=ee(r),d=!!n&&l==="video";return _e(r,n)?t.jsx("div",{className:"p-3",children:t.jsx("audio",{src:n,controls:!0,preload:"metadata",className:"block w-full",children:t.jsx("track",{kind:"captions"})})}):t.jsxs("div",{className:C("relative h-[180px] w-full overflow-hidden",d&&"bg-black"),children:[d?t.jsx("video",{src:n,poster:s,controls:!0,playsInline:!0,preload:"metadata",className:"absolute inset-0 h-full w-full object-contain",children:t.jsx("track",{kind:"captions"})}):s?t.jsx("img",{src:s,alt:a??"",draggable:!1,className:"absolute inset-0 h-full w-full object-cover"}):t.jsx("div",{className:C("flex h-full w-full items-center justify-center",Bn[e]),children:se(r,{className:Un[e],weight:"regular"})}),i?t.jsx("div",{className:"pointer-events-auto absolute left-3 top-3 z-10",children:i}):null,o?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-10",children:o}):null]})},Vn=({title:e,placeholderTitle:s,description:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:o,layout:l="featured",appIcon:d,cta:h,onDismiss:f,onEditClick:u})=>{const x=l==="classic",c=_e(r,o),g=f?t.jsx("button",{type:"button",onClick:f,"aria-label":"Dismiss attachment",className:"flex size-6 items-center justify-center rounded-full bg-[#121110] text-white",children:t.jsx(w.XIcon,{className:"size-3",weight:"bold"})}):void 0,N=u?t.jsx("button",{type:"button",onClick:u,"aria-label":"Edit attachment",className:"flex size-10 items-center justify-center rounded-full bg-white/10 text-white hover:bg-white/15",children:t.jsx(w.PencilSimpleIcon,{className:"size-5",weight:"regular"})}):void 0;return c?t.jsx(ve,{variant:"dark",bgClassName:He,children:t.jsxs("div",{className:"flex items-center gap-2 pr-3",children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsx(je,{variant:"dark",sourceUrl:o,title:e,mimeType:r})}),g&&t.jsx("div",{className:"shrink-0",children:g})]})}):t.jsxs(ve,{variant:"dark",topRight:x?g:void 0,children:[!x&&t.jsx(je,{variant:"dark",thumbnailUrl:i,sourceUrl:o,title:e,mimeType:r,topRight:g}),t.jsx(Ge,{variant:"dark",title:e,placeholderTitle:s,description:n,url:a,appIcon:d,cta:h,trailingAction:N})]})},Gn=({title:e,description:s,url:n,mimeType:a,thumbnailUrl:r,sourceUrl:i,layout:o="featured",appIcon:l,cta:d,onClick:h})=>{const f=Wt(a,i),u=Ve(n),x=d==null&&u!=null&&!f?u:void 0,c=d==null&&!f?h:void 0,g=_e(a,i)?He:void 0,N=d&&h?{...d,onClick:()=>{var v;h(),(v=d.onClick)==null||v.call(d)}}:d;return t.jsxs(ve,{variant:"light",href:x,onClick:c,ariaLabel:e??"Open attachment preview",bgClassName:g,"data-testid":"link-attachment",children:[o==="featured"&&t.jsx(je,{variant:"light",thumbnailUrl:r,sourceUrl:i,title:e,mimeType:a}),t.jsx(Ge,{variant:"light",title:e,description:s,url:n,appIcon:l,cta:N})]})},Hn=({title:e,placeholderTitle:s,description:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:o,layout:l="featured",appIcon:d,cta:h,onClick:f})=>{const u=Wt(r,o),x=Ve(a),c=h==null&&x!=null&&!u?x:void 0,g=h==null&&!u&&c!=null?f:void 0;return t.jsxs(ve,{variant:"dark",href:c,onClick:g,bgClassName:_e(r,o)?He:void 0,children:[l==="featured"&&t.jsx(je,{variant:"dark",thumbnailUrl:i,sourceUrl:o,title:e,mimeType:r}),t.jsx(Ge,{variant:"dark",title:e,placeholderTitle:s,description:n,url:a,appIcon:d,cta:h})]})},Yn={Composer:Vn,Sent:Hn,Received:Gn},qn={dark:"bg-[#121110]",light:"bg-[#e9eaed]"},Xn={dark:"text-white",light:"text-[#080707]"},Wn={dark:"border-white/[0.08]",light:"border-black/[0.08]"},Kn=e=>e==="dark"?"sender":"receiver",Jn={sender:{single:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]",first:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[4px]",middle:"rounded-tl-[18px] rounded-tr-[4px] rounded-bl-[18px] rounded-br-[4px]",end:"rounded-tl-[18px] rounded-tr-[4px] rounded-bl-[18px] rounded-br-[18px]"},receiver:{single:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]",first:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[4px] rounded-br-[18px]",middle:"rounded-tl-[4px] rounded-tr-[18px] rounded-bl-[4px] rounded-br-[18px]",end:"rounded-tl-[4px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]"}},me=({variant:e,text:s,bordered:n=!0,groupPosition:a="single",className:r,children:i,"data-testid":o})=>{const l=s!=null&&s!=="",d=Jn[Kn(e)][a];return t.jsxs("div",{"data-testid":o,"data-group-position":a,className:C("relative w-[280px] overflow-hidden px-2 py-2",d,qn[e],Xn[e],n&&"border",n&&Wn[e],r),children:[i,l?t.jsx("p",{className:C("whitespace-pre-wrap break-words leading-snug","pt-2","px-2"),children:s}):null]})},he=({onClick:e,variant:s="overlay",ariaLabel:n="Dismiss attachment"})=>t.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),e()},"aria-label":n,className:C("flex size-6 items-center justify-center rounded-full text-white",s==="overlay"?"bg-[#121110]/85 backdrop-blur":"bg-white/15 hover:bg-white/25"),children:t.jsx(w.XIcon,{className:"size-3",weight:"bold"})}),xe=e=>e==="received"?"light":"dark",Zn=({firstOfGroup:e,endOfGroup:s,groupedByUser:n})=>!n||e&&s?"single":e?"first":s?"end":"middle",Qn=({src:e,mimeType:s,filename:n,items:a})=>a&&a.length>0?a:e?[{src:e,mimeType:s,filename:n}]:[],ea=({item:e,preload:s,trailingAction:n})=>t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("audio",{src:e.src,controls:!0,preload:e.preload??s,className:"block min-w-0 flex-1",children:e.mimeType?t.jsx("source",{src:e.src,type:e.mimeType}):null}),n??null]}),Ye=({state:e,src:s,mimeType:n,filename:a,items:r,text:i,groupPosition:o,preload:l,onDismiss:d})=>{const h=xe(e),f=e==="composer"&&!!d,u=Qn({src:s,mimeType:n,filename:a,items:r});if(u.length===0)return null;const x=l??(u.length>1?"none":"metadata");return t.jsx(me,{variant:h,text:i,groupPosition:o,"data-testid":"audio-attachment",children:t.jsx("div",{className:"flex flex-col gap-2",children:u.map((c,g)=>t.jsx(ea,{item:c,preload:x,trailingAction:f&&g===0?t.jsx(he,{onClick:d,variant:"inline"}):void 0},`${c.src}-${g}`))})})},ta=e=>t.jsx(Ye,{...e,state:"composer"}),sa=e=>t.jsx(Ye,{...e,state:"sent"}),na=e=>t.jsx(Ye,{...e,state:"received"}),aa={Composer:ta,Sent:sa,Received:na};function Kt(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 ra={pdf:"PDF",doc:"DOC",xls:"XLS",csv:"CSV",ppt:"PPT",zip:"ZIP",text:"TXT",markdown:"MD"};function Jt(e,s){if(s){const r=s.lastIndexOf(".");if(r>0&&r<s.length-1){const i=s.slice(r+1);if(i&&i.length<=5)return i.toUpperCase()}}if(!e)return;if(ee(e)==="document"){const r=Rt(e),i=ra[r];if(i)return i;if(e==="application/octet-stream")return}const a=e.split("/")[1];if(!(!a||a==="*"))return a.toUpperCase()}function Zt(e,s,n){const a=Jt(e,s),r=typeof n=="number"&&n>0?Kt(n):void 0;return[a,r].filter(Boolean).join(" · ")||void 0}function Q(e){try{const n=new URL(e).pathname.split("/").pop();return n&&n.length>0?decodeURIComponent(n):"download"}catch{return"download"}}const ia={dark:"text-white/55",light:"text-black/65"},oa={dark:"bg-white/10",light:"bg-black/5"},la={dark:"text-white/85",light:"text-black/85"},Qt=({variant:e,filename:s,title:n,mimeType:a="application/octet-stream",fileSize:r,onActivate:i,activateLabel:o,trailingAction:l})=>{const d=n??s??"File",h=Zt(a,s,r),f=t.jsx("div",{className:C("flex size-10 shrink-0 items-center justify-center rounded-sm",oa[e]),"aria-hidden":!0,children:se(a,{className:C("size-6",la[e]),weight:"regular"})}),u=t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col text-left",children:[t.jsx("p",{className:"truncate font-medium leading-snug",children:d}),h?t.jsx("p",{className:C("truncate text-xs leading-4",ia[e]),children:h}):null]}),x=i?t.jsxs("button",{type:"button",onClick:i,"aria-label":o,className:C("flex min-w-0 flex-1 items-center gap-3 rounded-sm text-left transition-colors",e==="dark"?"hover:bg-white/[0.04]":"hover:bg-black/[0.04]"),children:[f,u]}):t.jsxs(t.Fragment,{children:[f,u]});return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[x,l?t.jsx("div",{className:"shrink-0",children:l}):null]})};async function es(e,s){const n=s??Q(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 ca=({src:e,filename:s,fileSize:n,mimeType:a,title:r,items:i})=>i&&i.length>0?i:e?[{src:e,filename:s,fileSize:n,mimeType:a,title:r}]:[],da=({variant:e,item:s,index:n,onActivate:a,trailingAction:r})=>{const i=s.filename??Q(s.src);return t.jsx(Qt,{variant:e,filename:i,title:s.title,mimeType:s.mimeType??"application/octet-stream",fileSize:s.fileSize,onActivate:()=>a(n),activateLabel:`Download ${i}`,trailingAction:r})},qe=({state:e,src:s,filename:n,fileSize:a,mimeType:r,title:i,items:o,text:l,groupPosition:d,onClick:h,onDismiss:f})=>{const u=xe(e),x=e==="composer"&&!!f,c=ca({src:s,filename:n,fileSize:a,mimeType:r,title:i,items:o}),g=v=>{if((h==null?void 0:h(v))===!1)return;const b=c[v];if(!b)return;const p=b.filename??Q(b.src);es(b.src,p)};if(c.length===0)return null;const N=t.jsx("span",{className:C("flex size-8 items-center justify-center rounded-full",u==="dark"?"text-white/70":"text-black/70"),"aria-hidden":!0,children:t.jsx(w.DownloadSimpleIcon,{className:"size-5",weight:"bold"})});return t.jsx(me,{variant:u,text:l,groupPosition:d,"data-testid":"file-attachment",children:t.jsx("div",{className:"flex flex-col gap-2",children:c.map((v,b)=>{const p=x&&b===0?t.jsx(he,{onClick:f,variant:"inline"}):N;return t.jsx(da,{variant:u,item:v,index:b,onActivate:g,trailingAction:p},`${v.src}-${b}`)})})})},ua=e=>t.jsx(qe,{...e,state:"composer"}),ma=e=>t.jsx(qe,{...e,state:"sent"}),ha=e=>t.jsx(qe,{...e,state:"received"}),xa={Composer:ua,Sent:ma,Received:ha},Xe=({onPrev:e,onNext:s,prevLabel:n="Previous",nextLabel:a="Next"})=>t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:e,"aria-label":n,className:"mes-media-viewer__nav mes-media-viewer__nav--prev",children:t.jsx(w.CaretLeftIcon,{size:20,weight:"bold","aria-hidden":!0})}),t.jsx("button",{type:"button",onClick:s,"aria-label":a,className:"mes-media-viewer__nav mes-media-viewer__nav--next",children:t.jsx(w.CaretRightIcon,{size:20,weight:"bold","aria-hidden":!0})})]}),ts=({url:e,filename:s,variant:n="pill",label:a="Download",iconOnly:r,tone:i="dark",onTriggered:o})=>{const[l,d]=m.useState(!1),h=m.useCallback(c=>{c.stopPropagation(),!l&&(d(!0),es(e,s).catch(()=>{}).finally(()=>{d(!1),o==null||o()}))},[l,e,s,o]),f=r??n!=="pill",x={className:C(n==="pill"?"size-4":"size-5","shrink-0"),weight:"bold"};if(n==="inline"){const c={dark:"text-white/70 hover:bg-white/[0.08] hover:text-white",light:"text-black/70 hover:bg-black/[0.08] hover:text-black"};return t.jsx("button",{type:"button",onClick:h,disabled:l,"aria-label":a,className:C("flex size-8 shrink-0 items-center justify-center rounded-full transition-colors disabled:opacity-70",c[i]),children:l?t.jsx(w.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):t.jsx(w.DownloadSimpleIcon,{className:"size-5 shrink-0",weight:"bold","aria-hidden":!0})})}return n==="viewer"?t.jsx("button",{type:"button",onClick:h,disabled:l,"aria-label":a,className:"mes-media-viewer__action",children:l?t.jsx(w.CircleNotchIcon,{size:20,weight:"bold","aria-hidden":!0}):t.jsx(w.DownloadSimpleIcon,{size:20,weight:"bold","aria-hidden":!0})}):t.jsxs("button",{type:"button",onClick:h,disabled:l,"aria-label":f?a:void 0,className:C("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?t.jsx(w.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):t.jsx(w.DownloadSimpleIcon,{...x,"aria-hidden":!0}),f?null:a]})},Ie=(e,s,n)=>Math.min(Math.max(e,s),n),We=({length:e,initialIndex:s,open:n})=>{const a=Ie(s,0,Math.max(e-1,0)),[r,i]=m.useState(a);m.useEffect(()=>{n&&i(Ie(s,0,Math.max(e-1,0)))},[n,s,e]),m.useEffect(()=>{i(d=>Ie(d,0,Math.max(e-1,0)))},[e]);const o=m.useCallback(()=>{e<=1||i(d=>d<=0?e-1:d-1)},[e]),l=m.useCallback(()=>{e<=1||i(d=>d>=e-1?0:d+1)},[e]);return m.useEffect(()=>{if(!n||e<=1)return;const d=h=>{if(h.key!=="ArrowLeft"&&h.key!=="ArrowRight")return;const f=document.activeElement;f&&(f.tagName==="VIDEO"||f.tagName==="AUDIO")||(h.preventDefault(),h.key==="ArrowLeft"?o():l())};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n,e,o,l]),{index:r,prev:o,next:l}},Ke=({open:e,onClose:s,ariaLabel:n,counter:a,actions:r,children:i,"data-testid":o})=>{const l=m.useRef(null),d=m.useRef(null);m.useEffect(()=>{var x;const u=l.current;if(u){if(e){if(!u.open)if(typeof u.showModal=="function")try{u.showModal()}catch{u.setAttribute("open","")}else u.setAttribute("open","");const c=typeof document<"u"?document.activeElement:null;return(x=d.current)==null||x.focus(),()=>{if(u.open)if(typeof u.close=="function")try{u.close()}catch{u.removeAttribute("open")}else u.removeAttribute("open");c&&document.body.contains(c)&&c.focus()}}if(u.open)if(typeof u.close=="function")try{u.close()}catch{u.removeAttribute("open")}else u.removeAttribute("open")}},[e]);const h=()=>{s()},f=u=>{u.target===l.current&&s()};return t.jsxs("dialog",{ref:l,className:"mes-media-viewer","aria-label":n??"Attachment viewer","data-testid":o,onClose:h,onClick:f,children:[t.jsxs("div",{className:"mes-media-viewer__chrome",children:[a?t.jsx("span",{className:"mes-media-viewer__counter",children:a}):null,t.jsxs("div",{className:"mes-media-viewer__actions",children:[r,t.jsx("button",{ref:d,type:"button",onClick:s,"aria-label":"Close viewer",className:"mes-media-viewer__action",children:t.jsx(w.XIcon,{size:20,weight:"bold","aria-hidden":!0})})]})]}),t.jsx("div",{className:"mes-media-viewer__body",children:i})]})},ss=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:o}=We({length:s.length,initialIndex:n,open:e}),l=s[r],d=m.useMemo(()=>(l==null?void 0:l.filename)??(l?Q(l.src):"image"),[l]);return l?t.jsxs(Ke,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,actions:t.jsx(ts,{url:l.src,filename:d,variant:"viewer",label:`Download ${d}`}),"data-testid":"image-viewer",children:[t.jsx("img",{src:l.src,alt:l.alt??d,draggable:!1,loading:"eager",decoding:"async",className:"mes-media-viewer__image"},`${r}:${l.src}`),s.length>1?t.jsx(Xe,{onPrev:i,onNext:o,prevLabel:"Previous image",nextLabel:"Next image"}):null]}):null},fa="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",ns=({tiles:e,onTileActivate:s,maxVisible:n=4,className:a})=>{const r=e.length;if(r===0)return null;const i=e.slice(0,Math.min(r,n)),o=r-i.length,l=(d,h,f)=>{const u=C(fa,"h-full w-full");return s?t.jsxs("button",{type:"button",onClick:()=>s(h),"aria-label":d.ariaLabel??`Open media ${h+1}`,className:C(u,"cursor-zoom-in"),children:[d.content,f]},h):t.jsxs("div",{className:u,children:[d.content,f]},h)};return i.length===1?t.jsx("div",{className:C("aspect-square w-full",a),children:l(i[0],0)}):i.length===2?t.jsx("div",{className:C("grid aspect-[16/9] w-full grid-cols-2 gap-0.5",a),children:i.map((d,h)=>l(d,h))}):i.length===3?t.jsxs("div",{className:C("grid aspect-[4/3] w-full grid-cols-2 grid-rows-2 gap-0.5",a),children:[t.jsx("div",{className:"row-span-2",children:l(i[0],0)}),l(i[1],1),l(i[2],2)]}):t.jsx("div",{className:C("grid aspect-[4/3] w-full grid-cols-2 grid-rows-2 gap-0.5",a),children:i.map((d,h)=>{const f=o>0&&h===i.length-1;return l(d,h,f?t.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-black/55 text-2xl font-semibold text-white",children:["+",o]}):null)})})},fe=e=>{const[s,n]=m.useState(!1),[a,r]=m.useState(0),i=m.useCallback(l=>{(e==null?void 0:e(l))!==!1&&(r(l),n(!0))},[e]),o=m.useCallback(()=>n(!1),[]);return{viewerOpen:s,viewerIndex:a,handleActivate:i,closeViewer:o}},ga=(e,s,n,a)=>({ariaLabel:`Open image ${s+1} of ${n}`,content:t.jsx("img",{src:e.src,alt:e.alt??"",width:e.width,height:e.height,draggable:!1,loading:e.loading??a,decoding:"async",className:"absolute inset-0 size-full rounded-md object-cover"})}),ba=({src:e,alt:s,items:n})=>n&&n.length>0?n:e?[{src:e,alt:s}]:[],as=(e,s)=>e.map((n,a)=>({src:n.src,alt:n.alt,filename:s&&e.length===1?s:s?`${s} (${a+1})`:void 0})),pa=({src:e,alt:s,filename:n,loading:a="lazy",onClick:r,onDismiss:i})=>{const{viewerOpen:o,viewerIndex:l,handleActivate:d,closeViewer:h}=fe(r);return t.jsxs("div",{className:"relative w-fit",children:[t.jsx("button",{type:"button",onClick:()=>d(0),"aria-label":"Open image",className:"block size-[280px] cursor-zoom-in overflow-hidden rounded-md outline-none focus-visible:ring-2 focus-visible:ring-black/40",children:t.jsx("img",{src:e,alt:s??"",draggable:!1,loading:a,decoding:"async",className:"size-full object-cover"})}),i?t.jsx("div",{className:"absolute right-2 top-2 z-10",children:t.jsx(he,{onClick:i})}):null,t.jsx(ss,{open:o,items:as([{src:e,alt:s}],n),initialIndex:l,onClose:h})]})},rs=({state:e,src:s,alt:n,filename:a,items:r,text:i,groupPosition:o,loading:l="lazy",onClick:d})=>{const h=ba({src:s,alt:n,items:r}),f=xe(e),{viewerOpen:u,viewerIndex:x,handleActivate:c,closeViewer:g}=fe(d);if(h.length===0)return null;const N=h.map((v,b)=>ga(v,b,h.length,l));return t.jsxs(me,{variant:f,text:i,groupPosition:o,"data-testid":"image-attachment",children:[t.jsx("div",{className:"relative",children:t.jsx(ns,{tiles:N,onTileActivate:c})}),t.jsx(ss,{open:u,items:as(h,a),initialIndex:x,onClose:g})]})},va=e=>t.jsx(pa,{...e}),ja=e=>t.jsx(rs,{...e,state:"sent"}),wa=e=>t.jsx(rs,{...e,state:"received"}),Na={Composer:va,Sent:ja,Received:wa},_a=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:o}=We({length:s.length,initialIndex:n,open:e}),l=s[r],d=m.useMemo(()=>(l==null?void 0:l.filename)??(l?Q(l.src):"document"),[l]),h=m.useMemo(()=>l?ya(l.src):void 0,[l]);return!l||!h?null:t.jsxs(Ke,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,"data-testid":"pdf-viewer",children:[t.jsx("iframe",{src:h,title:d,className:"mes-media-viewer__iframe",sandbox:"allow-scripts allow-forms allow-popups allow-downloads"},`${r}:${l.src}`),s.length>1?t.jsx(Xe,{onPrev:i,onNext:o,prevLabel:"Previous document",nextLabel:"Next document"}):null]})},ya=e=>{const s=e.indexOf("#"),n=s===-1?e:e.slice(0,s),a=s===-1?"":e.slice(s+1),r=new URLSearchParams(a);return r.has("toolbar")||r.set("toolbar","0"),r.has("navpanes")||r.set("navpanes","0"),`${n}#${r.toString()}`},Ca=({src:e,filename:s,fileSize:n,title:a,items:r})=>r&&r.length>0?r:e?[{src:e,filename:s,fileSize:n,title:a}]:[],ka=({variant:e,item:s,index:n,onActivate:a,trailingAction:r})=>{const i=s.filename??Q(s.src);return t.jsx(Qt,{variant:e,filename:i,title:s.title,mimeType:"application/pdf",fileSize:s.fileSize,onActivate:()=>a(n),activateLabel:`Open ${i}`,trailingAction:r})},Je=({state:e,src:s,filename:n,fileSize:a,title:r,items:i,text:o,groupPosition:l,onClick:d,onDismiss:h})=>{const f=xe(e),u=Ca({src:s,filename:n,fileSize:a,title:r,items:i}),{viewerOpen:x,viewerIndex:c,handleActivate:g,closeViewer:N}=fe(d),v=e==="composer"&&!!h;if(u.length===0)return null;const b=u.map(p=>({src:p.src,filename:p.filename??Q(p.src)}));return t.jsxs(me,{variant:f,text:o,groupPosition:l,"data-testid":"pdf-attachment",children:[t.jsx("div",{className:"flex flex-col gap-2",children:u.map((p,L)=>{const T=p.filename??Q(p.src),I=v&&L===0?t.jsx(he,{onClick:h,variant:"inline"}):e==="composer"?void 0:t.jsx(ts,{url:p.src,filename:T,variant:"inline",label:`Download ${T}`,tone:f});return t.jsx(ka,{variant:f,item:p,index:L,onActivate:g,trailingAction:I},`${p.src}-${L}`)})}),t.jsx(_a,{open:x,items:b,initialIndex:c,onClose:N})]})},Sa=e=>t.jsx(Je,{...e,state:"composer"}),Ia=e=>t.jsx(Je,{...e,state:"sent"}),Ea=e=>t.jsx(Je,{...e,state:"received"}),Ta={Composer:Sa,Sent:Ia,Received:Ea},is=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:o}=We({length:s.length,initialIndex:n,open:e}),l=s[r],d=m.useMemo(()=>(l==null?void 0:l.filename)??(l?Q(l.src):"video"),[l]);return l?t.jsxs(Ke,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,"data-testid":"video-viewer",children:[t.jsx("video",{src: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?t.jsx("source",{src:l.src,type:l.mimeType}):null},`${r}:${l.src}`),s.length>1?t.jsx(Xe,{onPrev:i,onNext:o,prevLabel:"Previous video",nextLabel:"Next video"}):null]}):null},Ma=()=>t.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:t.jsx("span",{className:"flex size-12 items-center justify-center rounded-full bg-black/55 text-white backdrop-blur",children:t.jsx(w.PlayIcon,{className:"size-6",weight:"fill","aria-hidden":!0})})}),os=({item:e,index:s})=>t.jsxs("div",{className:"absolute inset-0 size-full bg-[#0d0d0d]",children:[e.poster?t.jsx("img",{src:e.poster,alt:`Video ${s+1} thumbnail`,draggable:!1,loading:"lazy",decoding:"async",className:"absolute inset-0 size-full rounded-md object-cover"}):t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:t.jsx(w.VideoCameraIcon,{className:"size-16 rounded-md text-white/30",weight:"regular","aria-hidden":!0})}),t.jsx(Ma,{})]}),Aa=(e,s,n)=>({ariaLabel:`Play video ${s+1} of ${n}`,content:t.jsx(os,{item:e,index:s})}),Ra=({src:e,poster:s,mimeType:n,preload:a,items:r})=>r&&r.length>0?a?r.map(i=>({...i,preload:i.preload??a})):r:e?[{src:e,poster:s,mimeType:n,preload:a}]:[],ls=(e,s)=>e.map((n,a)=>({src:n.src,poster:n.poster,mimeType:n.mimeType,preload:n.preload,filename:s&&e.length===1?s:s?`${s} (${a+1})`:void 0})),La=({src:e,poster:s,mimeType:n,filename:a,preload:r,onClick:i,onDismiss:o})=>{const{viewerOpen:l,viewerIndex:d,handleActivate:h,closeViewer:f}=fe(i);return t.jsxs("div",{className:"relative w-fit",children:[t.jsx("button",{type:"button",onClick:()=>h(0),"aria-label":"Play video",className:"relative block size-[280px] cursor-pointer overflow-hidden rounded-md outline-none focus-visible:ring-2 focus-visible:ring-black/40",children:t.jsx(os,{item:{src:e,poster:s,mimeType:n},index:0})}),o?t.jsx("div",{className:"absolute right-2 top-2 z-10",children:t.jsx(he,{onClick:o})}):null,t.jsx(is,{open:l,items:ls([{src:e,poster:s,mimeType:n,preload:r}],a),initialIndex:d,onClose:f})]})},cs=({state:e,src:s,poster:n,mimeType:a,filename:r,items:i,text:o,groupPosition:l,preload:d,onClick:h})=>{const f=Ra({src:s,poster:n,mimeType:a,preload:d,items:i}),u=xe(e),{viewerOpen:x,viewerIndex:c,handleActivate:g,closeViewer:N}=fe(h);if(f.length===0)return null;const v=f.map((b,p)=>Aa(b,p,f.length));return t.jsxs(me,{variant:u,text:o,groupPosition:l,"data-testid":"video-attachment",children:[t.jsx("div",{className:"relative",children:t.jsx(ns,{tiles:v,onTileActivate:g,className:"overflow-hidden rounded-md"})}),t.jsx(is,{open:x,items:ls(f,r),initialIndex:c,onClose:N})]})},Da=e=>t.jsx(La,{...e}),Pa=e=>t.jsx(cs,{...e,state:"sent"}),za=e=>t.jsx(cs,{...e,state:"received"}),Oa={Composer:Da,Sent:Pa,Received:za},Fa={Image:Na,Video:Oa,Audio:aa,Pdf:Ta,File:xa},ds=({question:e,onClick:s,loading:n=!1,className:a})=>t.jsx("button",{type:"button",onClick:s,disabled:n,style:{backgroundColor:"#E6E5E3"},className:C("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}),$a=({faqs:e,onFaqClick:s,loadingFaqId:n,headerText:a,className:r,avatarImage:i,avatarName:o})=>{const l=e.filter(d=>d.enabled).sort((d,h)=>(d.order??0)-(h.order??0));return l.length===0?null:t.jsx("div",{className:r,children:t.jsxs("div",{className:"flex gap-3 items-end",children:[(i||o)&&t.jsx("div",{className:"flex-none",children:t.jsx(te,{id:o||"account",name:o||"Account",image:i,size:24,shape:"circle"})}),t.jsxs("div",{className:"flex-1 flex flex-col gap-3 rounded-lg p-4",style:{backgroundColor:"#F1F0EE"},children:[a&&t.jsx("p",{className:"text-md text-charcoal mb-4",children:a}),l.map(d=>t.jsx(ds,{question:d.question,onClick:()=>s(d.id),loading:n===d.id},d.id))]})]})})};exports.ActionButton=ae;exports.AttachmentThumbnail=Oe;exports.Avatar=te;exports.ChannelEmptyState=Gt;exports.ChannelList=Xt;exports.ChannelView=Ue;exports.CustomMessageProvider=qs;exports.FaqList=$a;exports.FaqListItem=ds;exports.LinkAttachment=Yn;exports.LockedAttachment=Ae;exports.MediaMessage=Gs;exports.MessageAttachment=Fa;exports.MessageVoteButtons=Bt;exports.MessagingProvider=hs;exports.MessagingShell=Sn;exports.bubbleGroupPositionFromStream=Zn;exports.buildCompactMetaLabel=Zt;exports.formatFileSize=Kt;exports.formatRelativeTime=Yt;exports.getFileExtensionLabel=Jt;exports.getMessageDisplayText=Pe;exports.getSourceType=ee;exports.isLinkAttachment=Be;exports.isUuidLike=It;exports.normalizeLanguageCode=Tt;exports.renderTypeIcon=se;exports.resolveLinkAttachment=we;exports.resolveMediaFromMessage=Ne;exports.resolveParticipantDisplayName=De;exports.useCustomMessage=Ft;exports.useMessageVote=Et;exports.useMessaging=kt;
2
- //# sourceMappingURL=index-BSQPos2Q.cjs.map