@linktr.ee/messaging-react 3.19.0-rc-1785393579 → 3.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CcUtwsNq.cjs");exports.ActionButton=e.ActionButton;exports.Avatar=e.Avatar;exports.ChannelEmptyState=e.ChannelEmptyState;exports.ChannelList=e.ChannelList;exports.ChannelView=e.ChannelView;exports.CustomMessageProvider=e.CustomMessageProvider;exports.FaqList=e.FaqList;exports.FaqListItem=e.FaqListItem;exports.LinkAttachment=e.LinkAttachment;exports.LockedAttachment=e.LockedAttachment;exports.MediaMessage=e.MediaMessage;exports.MessageAttachment=e.MessageAttachment;exports.MessageBubble=e.MessageBubble;exports.MessageVoteButtons=e.MessageVoteButtons;exports.MessagingProvider=e.MessagingProvider;exports.MessagingShell=e.MessagingShell;exports.buildCompactMetaLabel=e.buildCompactMetaLabel;exports.formatFileSize=e.formatFileSize;exports.formatRelativeTime=e.formatRelativeTime;exports.getFileExtensionLabel=e.getFileExtensionLabel;exports.getMessageDisplayText=e.getMessageDisplayText;exports.isLinkAttachment=e.isLinkAttachment;exports.isUuidLike=e.isUuidLike;exports.messageAttachmentGroupPositionFromStream=e.bubbleGroupPositionFromStream;exports.normalizeLanguageCode=e.normalizeLanguageCode;exports.optimizeMessagingAttachmentUrl=e.optimizeMessagingAttachmentUrl;exports.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DSZ8Rxnl.cjs");exports.ActionButton=e.ActionButton;exports.Avatar=e.Avatar;exports.ChannelEmptyState=e.ChannelEmptyState;exports.ChannelList=e.ChannelList;exports.ChannelView=e.ChannelView;exports.CustomMessageProvider=e.CustomMessageProvider;exports.FaqList=e.FaqList;exports.FaqListItem=e.FaqListItem;exports.LinkAttachment=e.LinkAttachment;exports.LockedAttachment=e.LockedAttachment;exports.MediaMessage=e.MediaMessage;exports.MessageAttachment=e.MessageAttachment;exports.MessageBubble=e.MessageBubble;exports.MessageVoteButtons=e.MessageVoteButtons;exports.MessagingProvider=e.MessagingProvider;exports.MessagingShell=e.MessagingShell;exports.buildCompactMetaLabel=e.buildCompactMetaLabel;exports.formatFileSize=e.formatFileSize;exports.formatRelativeTime=e.formatRelativeTime;exports.getFileExtensionLabel=e.getFileExtensionLabel;exports.getMessageDisplayText=e.getMessageDisplayText;exports.isLinkAttachment=e.isLinkAttachment;exports.isUuidLike=e.isUuidLike;exports.messageAttachmentGroupPositionFromStream=e.bubbleGroupPositionFromStream;exports.normalizeLanguageCode=e.normalizeLanguageCode;exports.optimizeMessagingAttachmentUrl=e.optimizeMessagingAttachmentUrl;exports.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as p, m as d, n as v, p as C, q as A, s as k, t as F, u as b, v as P, w as f, x, o as y, y as z, z as B, B as S, D as q, E as D, G as E, H as V, I as w } from "./index-DtD5bLEl.js";
1
+ import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as p, m as d, n as v, p as C, q as A, s as k, t as F, u as b, v as P, w as f, x, o as y, y as z, z as B, B as S, D as q, E as D, G as E, H as V, I as w } from "./index-BuqmY6ae.js";
2
2
  export {
3
3
  e as ActionButton,
4
4
  t as Avatar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linktr.ee/messaging-react",
3
- "version": "3.19.0-rc-1785393579",
3
+ "version": "3.19.0",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -50,8 +50,8 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@linktr.ee/component-library": "11.8.6",
53
- "@linktr.ee/messaging-core": "2.3.0-rc-1785393579",
54
- "@linktr.ee/messaging-taxonomy": "^0.1.0",
53
+ "@linktr.ee/messaging-core": "^2.2.0",
54
+ "@linktr.ee/messaging-taxonomy": "^0.2.0",
55
55
  "@phosphor-icons/react": "^2.1.10"
56
56
  },
57
57
  "devDependencies": {
@@ -1,26 +1,18 @@
1
+ import {
2
+ isAgeSafetySystemType,
3
+ isDmAgentSystemType,
4
+ type AgeSafetySystemType,
5
+ type DmAgentSystemType,
6
+ } from '@linktr.ee/messaging-taxonomy'
1
7
  import { ProhibitIcon, SparkleIcon } from '@phosphor-icons/react'
2
8
  import { MessageTimestamp, type EventComponentProps } from 'stream-chat-react'
3
9
 
4
- import type {
5
- AgeSafetySystemType,
6
- DmAgentSystemType,
7
- } from '../../stream-custom-data'
8
-
9
- const DM_AGENT_SYSTEM_TYPES: readonly DmAgentSystemType[] = [
10
- 'SYSTEM_DM_AGENT_PAUSED',
11
- 'SYSTEM_DM_AGENT_RESUMED',
12
- ]
13
-
14
10
  const DM_AGENT_SYSTEM_MESSAGE_FALLBACK_TEXT: Record<DmAgentSystemType, string> =
15
11
  {
16
12
  SYSTEM_DM_AGENT_PAUSED: 'DM Agent has left the conversation',
17
13
  SYSTEM_DM_AGENT_RESUMED: 'DM Agent has rejoined the conversation',
18
14
  }
19
15
 
20
- const AGE_SAFETY_SYSTEM_TYPES: readonly AgeSafetySystemType[] = [
21
- 'SYSTEM_AGE_SAFETY_BLOCKED',
22
- ]
23
-
24
16
  /**
25
17
  * System-message timestamps are hidden by default. A semantic type must opt in
26
18
  * here to render one, so new/unknown system types stay timestamp-less until
@@ -41,18 +33,6 @@ const AGE_SAFETY_SYSTEM_MESSAGE_FALLBACK_TEXT: Record<
41
33
  const AGE_SAFETY_SYSTEM_MESSAGE_EMPHASIS = 'age safety guidelines.'
42
34
  const AGE_SAFETY_SYSTEM_MESSAGE_URL = 'https://linktr.ee/s/about/contact'
43
35
 
44
- const isDmAgentSystemType = (
45
- value: string | undefined
46
- ): value is DmAgentSystemType => {
47
- return DM_AGENT_SYSTEM_TYPES.includes(value as DmAgentSystemType)
48
- }
49
-
50
- const isAgeSafetySystemType = (
51
- value: string | undefined
52
- ): value is AgeSafetySystemType => {
53
- return AGE_SAFETY_SYSTEM_TYPES.includes(value as AgeSafetySystemType)
54
- }
55
-
56
36
  const isShowTimestampSystemType = (
57
37
  value: string | undefined
58
38
  ): value is (typeof SHOW_SYSTEM_MESSAGE_TIMESTAMP_TYPES)[number] => {
@@ -13,27 +13,21 @@
13
13
  */
14
14
 
15
15
  import {
16
- MESSAGE_CUSTOM_TYPE,
17
16
  type ClassifiableMessage,
18
17
  type MessageCustomType,
18
+ type DmAgentSystemType,
19
+ type AgeSafetySystemType,
20
+ type EscalationSystemType,
19
21
  } from '@linktr.ee/messaging-taxonomy'
20
22
  import type { Attachment, LocalMessage } from 'stream-chat'
21
23
  import 'stream-chat'
22
24
 
23
25
  /**
24
- * System `custom_type` sub-unions consumed by {@link CustomSystemMessage}. The
25
- * taxonomy owns the full {@link MessageCustomType} union but does not export
26
- * these semantic groupings, so they are derived here from the shared catalog
27
- * (never re-typed as bare literals) to stay in lockstep with it.
26
+ * System `custom_type` sub-unions consumed by {@link CustomSystemMessage},
27
+ * re-exported from the shared taxonomy so this module stays their single local
28
+ * entry point.
28
29
  */
29
- export type DmAgentSystemType =
30
- | typeof MESSAGE_CUSTOM_TYPE.SYSTEM_DM_AGENT_PAUSED
31
- | typeof MESSAGE_CUSTOM_TYPE.SYSTEM_DM_AGENT_RESUMED
32
-
33
- export type AgeSafetySystemType =
34
- typeof MESSAGE_CUSTOM_TYPE.SYSTEM_AGE_SAFETY_BLOCKED
35
-
36
- export type EscalationSystemType = typeof MESSAGE_CUSTOM_TYPE.SYSTEM_ESCALATION
30
+ export type { DmAgentSystemType, AgeSafetySystemType, EscalationSystemType }
37
31
 
38
32
  /**
39
33
  * Message metadata for paid messaging and chatbot flows.
@@ -1,10 +1,9 @@
1
- import { isOfficialChannel } from '@linktr.ee/messaging-taxonomy'
1
+ import {
2
+ isOfficialChannel,
3
+ OFFICIAL_SENDER_USER_ID,
4
+ } from '@linktr.ee/messaging-taxonomy'
2
5
  import type { Channel } from 'stream-chat'
3
6
 
4
- // Stream user id of the sender that authors official welcome messages. It is
5
- // the non-linker member of every `linktree-official` channel.
6
- const OFFICIAL_SENDER_USER_ID = 'linktree-official-sender'
7
-
8
7
  type ChannelMembers = NonNullable<Channel['state']>['members']
9
8
  type ChannelMember = ChannelMembers[string]
10
9
 
@@ -1,2 +0,0 @@
1
- "use strict";const t=require("react/jsx-runtime"),m=require("react"),zs=require("@linktr.ee/messaging-core"),ye=require("stream-chat"),w=require("stream-chat-react"),S=require("classnames"),y=require("@phosphor-icons/react"),Z=require("@linktr.ee/messaging-taxonomy"),He=require("stream-chat-react/experimental"),Yt=m.createContext({service:null,client:null,isConnected:!1,isLoading:!1,error:null,capabilities:{},refreshConnection:async()=>{},debug:!1}),Ye=()=>m.useContext(Yt),Bs=({children:e,user:s,serviceConfig:n,apiKey:a,capabilities:r={},debug:i=!1,client:l})=>{var I,T;const o=m.useCallback((k,...O)=>{i&&console.log(`🔥 [MessagingProvider] ${k}`,...O)},[i]);o("🔄 RENDER START",{userId:s==null?void 0:s.id,apiKey:(a==null?void 0:a.substring(0,8))+"...",serviceConfig:!!n,capabilities:Object.keys(r)});const[d,h]=m.useState(null),[f,u]=m.useState(null),[x,c]=m.useState(!1),[v,j]=m.useState(!1),[p,g]=m.useState(null),b=m.useRef(!1),_=m.useRef(null),C=m.useRef(n);C.current=n;const L=m.useRef(i);L.current=i;const R=m.useRef({userId:s==null?void 0:s.id,apiKey:a,serviceConfig:n,capabilities:r}),F=m.useRef(0);F.current++,o("📊 RENDER INFO",{renderCount:F.current,currentProps:{userId:s==null?void 0:s.id,apiKey:(a==null?void 0:a.substring(0,8))+"..."},propChanges:{userChanged:R.current.userId!==(s==null?void 0:s.id),apiKeyChanged:R.current.apiKey!==a,serviceConfigChanged:R.current.serviceConfig!==n,capabilitiesChanged:R.current.capabilities!==r}}),R.current={userId:s==null?void 0:s.id,apiKey:a,serviceConfig:n,capabilities:r};const B=m.useRef(null);!l&&a&&((I=B.current)==null?void 0:I.apiKey)!==a&&(B.current={apiKey:a,client:new ye.StreamChat(a)});const z=l||(a?((T=B.current)==null?void 0:T.client)??null:null);m.useEffect(()=>{const k=F.current,O=C.current;if(l){_.current=null,h(null),u(null),c(!1),g(null),j(!1);return}if(!a||!z||!O){o("⚠️ SERVICE INIT SKIPPED",{renderCount:k,reason:"Missing apiKey, client, or serviceConfig"});return}o("🚀 CREATING SERVICE",{renderCount:k,apiKey:(a==null?void 0:a.substring(0,8))+"..."});const G=new zs.StreamChatService({...O,apiKey:a,debug:L.current,client:z});_.current=G,h(G),o("✅ SERVICE SET",{renderCount:k,serviceInstance:!!G})},[a,z,l]);const P=m.useRef(null);m.useEffect(()=>{var O,G;if(o("🔗 USER CONNECTION EFFECT TRIGGERED",{hasService:!!d,hasUser:!!s,userId:s==null?void 0:s.id,isConnecting:b.current,isConnected:x,dependencies:{service:!!d,userId:s==null?void 0:s.id}}),l)return;if(!d||!s){o("⚠️ USER CONNECTION SKIPPED","Missing service or user");return}if(b.current){o("⚠️ USER CONNECTION SKIPPED","Already connecting");return}if(((O=P.current)==null?void 0:O.serviceId)===d&&((G=P.current)==null?void 0:G.userId)===s.id){o("⚠️ USER CONNECTION SKIPPED","Already connected this user with this service");return}(async()=>{o("🚀 STARTING USER CONNECTION",{userId:s.id}),b.current=!0,j(!0),g(null);try{o("📞 CALLING SERVICE.CONNECTUSER",{userId:s.id});const H=await d.connectUser(s);u(H),c(!0),P.current={serviceId:d,userId:s.id},o("✅ USER CONNECTION SUCCESS",{userId:s.id,clientId:H.userID})}catch(H){const q=H instanceof Error?H.message:"Connection failed";g(q),o("❌ USER CONNECTION ERROR",{userId:s.id,error:q})}finally{j(!1),b.current=!1,o("🔄 USER CONNECTION FINISHED",{userId:s.id,isConnected:x})}})()},[d,s,o,x,l]),m.useEffect(()=>{const k=z;return()=>{var O;k&&(P.current=null,(O=_.current)==null||O.disconnectUser().catch(console.error))}},[z]);const E=m.useCallback(async()=>{if(o("🔄 REFRESH CONNECTION CALLED",{hasService:!!d,hasUser:!!s}),!l){if(!d||!s){o("⚠️ REFRESH CONNECTION SKIPPED","Missing service or user");return}o("🚀 STARTING CONNECTION REFRESH",{userId:s.id}),j(!0);try{o("🔌 DISCONNECTING FOR REFRESH"),await d.disconnectUser(),o("📞 RECONNECTING FOR REFRESH");const k=await d.connectUser(s);u(k),c(!0),g(null),o("✅ CONNECTION REFRESH SUCCESS",{userId:s.id})}catch(k){const O=k instanceof Error?k.message:"Refresh failed";g(O),o("❌ CONNECTION REFRESH ERROR",{userId:s.id,error:O})}finally{j(!1),o("🔄 CONNECTION REFRESH FINISHED",{userId:s.id})}}},[d,s,o,l]),M=m.useMemo(()=>(o("💫 CONTEXT VALUE MEMOIZATION",{hasService:!!d,hasClient:!!f,isConnected:x,isLoading:v,hasError:!!p,capabilitiesKeys:Object.keys(r)}),{service:l?null:d,client:l??f,isConnected:l?!0:x,isLoading:l?!1:v,error:l?null:p,capabilities:r,refreshConnection:E,debug:i}),[d,f,l,x,v,p,r,E,i,o]);return o("🔄 RENDER END",{renderCount:F.current,willRenderChat:!!z,contextValueReady:!!M}),t.jsx(Yt.Provider,{value:M,children:z?t.jsx(w.Chat,{client:z,customClasses:{channelList:"str-chat__channel-list str-chat__channel-list-react bg-transparent lg:border-r-2 border-r-0 border-[#0000000A]"},children:e}):e})},qt=()=>Ye(),Wt=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=o=>{var d;n(o!=null&&o.member?!!o.member.pinned_at:!!((d=e.state.membership)!=null&&d.pinned_at))};return e.on("member.updated",i),()=>{e.off("member.updated",i)}},[e]),s},$s="linktree-official-sender";function qe(e,s,n){const a=Object.values(e||{});if(Z.isOfficialChannel(n)){const r=a.find(i=>{var l;return((l=i.user)==null?void 0:l.id)===$s});if(r)return r}return a.find(r=>{var i;return((i=r.user)==null?void 0:i.id)&&r.user.id!==s})}const Us=/^[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 Xt(e){return Us.test(e.trim())}function Mt(e,s){const n=e==null?void 0:e.trim();return!n||s&&n===s||s&&n===`Follower ${s}`?!1:!Xt(n)}function We(e){return Mt(e==null?void 0:e.name,e==null?void 0:e.id)?e.name.trim():Mt(e==null?void 0:e.username,e==null?void 0:e.id)?e.username.trim():"Unknown member"}const At=[{emoji:"🍎",bgColor:"#FFD1DD"},{emoji:"🍌",bgColor:"#FFF1C9"},{emoji:"🍇",bgColor:"#E6D9FF"},{emoji:"🍊",bgColor:"#D6F4FF"},{emoji:"🍓",bgColor:"#FFE0AE"},{emoji:"🥥",bgColor:"#F7E7D8"},{emoji:"🍒",bgColor:"#DFF4D8"},{emoji:"🥭",bgColor:"#FFD8C2"},{emoji:"🍉",bgColor:"#D6EBFF"},{emoji:"🍋",bgColor:"#CAEEB5"},{emoji:"🥝",bgColor:"#FFE7C7"},{emoji:"🫒",bgColor:"#F6E3B4"},{emoji:"🍈",bgColor:"#D9F7E1"}];function Vs(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 Kt(e){return At[Vs(e)%At.length]}function Gs(e){return Kt(e).emoji}function Hs(e){return Kt(e).bgColor}const le=({id:e,image:s,size:n=40,className:a,starred:r=!1,shape:i="squircle",dmAgentEnabled:l=!1})=>{const o=Gs(e),d=Hs(e),h=.45,u=n<32?Math.round(n*h):n<56?14:n<120?18:36,x=n>=40?2:1,c=i==="circle"?{borderRadius:"50%"}:{borderRadius:"1rem"},v=t.jsx("div",{className:"h-full w-full overflow-hidden",style:c,children:s?t.jsx("img",{src:s,alt:"",className:"h-full w-full object-cover"}):t.jsx("div",{"aria-hidden":"true",className:S("avatar-fallback flex h-full w-full items-center justify-center font-semibold select-none transition-colors"),style:{fontSize:u,lineHeight:1},children:o})});return t.jsxs("div",{className:S("relative flex-shrink-0",a),style:{"--str-chat__avatar-size":`${n}px`,width:`${n}px`,height:`${n}px`,backgroundColor:s?void 0:d,...c},children:[r&&t.jsx("div",{"aria-hidden":"true",className:"absolute -left-1.5 -top-1.5 z-10 flex size-5 items-center justify-center rounded-full bg-white shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]",children:t.jsx(y.StarIcon,{className:"size-3 text-yellow-600",weight:"duotone"})}),t.jsx("div",{"data-testid":"avatar-ring",className:S("h-full w-full","bg-transparent"),style:{...c,...l&&{borderWidth:`${x}px`,borderStyle:"solid",borderColor:"var(--AI-Gradient, #7F22FE)",boxShadow:"inset 0 1px 2px 0 rgba(255, 255, 255, 0.5)"}},children:v})]})},Ys="https://linktr.ee/s/about/trust-center/report",qs=({channel:e,participant:s,showBlockParticipant:n=!0,enabled:a=!0,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:l,onBlockParticipantClick:o,onReportParticipantClick:d,onActionComplete:h,logLabel:f="useChannelModerationActions"})=>{var M;const{service:u,debug:x}=Ye(),c=(M=s==null?void 0:s.user)==null?void 0:M.id,v=!!(a&&n&&u&&c),[j,p]=m.useState(!1),[g,b]=m.useState(null),[_,C]=m.useState(!1),[L,R]=m.useState(!1),F=v&&((g==null?void 0:g.participantId)!==c||(g==null?void 0:g.service)!==u);return m.useEffect(()=>{if(!v||!u||!c){p(!1),b(null);return}let I=!1;return(async()=>{try{const T=await u.getBlockedUsers();if(I)return;p(T.some(k=>k.blocked_user_id===c))}catch(T){I||console.error(`[${f}] Failed to check blocked status:`,T)}finally{I||b({participantId:c,service:u})}})(),()=>{I=!0}},[v,u,c,f]),{isParticipantBlocked:j,isCheckingBlockedStatus:F,isLeaving:_,isUpdatingBlockStatus:L,handleLeaveConversation:async()=>{var I;if(!_){l==null||l(),x&&console.log(`[${f}] Leave conversation`,e.cid),C(!0);try{const T=((I=e._client)==null?void 0:I.userID)??null;await e.hide(T,!1),r&&await r(e),h==null||h()}catch(T){console.error(`[${f}] Failed to leave conversation`,T)}finally{C(!1)}}},handleBlockUser:async()=>{var I,T,k;if(!(L||!u)){o==null||o(),x&&console.log(`[${f}] Block member`,(I=s==null?void 0:s.user)==null?void 0:I.id),R(!0);try{await u.blockUser((T=s==null?void 0:s.user)==null?void 0:T.id),i&&await i((k=s==null?void 0:s.user)==null?void 0:k.id),h==null||h()}catch(O){console.error(`[${f}] Failed to block member`,O)}finally{R(!1)}}},handleUnblockUser:async()=>{var I,T,k;if(!(L||!u)){o==null||o(),x&&console.log(`[${f}] Unblock member`,(I=s==null?void 0:s.user)==null?void 0:I.id),R(!0);try{await u.unBlockUser((T=s==null?void 0:s.user)==null?void 0:T.id),i&&await i((k=s==null?void 0:s.user)==null?void 0:k.id),h==null||h()}catch(O){console.error(`[${f}] Failed to unblock member`,O)}finally{R(!1)}}},handleReportUser:()=>{d==null||d(),h==null||h(),window.open(Ys,"_blank","noopener,noreferrer")}}},me=({variant:e="default",className:s,children:n,...a})=>{const r=e==="danger";return t.jsx("button",{type:"button",className:S("flex w-full items-center gap-3 rounded-lg px-4 py-3 text-left text-sm transition-colors focus-ring disabled:cursor-not-allowed disabled:opacity-60",r?"text-danger hover:bg-danger/50":"text-charcoal hover:bg-sand",s),...a,children:n})},Ws=({channel:e,participant:s,showDeleteConversation:n=!0,showBlockParticipant:a=!0,showReportParticipant:r=!0,onLeaveConversation:i,onBlockParticipant:l,onDeleteConversationClick:o,onBlockParticipantClick:d,onReportParticipantClick:h,customChannelActions:f,triggerClassName:u})=>{const[x,c]=m.useState(!1),v=m.useRef(null),j=m.useId(),p=m.useCallback(()=>c(!1),[]),{isParticipantBlocked:g,isCheckingBlockedStatus:b,isLeaving:_,isUpdatingBlockStatus:C,handleLeaveConversation:L,handleBlockUser:R,handleUnblockUser:F,handleReportUser:B}=qs({channel:e,participant:s,showBlockParticipant:a,enabled:x,onLeaveConversation:i,onBlockParticipant:l,onDeleteConversationClick:o,onBlockParticipantClick:d,onReportParticipantClick:h,onActionComplete:p,logLabel:"ChannelActionsMenu"});return m.useEffect(()=>{if(!x)return;const P=M=>{v.current&&!v.current.contains(M.target)&&c(!1)},E=M=>{M.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",P),document.addEventListener("keydown",E),()=>{document.removeEventListener("mousedown",P),document.removeEventListener("keydown",E)}},[x]),!s||!(n||a||r||!!f)?null:t.jsxs("div",{ref:v,className:"relative",children:[t.jsxs("button",{className:u,type:"button","aria-haspopup":"true","aria-expanded":x,"aria-controls":x?j:void 0,onClick:()=>c(P=>!P),children:[t.jsx(y.DotsThreeIcon,{className:"size-5 text-black/90"}),t.jsx("span",{className:"sr-only",children:"More options"})]}),x&&t.jsx("div",{id:j,"aria-label":"Conversation options",className:S("absolute right-0 top-full z-50 mt-2 w-56 overflow-hidden","rounded-lg border border-sand bg-white p-1 shadow-max-elevation-light"),children:t.jsxs("ul",{className:"flex flex-col gap-1",children:[n&&t.jsx("li",{children:t.jsxs(me,{onClick:L,disabled:_,"aria-busy":_,children:[_?t.jsx(y.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(y.SignOutIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Delete Conversation"})]})}),a&&t.jsx("li",{children:b?t.jsxs(me,{disabled:!0,"aria-busy":!0,children:[t.jsx(y.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}),t.jsx("span",{children:"Block"})]}):g?t.jsxs(me,{onClick:F,disabled:C,"aria-busy":C,children:[C?t.jsx(y.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(y.ProhibitInsetIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Unblock"})]}):t.jsxs(me,{onClick:R,disabled:C,"aria-busy":C,children:[C?t.jsx(y.SpinnerGapIcon,{className:"h-5 w-5 animate-spin"}):t.jsx(y.ProhibitInsetIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Block"})]})}),r&&t.jsx("li",{children:t.jsxs(me,{variant:"danger",onClick:B,children:[t.jsx(y.FlagIcon,{className:"h-5 w-5"}),t.jsx("span",{children:"Report"})]})}),f]})})]})},De="flex size-10 flex-shrink-0 items-center justify-center rounded-full bg-white/65 shadow-[0px_4px_8px_0px_rgba(0,0,0,0.06),0px_0px_0px_1px_rgba(0,0,0,0.04)] backdrop-blur-[40px] transition-filter duration-150 hover:brightness-95 aria-expanded:brightness-95 focus-ring",Xs="CUSTOMER_PAID",Ks=e=>typeof e=="string"&&e.trim().replace(/[\s-]+/g,"_").toUpperCase()===Xs,Zs=({className:e,onBack:s,showBackButton:n,showStarButton:a=!1,onLeaveConversation:r,onBlockParticipant:i,showDeleteConversation:l=!0,showBlockParticipant:o=!0,showReportParticipant:d=!0,onDeleteConversationClick:h,onBlockParticipantClick:f,onReportParticipantClick:u,customChannelActions:x,renderChannelActions:c,showChannelInfo:v=!0,onParticipantNameClick:j})=>{var E,M,I,T;const{channel:p}=w.useChannelStateContext(),{client:g}=w.useChatContext(),b=m.useMemo(()=>{var k;return qe((k=p.state)==null?void 0:k.members,g==null?void 0:g.userID,p.type)},[(E=p.state)==null?void 0:E.members,g==null?void 0:g.userID,p.type]),_=We(b==null?void 0:b.user),C=(M=b==null?void 0:b.user)==null?void 0:M.image,L=Wt(p),R=Ks((I=p.data)==null?void 0:I.customer_tag)&&(b==null?void 0:b.is_follower)===!0,F=a&&L,B=R||F||!!j,z=async()=>{try{L?await p.unpin():await p.pin()}catch(k){console.error("[ChannelHeaderRedesign] Failed to update pinned status:",k)}},P=t.jsxs(t.Fragment,{children:[t.jsx(le,{id:((T=b==null?void 0:b.user)==null?void 0:T.id)||p.id||"unknown",name:_,image:C,shape:"circle",size:48,className:"-mb-2"}),t.jsx("span",{className:S("relative z-10 flex max-w-full flex-col items-center justify-center rounded-full border border-white/10 bg-white/65 py-1.5 shadow-[0px_0px_0px_0px_rgba(0,0,0,0.04),0px_1px_2px_0px_rgba(0,0,0,0.04),0px_8px_32px_0px_rgba(0,0,0,0.1)] backdrop-blur-[2px] transition-filter duration-150 group-hover:brightness-95",B?"pl-3 pr-2":"px-3"),children:t.jsxs("span",{className:"flex max-w-full items-center justify-center",children:[t.jsx("span",{className:"min-w-0 truncate text-sm font-bold leading-[1.43] tracking-[0.28px] text-black/90",children:_}),B&&t.jsxs("span",{className:"ml-2 flex gap-1",children:[R&&t.jsx("span",{"aria-label":"Paid customer",className:"flex size-4 shrink-0 items-center justify-center rounded-full bg-[#34C759] text-white",children:t.jsx(y.CurrencyDollarIcon,{className:"size-2.5",weight:"bold"})}),F&&t.jsx("span",{"aria-label":"Starred conversation",className:"flex size-4 shrink-0 items-center justify-center rounded-full bg-[#FFD60A] text-white",children:t.jsx(y.StarIcon,{className:"size-2.5",weight:"fill"})}),j&&t.jsx(y.CaretRightIcon,{"aria-hidden":"true",className:"size-4 shrink-0 text-black/65",weight:"bold"})]})]})})]});return t.jsx("div",{className:S("@container bg-[linear-gradient(180deg,#FBFAF9_0%,rgba(251,250,249,0.92)_58%,rgba(251,250,249,0)_100%)]",e),children:t.jsxs("div",{className:"grid min-h-[100px] grid-cols-[minmax(40px,1fr)_auto_minmax(40px,1fr)] items-start pb-2 pt-5 @lg:min-h-[104px] @lg:pt-6",children:[t.jsx("div",{className:"flex items-start",children:n&&t.jsx("button",{className:S(De,"messaging-channel-view-back-button-mobile messaging-channel-view-back-button-desktop"),onClick:s||(()=>{}),type:"button","aria-label":"Back to conversations",children:t.jsx(y.ArrowLeftIcon,{className:"size-5 text-black/90"})})}),t.jsx("div",{className:"flex min-w-0 justify-center","data-dd-privacy":"mask",children:j?t.jsx("button",{type:"button",onClick:j,"aria-label":`View details for ${_}`,className:"group flex min-w-0 max-w-full appearance-none flex-col items-center border-0 bg-transparent px-2 focus-ring focus-visible:outline-none",children:P}):t.jsx("div",{className:"flex min-w-0 max-w-full flex-col items-center px-2",children:P})}),t.jsxs("div",{className:"flex items-start justify-end gap-2",children:[a&&t.jsx("button",{className:De,onClick:z,type:"button","aria-pressed":L,"aria-label":L?"Unstar conversation":"Star conversation",children:t.jsx(y.StarIcon,{className:S("size-5",{"text-[#FFD60A]":L,"text-black/90":!L}),weight:L?"fill":"regular"})}),v&&(c!==void 0?c:t.jsx(Ws,{channel:p,participant:b,showDeleteConversation:l,showBlockParticipant:o,showReportParticipant:d,onLeaveConversation:r,onBlockParticipant:i,onDeleteConversationClick:h,onBlockParticipantClick:f,onReportParticipantClick:u,customChannelActions:x,triggerClassName:De}))]})]})})},Js=e=>t.jsx(w.DateSeparator,{...e,position:"center"}),Ue="vote_up",Ve="vote_down";function Qs(e){return e!=null&&e.length?e.some(s=>s.type===Ve)?"down":e.some(s=>s.type===Ue)?"up":null:null}function Zt(e){const{channel:s}=w.useChannelStateContext(),{client:n}=w.useChatContext("useMessageVote"),a=m.useMemo(()=>Qs(e.own_reactions),[e.own_reactions]),r=m.useCallback(async()=>{if(n!=null&&n.userID)try{a==="up"?await s.deleteReaction(e.id,Ue):await s.sendReaction(e.id,{type:Ue},{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,Ve):await s.sendReaction(e.id,{type:Ve},{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 Jt(e){return(e==null?void 0:e.trim().toLowerCase().split(/[-_]/)[0])||void 0}function Xe({message:e,viewerLanguage:s}){var r;const n=e==null?void 0:e.text,a=Jt(s);return a?((r=e==null?void 0:e.i18n)==null?void 0:r[`${a}_text`])??n:n}const en=["linktr.ee"],Lt="messaging-attachment-v1_0";function tn(e){try{return new URL(e).hostname.toLowerCase()}catch{return null}}function sn(e){return en.some(s=>e===s||e.endsWith(`.${s}`))}function ae(e){const s=e==null?void 0:e.trim();if(!s)return;const n=tn(s);if(!n||!sn(n))return s;const a=new URL(s);return a.searchParams.get("io")==="true"&&a.searchParams.get("size")===Lt?s:(a.searchParams.set("io","true"),a.searchParams.set("size",Lt),a.toString())}const nn=[[/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 Qt(e){const s=nn.find(([n])=>n.test(e));return s?s[1]:"generic"}const an={video:y.VideoCameraIcon,audio:y.SpeakerHighIcon,image:y.ImageIcon,document:y.FileIcon},rn={pdf:y.FilePdfIcon,doc:y.FileDocIcon,xls:y.FileXlsIcon,csv:y.FileCsvIcon,ppt:y.FilePptIcon,zip:y.FileZipIcon,text:y.FileTextIcon,markdown:y.FileMdIcon,generic:y.FileIcon};function on(e){const s=ee(e);return s!=="document"?an[s]:rn[Qt(e)]}function oe(e,s){return m.createElement(on(e),s)}const ln=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},cn=({source:e,mimeType:s,poster:n,autoPlay:a=!1,playing:r,loop:i=!1,controls:l=!0,showProgress:o=!1,muted:d=!1,onContainerClick:h})=>{const f=ee(s),u=m.useRef(null),x=m.useRef(null),c=m.useRef(null),v=m.useRef(r),[j,p]=m.useState(a),[g,b]=m.useState(0),[_,C]=m.useState(!1),[L,R]=m.useState(!1),[F,B]=m.useState(!1),[z,P]=m.useState(!1),[E,M]=m.useState(!0),[I,T]=m.useState(null),k=m.useCallback(()=>{B(!1),p(!0)},[]),O=m.useCallback(N=>{const A=x.current;if(!A)return 0;const $=A.getBoundingClientRect();return Math.max(0,Math.min(1,(ln(N)-$.left)/$.width))},[]),G=m.useCallback(N=>{const A=u.current;A&&A.duration&&(A.currentTime=N*A.duration)},[]),H=N=>{N.stopPropagation(),C(!0);const A=O(N);b(A),G(A)};m.useEffect(()=>{r!==void 0&&r!==v.current&&(v.current=r,p(r))},[r]),m.useEffect(()=>{if(!j){c.current!==null&&(cancelAnimationFrame(c.current),c.current=null);return}const N=()=>{const A=u.current;A&&A.duration&&!_&&b(A.currentTime/A.duration),c.current=requestAnimationFrame(N)};return c.current=requestAnimationFrame(N),()=>{c.current!==null&&cancelAnimationFrame(c.current)}},[j,_]),m.useEffect(()=>{const N=u.current;N&&(j?N.play().catch(A=>{p(!1),B(!0)}):N.pause())},[j]),m.useEffect(()=>{if(!_)return;const N=$=>b(O($)),A=$=>{C(!1),G(O($))};return window.addEventListener("mousemove",N),window.addEventListener("mouseup",A),window.addEventListener("touchmove",N,{passive:!0}),window.addEventListener("touchend",A),()=>{window.removeEventListener("mousemove",N),window.removeEventListener("mouseup",A),window.removeEventListener("touchmove",N),window.removeEventListener("touchend",A)}},[_,O,G]);const q=I?{aspectRatio:String(I)}:void 0,W=I?"":" aspect-video",V=Math.round(g*100);return t.jsxs("div",{role:"button",tabIndex:0,className:`relative cursor-pointer overflow-hidden bg-black ${W}`,style:q,onClick:N=>{if(h){h(N);return}F||l&&p(A=>!A)},onKeyDown:N=>{if(!(N.key!=="Enter"&&N.key!==" ")){if(N.preventDefault(),h){h(N);return}F||l&&p(A=>!A)}},children:[n&&(f==="audio"||E)&&t.jsx("img",{src:n,alt:"",className:"absolute inset-0 h-full w-full object-cover"}),!n&&(f==="audio"||E)&&t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:oe(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:()=>P(!0),onCanPlay:()=>{P(!1),M(!1)},onWaiting:()=>P(!0),onPlay:()=>B(!1),onEnded:()=>{i||(p(!1),b(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:()=>P(!0),onCanPlay:()=>{P(!1),M(!1)},onWaiting:()=>P(!0),onPlay:()=>B(!1),onLoadedMetadata:()=>{const N=u.current;N instanceof HTMLVideoElement&&N.videoWidth&&N.videoHeight&&T(N.videoWidth/N.videoHeight)},onEnded:()=>{i||(p(!1),b(0))},children:t.jsx("track",{kind:"captions"})})}),z&&!F&&t.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center",children:t.jsx(y.CircleNotchIcon,{className:"size-8 animate-spin text-white/80",weight:"bold"})}),F&&!l&&t.jsx("div",{className:"absolute inset-0 z-30 flex cursor-pointer items-center justify-center bg-black/35",role:"button",tabIndex:0,"aria-label":"Play preview",onClick:N=>{N.stopPropagation(),k()},onKeyDown:N=>{N.key!=="Enter"&&N.key!==" "||(N.preventDefault(),N.stopPropagation(),k())},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(y.PlayIcon,{className:"size-9 translate-x-0.5",weight:"fill"})})}),o&&!l&&t.jsx("div",{className:"absolute inset-x-0 bottom-0 px-3 pb-2.5 pt-6 bg-gradient-to-t from-black/40 to-transparent",children:t.jsx("div",{role:"slider","aria-label":"Playback position","aria-valuenow":V,"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:N=>N.stopPropagation(),onKeyDown:N=>{N.key==="ArrowRight"&&G(Math.min(1,g+.05)),N.key==="ArrowLeft"&&G(Math.max(0,g-.05))},children:t.jsx("div",{className:"w-full overflow-hidden rounded-full bg-white/30 h-1",children:t.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${V}%`}})})})}),l&&t.jsxs("div",{className:"absolute inset-x-0 bottom-0 flex items-center gap-2 bg-gradient-to-t from-black/60 to-transparent px-3 pb-2.5 pt-6 transition-all duration-200",children:[t.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),p(A=>!A)},className:"shrink-0 text-white","aria-label":j?"Pause":"Play",children:j?t.jsx(y.PauseIcon,{className:"size-5",weight:"fill"}):t.jsx(y.PlayIcon,{className:"size-5 translate-x-px",weight:"fill"})}),t.jsxs("div",{role:"slider","aria-label":"Playback position","aria-valuenow":V,"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:N=>N.stopPropagation(),onMouseEnter:()=>R(!0),onMouseLeave:()=>R(!1),onKeyDown:N=>{N.key==="ArrowRight"&&G(Math.min(1,g+.05)),N.key==="ArrowLeft"&&G(Math.max(0,g-.05))},children:[t.jsx("div",{className:`w-full overflow-hidden rounded-full bg-white/30 transition-all duration-200 ${L||_?"h-1.5":"h-1"}`,children:t.jsx("div",{className:"h-full rounded-full bg-white",style:{width:`${V}%`}})}),t.jsx("div",{className:`absolute size-3 -translate-x-1/2 rounded-full bg-white shadow transition-[opacity,transform] duration-200 ${L||_?"scale-100 opacity-100":"scale-0 opacity-0"}`,style:{left:`${V}%`}})]})]})]})},Rt=e=>e==="dark"?"size-12 text-white/20":"size-12 text-black/20",dn=e=>e==="dark"?"aspect-video overflow-hidden bg-white/10":"aspect-video overflow-hidden bg-black/5",Ke=({mimeType:e,sourceUrl:s,thumbnailUrl:n,title:a,variant:r,mediaPlayerProps:i,containedImage:l=!1})=>{const o=ee(e),[d,h]=m.useState(!1),f=ae(s),u=ae(n);return s&&(o==="video"||o==="audio")?t.jsx(cn,{source:s,mimeType:e,poster:u,controls:!0,...i}):s&&o==="image"?l?t.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:t.jsx("img",{src:f??s,alt:a??"",className:`absolute inset-0 h-full w-full object-contain transition-opacity duration-300 ${d?"opacity-100":"opacity-0"}`,draggable:!1,onLoad:()=>h(!0)})}):t.jsx("img",{src:f??s,alt:a??"",className:"block w-full",draggable:!1}):s&&o==="document"?n?l?t.jsx("div",{className:"relative aspect-video overflow-hidden bg-black/5",children:t.jsx("img",{src:u??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:u??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:oe(e,{className:Rt(r),weight:"regular"})}):n?t.jsx("div",{className:`relative ${dn(r)}`,children:t.jsx("img",{src:u??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:oe(e,{className:Rt(r),weight:"regular"})})},es=({variant:e,thumbnail:s,title:n,placeholderTitle:a="Attachment title",mimeType:r,detail:i,statusBadge:l,action:o,topLeft:d,topRight:h,rootRef:f,"data-testid":u})=>{const x=e==="dark",c=x?n??a:n??"",v=x&&!n;return t.jsxs("div",{ref:f,"data-testid":u,className:S("relative w-[280px] select-none overflow-hidden rounded-[24px] shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]",x?"bg-[#1e2330]":"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:S("mb-0.5 truncate text-base font-medium",{"text-black":!x,"text-white/30":x&&v,"text-white":x&&!v}),children:c}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[oe(r,{className:S("size-5 shrink-0",x?"text-white/55":"text-black/55"),weight:"regular"}),i!=null&&i!==""&&t.jsx("span",{className:S("text-xs font-medium",x?"text-white/55":"text-black/55"),children:i}),l]}),o]})]})};function ts(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ze(e){return`w-[280px] select-none overflow-hidden rounded-[24px] ${e?"bg-[#1e2330]":"bg-[#F3F3F1]"} shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_4px_8px_rgba(0,0,0,0.06)]`}function un(e){return e?"bg-white/10":"bg-black/5"}function mn(e){return e?"text-white":"text-black"}function hn(e){return e?"text-white/55":"text-black/55"}function fn(e){return e?"text-white/40":"text-black/40"}function xn(e){return e?"text-white/20":"text-black/20"}const Je=({attachment:e,isMyMessage:s})=>{const{title:n,text:a,image_url:r,og_scrape_url:i,title_link:l}=e,o=i??l,d=typeof o=="string"&&o.trim()!==""?o:void 0,h=t.jsxs(m.Fragment,{children:[t.jsx("div",{className:"p-2",children:r?t.jsx("img",{src:ae(r)??r,alt:n??"",className:"aspect-video w-full rounded-[20px] object-cover"}):t.jsx("div",{className:`aspect-video w-full rounded-[20px] ${un(s)} flex items-center justify-center`,children:t.jsx(y.LinkIcon,{className:`size-12 ${xn(s)}`})})}),t.jsxs("div",{className:"px-3 pb-3",children:[n&&t.jsx("p",{className:`truncate text-[14px] font-medium leading-5 ${mn(s)}`,children:n}),a&&t.jsx("p",{className:`truncate text-[12px] leading-4 ${hn(s)}`,children:a}),d&&t.jsx("p",{className:`mt-1 truncate text-[12px] leading-4 ${fn(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 Qe(e){return e.type==="link"||!!e.og_scrape_url&&!e.asset_url}function Me(e){var s;return(s=e.attachments)==null?void 0:s.find(Qe)}async function gn(e,s){let n;try{n=s??new URL(e).pathname.split("/").pop()??"download"}catch{n=s??"download"}const a=await fetch(e,{mode:"cors"});if(!a.ok)throw new Error(`HTTP ${a.status}`);const r=await a.blob(),i=URL.createObjectURL(r),l=document.createElement("a");l.href=i,l.download=n,l.style.display="none",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(i)}const pn=({url:e,filename:s})=>{const[n,a]=m.useState(!1),r=i=>{i.stopPropagation();const l=window.open("","_blank","noopener,noreferrer");a(!0),gn(e,s).then(()=>{l==null||l.close()}).catch(()=>{l&&(l.location.href=e)}).finally(()=>a(!1))};return t.jsx("button",{type:"button",onClick:r,disabled:n,className:"mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full bg-[#121110] px-4 text-sm font-medium leading-none text-white hover:bg-[#2a2928] disabled:opacity-70",children:n?t.jsx(y.CircleNotchIcon,{className:"size-4 animate-spin text-white",weight:"bold"}):t.jsxs(m.Fragment,{children:[t.jsx(y.DownloadSimpleIcon,{className:"size-4 text-white",weight:"bold"}),"Download"]})})};function Ae(e){var u,x,c,v;const s=(u=e.attachments)==null?void 0:u.find(j=>j.type==="video"&&j.asset_url),n=(x=e.attachments)==null?void 0:x.find(j=>j.type==="image"&&j.image_url),a=(c=e.attachments)==null?void 0:c.find(j=>j.type==="audio"&&j.asset_url),r=(v=e.attachments)==null?void 0:v.find(j=>j.type==="file"&&j.asset_url),i=s??n??a??r,l=(s==null?void 0:s.asset_url)??(n==null?void 0:n.image_url)??(a==null?void 0:a.asset_url)??(r==null?void 0:r.asset_url);if(!l)return null;const o=(i==null?void 0:i.mime_type)??((i==null?void 0:i.type)==="image"?"image/jpeg":(i==null?void 0:i.type)==="video"?"video/mp4":(i==null?void 0:i.type)==="audio"?"audio/mpeg":"application/octet-stream"),d=i==null?void 0:i.title,h=i==null?void 0:i.file_size,f=s==null?void 0:s.thumb_url;return{resolvedUrl:l,resolvedType:o,title:d,fileSize:h,thumbnailUrl:f}}const ss=({resolvedUrl:e,resolvedType:s,title:n,fileSize:a,thumbnailUrl:r})=>{const i=a!==void 0?ts(a):void 0;return t.jsx(es,{variant:"dark",title:n,placeholderTitle:"",mimeType:s,detail:i,thumbnail:t.jsx(Ke,{mimeType:s,sourceUrl:e,thumbnailUrl:r,title:n,variant:"dark"})})},ns=({resolvedUrl:e,resolvedType:s,title:n,fileSize:a,thumbnailUrl:r})=>{const i=ee(s),l=a!==void 0?ts(a):void 0;return t.jsx(es,{variant:"light",title:n,mimeType:s,detail:l,thumbnail:t.jsx(Ke,{mimeType:s,sourceUrl:e,thumbnailUrl:r,title:n,variant:"light",containedImage:i==="image"||i==="document"}),action:t.jsx(pn,{url:e,filename:n})})},bn=({message:e,isMyMessage:s=!1})=>{const n=Me(e),a=Ae(e);if(!n&&!a)return null;const r=s?"str-chat__message str-chat__message-simple str-chat__message--me str-chat__message-simple--me":"str-chat__message str-chat__message-simple str-chat__message--other";return t.jsxs("div",{className:r,"data-dd-privacy":"mask",children:[!s&&e.user&&t.jsx(le,{className:"str-chat__avatar str-chat__message-sender-avatar",id:e.user.id,image:e.user.image,name:e.user.name??e.user.id}),t.jsx("div",{className:"str-chat__message-inner",style:{marginInlineEnd:0,marginInlineStart:0},children:t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsx("div",{className:"str-chat__message-bubble","data-attachment-bubble":"true",style:{padding:0,borderRadius:0,overflow:"visible",background:"transparent"},children:n?t.jsx("div",{className:Ze(s),children:t.jsx(Je,{attachment:n,isMyMessage:s})}):s?t.jsx(ss,{...a}):t.jsx(ns,{...a})})})})]})},vn=({message:e})=>{const s=Me(e);if(s)return t.jsx("div",{className:Ze(!0),"data-dd-privacy":"mask",children:t.jsx(Je,{attachment:s,isMyMessage:!0})});const n=Ae(e);return n?t.jsx("div",{style:{display:"contents"},"data-dd-privacy":"mask",children:t.jsx(ss,{...n})}):null},jn=({message:e})=>{const s=Me(e);if(s)return t.jsx("div",{className:Ze(!1),"data-dd-privacy":"mask",children:t.jsx(Je,{attachment:s,isMyMessage:!1})});const n=Ae(e);return n?t.jsx("div",{style:{display:"contents"},"data-dd-privacy":"mask",children:t.jsx(ns,{...n})}):null},_n=Object.assign(bn,{Creator:vn,Visitor:jn}),wn={dark:"bg-[#1e2330]",light:"bg-[#f2f1ef]"},Nn={dark:"text-white",light:"text-[#000000]"},yn={dark:"border-white/[0.08]",light:"border-black/[0.08]"},Cn=e=>e==="dark"?"sender":"receiver",Sn={sender:{single:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]",first:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[4px]",middle:"rounded-tl-[18px] rounded-tr-[4px] rounded-bl-[18px] rounded-br-[4px]",end:"rounded-tl-[18px] rounded-tr-[4px] rounded-bl-[18px] rounded-br-[18px]"},receiver:{single:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]",first:"rounded-tl-[18px] rounded-tr-[18px] rounded-bl-[4px] rounded-br-[18px]",middle:"rounded-tl-[4px] rounded-tr-[18px] rounded-bl-[4px] rounded-br-[18px]",end:"rounded-tl-[4px] rounded-tr-[18px] rounded-bl-[18px] rounded-br-[18px]"}},ge=({variant:e,text:s,bordered:n=!0,groupPosition:a="single",widthClassName:r="w-[280px]",paddingClassName:i="px-2 py-2",radiusClassName:l,className:o,children:d,"data-testid":h})=>{const f=s!=null&&s!=="",u=l??Sn[Cn(e)][a];return t.jsxs("div",{"data-testid":h,"data-group-position":a,className:S("relative",r,"overflow-hidden",i,f&&"pb-0",u,wn[e],Nn[e],n&&"border",n&&yn[e],o),children:[d,f?t.jsx("p",{className:S("whitespace-pre-wrap break-words leading-snug","pb-2 pt-2","px-2"),children:s}):null]})},pe=({onClick:e,variant:s="overlay",ariaLabel:n="Dismiss attachment"})=>t.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),e()},"aria-label":n,className:S("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(y.XIcon,{className:"size-3",weight:"bold"})}),be=e=>e==="received"?"light":"dark",as=({firstOfGroup:e,endOfGroup:s,groupedByUser:n})=>!n||e&&s?"single":e?"first":s?"end":"middle",kn=({src:e,mimeType:s,filename:n,items:a})=>a&&a.length>0?a:e?[{src:e,mimeType:s,filename:n}]:[],En=({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]}),et=({state:e,src:s,mimeType:n,filename:a,items:r,text:i,groupPosition:l,preload:o,onDismiss:d})=>{const h=be(e),f=e==="composer"&&!!d,u=kn({src:s,mimeType:n,filename:a,items:r});if(u.length===0)return null;const x=o??(u.length>1?"none":"metadata");return t.jsx(ge,{variant:h,text:i,groupPosition:l,"data-testid":"audio-attachment",children:t.jsx("div",{className:"flex flex-col gap-2",children:u.map((c,v)=>t.jsx(En,{item:c,preload:x,trailingAction:f&&v===0?t.jsx(pe,{onClick:d,variant:"inline"}):void 0},`${c.src}-${v}`))})})},In=e=>t.jsx(et,{...e,state:"composer"}),Tn=e=>t.jsx(et,{...e,state:"sent"}),Mn=e=>t.jsx(et,{...e,state:"received"}),An={Composer:In,Sent:Tn,Received:Mn};function rs(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 Ln={pdf:"PDF",doc:"DOC",xls:"XLS",csv:"CSV",ppt:"PPT",zip:"ZIP",text:"TXT",markdown:"MD"};function is(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=Qt(e),i=Ln[r];if(i)return i;if(e==="application/octet-stream")return}const a=e.split("/")[1];if(!(!a||a==="*"))return a.toUpperCase()}function os(e,s,n){const a=is(e,s),r=typeof n=="number"&&n>0?rs(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 Rn={dark:"text-white/55",light:"text-black/65"},Dn={dark:"bg-white/10",light:"bg-black/5"},Pn={dark:"text-white/85",light:"text-black/85"},ls=({variant:e,filename:s,title:n,mimeType:a="application/octet-stream",fileSize:r,onActivate:i,activateLabel:l,trailingAction:o})=>{const d=n??s??"File",h=os(a,s,r),f=t.jsx("div",{className:S("flex size-10 shrink-0 items-center justify-center rounded-sm",Dn[e]),"aria-hidden":!0,children:oe(a,{className:S("size-6",Pn[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:S("truncate text-xs leading-4",Rn[e]),children:h}):null]}),x=i?t.jsxs("button",{type:"button",onClick:i,"aria-label":l,className:S("flex min-w-0 flex-1 items-center gap-3 rounded-sm text-left transition-colors",e==="dark"?"hover:bg-white/[0.04]":"hover:bg-black/[0.04]"),children:[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,o?t.jsx("div",{className:"shrink-0",children:o}):null]})};async function cs(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),l=document.createElement("a");l.href=i,l.download=n,l.style.display="none",document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(i)}catch{if(!window.open(e,"_blank","noopener,noreferrer")){const r=document.createElement("a");r.href=e,r.download=n,r.target="_blank",r.rel="noopener noreferrer",r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)}}}const On=({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}]:[],Fn=({variant:e,item:s,index:n,onActivate:a,trailingAction:r})=>{const i=s.filename??Q(s.src);return t.jsx(ls,{variant:e,filename:i,title:s.title,mimeType:s.mimeType??"application/octet-stream",fileSize:s.fileSize,onActivate:()=>a(n),activateLabel:`Download ${i}`,trailingAction:r})},tt=({state:e,src:s,filename:n,fileSize:a,mimeType:r,title:i,items:l,text:o,groupPosition:d,onClick:h,onDismiss:f})=>{const u=be(e),x=e==="composer"&&!!f,c=On({src:s,filename:n,fileSize:a,mimeType:r,title:i,items:l}),v=p=>{if((h==null?void 0:h(p))===!1)return;const g=c[p];if(!g)return;const b=g.filename??Q(g.src);cs(g.src,b)};if(c.length===0)return null;const j=t.jsx("span",{className:S("flex size-8 items-center justify-center rounded-full",u==="dark"?"text-white/70":"text-black/70"),"aria-hidden":!0,children:t.jsx(y.DownloadSimpleIcon,{className:"size-5",weight:"bold"})});return t.jsx(ge,{variant:u,text:o,groupPosition:d,"data-testid":"file-attachment",children:t.jsx("div",{className:"flex flex-col gap-2",children:c.map((p,g)=>{const b=x&&g===0?t.jsx(pe,{onClick:f,variant:"inline"}):j;return t.jsx(Fn,{variant:u,item:p,index:g,onActivate:v,trailingAction:b},`${p.src}-${g}`)})})})},zn=e=>t.jsx(tt,{...e,state:"composer"}),Bn=e=>t.jsx(tt,{...e,state:"sent"}),$n=e=>t.jsx(tt,{...e,state:"received"}),Un={Composer:zn,Sent:Bn,Received:$n},st=({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(y.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(y.CaretRightIcon,{size:20,weight:"bold","aria-hidden":!0})})]}),ds=({url:e,filename:s,variant:n="pill",label:a="Download",iconOnly:r,tone:i="dark",onTriggered:l})=>{const[o,d]=m.useState(!1),h=m.useCallback(c=>{c.stopPropagation(),!o&&(d(!0),cs(e,s).catch(()=>{}).finally(()=>{d(!1),l==null||l()}))},[o,e,s,l]),f=r??n!=="pill",x={className:S(n==="pill"?"size-4":"size-5","shrink-0"),weight:"bold"};if(n==="inline"){const c={dark:"text-white/70 hover:bg-white/[0.08] hover:text-white",light:"text-black/70 hover:bg-black/[0.08] hover:text-black"};return t.jsx("button",{type:"button",onClick:h,disabled:o,"aria-label":a,className:S("flex size-8 shrink-0 items-center justify-center rounded-full transition-colors disabled:opacity-70",c[i]),children:o?t.jsx(y.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):t.jsx(y.DownloadSimpleIcon,{className:"size-5 shrink-0",weight:"bold","aria-hidden":!0})})}return n==="viewer"?t.jsx("button",{type:"button",onClick:h,disabled:o,"aria-label":a,className:"mes-media-viewer__action",children:o?t.jsx(y.CircleNotchIcon,{size:20,weight:"bold","aria-hidden":!0}):t.jsx(y.DownloadSimpleIcon,{size:20,weight:"bold","aria-hidden":!0})}):t.jsxs("button",{type:"button",onClick:h,disabled:o,"aria-label":f?a:void 0,className:S("mt-3 inline-flex h-10 w-full items-center justify-center gap-2 rounded-full px-4 text-sm font-medium leading-none transition-colors disabled:opacity-70",i==="dark"?"bg-[#121110] text-white hover:bg-[#2a2928]":"bg-white text-[#121110] hover:bg-white/90"),children:[o?t.jsx(y.CircleNotchIcon,{className:"size-4 animate-spin",weight:"bold","aria-hidden":!0}):t.jsx(y.DownloadSimpleIcon,{...x,"aria-hidden":!0}),f?null:a]})},Pe=(e,s,n)=>Math.min(Math.max(e,s),n),nt=({length:e,initialIndex:s,open:n})=>{const a=Pe(s,0,Math.max(e-1,0)),[r,i]=m.useState(a);m.useEffect(()=>{n&&i(Pe(s,0,Math.max(e-1,0)))},[n,s,e]),m.useEffect(()=>{i(d=>Pe(d,0,Math.max(e-1,0)))},[e]);const l=m.useCallback(()=>{e<=1||i(d=>d<=0?e-1:d-1)},[e]),o=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"?l():o())};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n,e,l,o]),{index:r,prev:l,next:o}},at=({open:e,onClose:s,ariaLabel:n,counter:a,actions:r,children:i,"data-testid":l})=>{const o=m.useRef(null),d=m.useRef(null);m.useEffect(()=>{var x;const u=o.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===o.current&&s()};return t.jsxs("dialog",{ref:o,className:"mes-media-viewer","aria-label":n??"Attachment viewer","data-testid":l,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(y.XIcon,{size:20,weight:"bold","aria-hidden":!0})})]})]}),t.jsx("div",{className:"mes-media-viewer__body",children:i})]})},us=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=nt({length:s.length,initialIndex:n,open:e}),o=s[r],d=m.useMemo(()=>(o==null?void 0:o.filename)??(o?Q(o.src):"image"),[o]);return o?t.jsxs(at,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,actions:t.jsx(ds,{url:o.src,filename:d,variant:"viewer",label:`Download ${d}`}),"data-testid":"image-viewer",children:[e?t.jsx("img",{src:o.src,alt:o.alt??d,draggable:!1,loading:"eager",decoding:"async",className:"mes-media-viewer__image"},`${r}:${o.src}`):null,s.length>1?t.jsx(st,{onPrev:i,onNext:l,prevLabel:"Previous image",nextLabel:"Next image"}):null]}):null},Vn="relative block size-full overflow-hidden bg-black/5 outline-none after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-white/80 focus-visible:after:ring-offset-2 focus-visible:after:ring-offset-black",Gn={1:["rounded-[18px]"],2:["rounded-l-[18px]","rounded-r-[18px]"],3:["rounded-l-[18px]","rounded-tr-[18px]","rounded-br-[18px]"],4:["rounded-tl-[18px]","rounded-tr-[18px]","rounded-bl-[18px]","rounded-br-[18px]"]},Hn="--mes-single-width-cap",Yn="[--mes-single-width-cap:309px] sm:[--mes-single-width-cap:326px]",qn=436,ms=({tiles:e,onTileActivate:s,maxVisible:n=4,singleAspectRatio:a,className:r})=>{const i=e.length;if(i===0)return null;const l=e.slice(0,Math.min(i,n)),o=i-l.length,d=(f,u,x)=>{var v;const c=S(Vn,"h-full w-full",(v=Gn[l.length])==null?void 0:v[u]);return s?t.jsxs("button",{type:"button",onClick:()=>s(u),"aria-label":f.ariaLabel??`Open media ${u+1}`,className:S(c,"cursor-zoom-in"),children:[f.content,x]},u):t.jsxs("div",{className:c,children:[f.content,x]},u)};let h;return a&&(h={aspectRatio:a,width:`min(var(${Hn}), ${Math.round(qn*a*100)/100}px)`,maxWidth:"100%"}),l.length===1?t.jsx("div",{className:S(a?Yn:"aspect-square w-full",r),style:h,children:d(l[0],0)}):l.length===2?t.jsx("div",{className:S("grid aspect-[16/9] w-full grid-cols-2 gap-0.5",r),children:l.map((f,u)=>d(f,u))}):l.length===3?t.jsxs("div",{className:S("grid aspect-[4/3] w-full grid-cols-2 grid-rows-2 gap-0.5",r),children:[t.jsx("div",{className:"row-span-2",children:d(l[0],0)}),d(l[1],1),d(l[2],2)]}):t.jsx("div",{className:S("grid aspect-[379/286] w-full grid-cols-2 grid-rows-2 gap-0.5",r),children:l.map((f,u)=>{const x=o>0&&u===l.length-1;return d(f,u,x?t.jsxs("div",{className:"absolute inset-0 flex items-center justify-center bg-black/55 text-2xl font-semibold text-white",children:["+",o]}):null)})})},ve=e=>{const[s,n]=m.useState(!1),[a,r]=m.useState(0),i=m.useCallback(o=>{(e==null?void 0:e(o))!==!1&&(r(o),n(!0))},[e]),l=m.useCallback(()=>n(!1),[]);return{viewerOpen:s,viewerIndex:a,handleActivate:i,closeViewer:l}},Wn=({item:e,index:s,totalCount:n,fallbackLoading:a,imgRef:r,onLoad:i})=>({ariaLabel:`Open image ${s+1} of ${n}`,content:t.jsx("img",{ref:r,src:ae(e.src)??e.src,alt:e.alt??"",width:e.width,height:e.height,draggable:!1,loading:e.loading??a,decoding:"async",onLoad:i,className:"absolute inset-0 size-full object-cover"})}),Xn=({src:e,alt:s,items:n})=>n&&n.length>0?n:e?[{src:e,alt:s}]:[],hs=(e,s)=>e.map((n,a)=>({src:n.src,alt:n.alt,filename:s&&e.length===1?s:s?`${s} (${a+1})`:void 0})),Kn=({src:e,alt:s,filename:n,loading:a="lazy",onClick:r,onDismiss:i})=>{const{viewerOpen:l,viewerIndex:o,handleActivate:d,closeViewer:h}=ve(r);return t.jsxs("div",{className:"relative w-fit",children:[t.jsx("button",{type:"button",onClick:()=>d(0),"aria-label":"Open image",className:"block size-[280px] cursor-zoom-in overflow-hidden rounded-md outline-none focus-visible:ring-2 focus-visible:ring-black/40",children:t.jsx("img",{src:ae(e)??e,alt:s??"",draggable:!1,loading:a,decoding:"async",className:"size-full object-cover"})}),i?t.jsx("div",{className:"absolute right-2 top-2 z-10",children:t.jsx(pe,{onClick:i})}):null,t.jsx(us,{open:l,items:hs([{src:e,alt:s}],n),initialIndex:o,onClose:h})]})},Zn=326/246,Jn=e=>{const s=e==null?void 0:e.src,[n,a]=m.useState(),r=m.useCallback(d=>{if(!d||d.naturalWidth<=0||d.naturalHeight<=0||s===void 0)return;const h=d.naturalWidth/d.naturalHeight;a(f=>f&&f.src===s&&f.ratio===h?f:{src:s,ratio:h})},[s]),i=m.useCallback(d=>r(d.currentTarget),[r]),l=e!=null&&e.width&&(e!=null&&e.height)?e.width/e.height:void 0,o=n&&n.src===s?n.ratio:void 0;return{ratio:l??o??Zn,imgRef:r,onLoad:i}},fs=({state:e,src:s,alt:n,filename:a,items:r,text:i,groupPosition:l,loading:o="lazy",onClick:d})=>{const h=Xn({src:s,alt:n,items:r}),f=be(e),{viewerOpen:u,viewerIndex:x,handleActivate:c,closeViewer:v}=ve(d),j=h.length===1,p=Jn(j?h[0]:void 0);if(h.length===0)return null;const g=h.map((b,_)=>Wn({item:b,index:_,totalCount:h.length,fallbackLoading:o,imgRef:j?p.imgRef:void 0,onLoad:j?p.onLoad:void 0}));return t.jsxs(ge,{variant:f,text:i,groupPosition:l,bordered:!1,widthClassName:j?"w-fit max-w-[313px] sm:max-w-[330px]":"w-[383px] max-w-full",paddingClassName:"p-0.5",radiusClassName:"rounded-[20px]","data-testid":"image-attachment",children:[t.jsx("div",{className:"relative",children:t.jsx(ms,{tiles:g,onTileActivate:c,singleAspectRatio:j?p.ratio:void 0})}),t.jsx(us,{open:u,items:hs(h,a),initialIndex:x,onClose:v})]})},Qn=e=>t.jsx(Kn,{...e}),ea=e=>t.jsx(fs,{...e,state:"sent"}),ta=e=>t.jsx(fs,{...e,state:"received"}),sa={Composer:Qn,Sent:ea,Received:ta},na=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=nt({length:s.length,initialIndex:n,open:e}),o=s[r],d=m.useMemo(()=>(o==null?void 0:o.filename)??(o?Q(o.src):"document"),[o]),h=m.useMemo(()=>o?aa(o.src):void 0,[o]);return!o||!h?null:t.jsxs(at,{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}:${o.src}`),s.length>1?t.jsx(st,{onPrev:i,onNext:l,prevLabel:"Previous document",nextLabel:"Next document"}):null]})},aa=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()}`},ra=({src:e,filename:s,fileSize:n,title:a,items:r})=>r&&r.length>0?r:e?[{src:e,filename:s,fileSize:n,title:a}]:[],ia=({variant:e,item:s,index:n,onActivate:a,trailingAction:r})=>{const i=s.filename??Q(s.src);return t.jsx(ls,{variant:e,filename:i,title:s.title,mimeType:"application/pdf",fileSize:s.fileSize,onActivate:()=>a(n),activateLabel:`Open ${i}`,trailingAction:r})},rt=({state:e,src:s,filename:n,fileSize:a,title:r,items:i,text:l,groupPosition:o,onClick:d,onDismiss:h})=>{const f=be(e),u=ra({src:s,filename:n,fileSize:a,title:r,items:i}),{viewerOpen:x,viewerIndex:c,handleActivate:v,closeViewer:j}=ve(d),p=e==="composer"&&!!h;if(u.length===0)return null;const g=u.map(b=>({src:b.src,filename:b.filename??Q(b.src)}));return t.jsxs(ge,{variant:f,text:l,groupPosition:o,"data-testid":"pdf-attachment",children:[t.jsx("div",{className:"flex flex-col gap-2",children:u.map((b,_)=>{const C=b.filename??Q(b.src),L=p&&_===0?t.jsx(pe,{onClick:h,variant:"inline"}):e==="composer"?void 0:t.jsx(ds,{url:b.src,filename:C,variant:"inline",label:`Download ${C}`,tone:f});return t.jsx(ia,{variant:f,item:b,index:_,onActivate:v,trailingAction:L},`${b.src}-${_}`)})}),t.jsx(na,{open:x,items:g,initialIndex:c,onClose:j})]})},oa=e=>t.jsx(rt,{...e,state:"composer"}),la=e=>t.jsx(rt,{...e,state:"sent"}),ca=e=>t.jsx(rt,{...e,state:"received"}),da={Composer:oa,Sent:la,Received:ca},xs=({open:e,items:s,initialIndex:n=0,onClose:a})=>{const{index:r,prev:i,next:l}=nt({length:s.length,initialIndex:n,open:e}),o=s[r],d=m.useMemo(()=>(o==null?void 0:o.filename)??(o?Q(o.src):"video"),[o]);return o?t.jsxs(at,{open:e,onClose:a,ariaLabel:d,counter:s.length>1?`${r+1} / ${s.length}`:void 0,"data-testid":"video-viewer",children:[t.jsx("video",{src:o.src,poster:o.poster,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,preload:o.preload??"metadata",className:"mes-media-viewer__video",children:o.mimeType?t.jsx("source",{src:o.src,type:o.mimeType}):null},`${r}:${o.src}`),s.length>1?t.jsx(st,{onPrev:i,onNext:l,prevLabel:"Previous video",nextLabel:"Next video"}):null]}):null},ua=()=>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(y.PlayIcon,{className:"size-6",weight:"fill","aria-hidden":!0})})}),gs=({item:e,index:s})=>t.jsxs("div",{className:"absolute inset-0 size-full bg-[#0d0d0d]",children:[e.poster?t.jsx("img",{src:e.poster,alt:`Video ${s+1} thumbnail`,draggable:!1,loading:"lazy",decoding:"async",className:"absolute inset-0 size-full object-cover"}):t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:t.jsx(y.VideoCameraIcon,{className:"size-16 text-white/30",weight:"regular","aria-hidden":!0})}),t.jsx(ua,{})]}),ma=(e,s,n)=>({ariaLabel:`Play video ${s+1} of ${n}`,content:t.jsx(gs,{item:e,index:s})}),ha=({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}]:[],ps=(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})),fa=({src:e,poster:s,mimeType:n,filename:a,preload:r,onClick:i,onDismiss:l})=>{const{viewerOpen:o,viewerIndex:d,handleActivate:h,closeViewer:f}=ve(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(gs,{item:{src:e,poster:s,mimeType:n},index:0})}),l?t.jsx("div",{className:"absolute right-2 top-2 z-10",children:t.jsx(pe,{onClick:l})}):null,t.jsx(xs,{open:o,items:ps([{src:e,poster:s,mimeType:n,preload:r}],a),initialIndex:d,onClose:f})]})},bs=({state:e,src:s,poster:n,mimeType:a,filename:r,items:i,text:l,groupPosition:o,preload:d,onClick:h})=>{const f=ha({src:s,poster:n,mimeType:a,preload:d,items:i}),u=be(e),{viewerOpen:x,viewerIndex:c,handleActivate:v,closeViewer:j}=ve(h);if(f.length===0)return null;const p=f.map((g,b)=>ma(g,b,f.length));return t.jsxs(ge,{variant:u,text:l,groupPosition:o,"data-testid":"video-attachment",children:[t.jsx("div",{className:"relative",children:t.jsx(ms,{tiles:p,onTileActivate:v})}),t.jsx(xs,{open:x,items:ps(f,r),initialIndex:c,onClose:j})]})},xa=e=>t.jsx(fa,{...e}),ga=e=>t.jsx(bs,{...e,state:"sent"}),pa=e=>t.jsx(bs,{...e,state:"received"}),ba={Composer:xa,Sent:ga,Received:pa},he={Image:sa,Video:ba,Audio:An,Pdf:da,File:Un},va={isUnlocking:()=>!1},ja={LockedAttachment:va},vs=m.createContext({}),_a=vs.Provider;function js(e){return m.useContext(vs)[e]??ja[e]}const wa=m.lazy(()=>Promise.resolve().then(()=>require("./Card-415OfRhw.cjs"))),Na=m.lazy(()=>Promise.resolve().then(()=>require("./Card-BI3pdi-h.cjs"))),ya=()=>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}),fe=e=>t.jsx(m.Suspense,{fallback:t.jsx(ya,{}),children:e.contentType==="text"?t.jsx(wa,{...e}):t.jsx(Na,{...e})}),Ca=({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})}),Sa=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)===Z.MESSAGE_CUSTOM_TYPE.TIP},_s=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)===Z.MESSAGE_CUSTOM_TYPE.PAID},Ce=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)===Z.MESSAGE_CUSTOM_TYPE.CHATBOT},it=e=>{var s;return((s=e.metadata)==null?void 0:s.custom_type)===Z.MESSAGE_CUSTOM_TYPE.ATTACHMENT},ka=e=>{var s;return it(e)&&((s=e.metadata)==null?void 0:s.attachment_content_type)==="text"},Ea=e=>{var s;return it(e)&&((s=e.metadata)==null?void 0:s.attachment_content_type)!=="text"},ws=e=>Sa(e)||_s(e),Ia=e=>{var s;return ws(e)&&!((s=e.text)!=null&&s.trim())},Oe=({message:e,standalone:s=!1,isMyMessage:n=!1,hasAttachment:a=!1})=>{var u;const r=ws(e),i=Ce(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",v=_s(e)?"message":"tip",j=s?`${x} ${v}`:`Delivered with ${x} ${v}`;return t.jsxs("div",{className:c,children:[t.jsx(y.GiftIcon,{size:s?14:12}),t.jsx("span",{children:j})]})}const l=n&&a,o=l?"Sent with AI":"Sent by AI Assistant",d=["message-chatbot-indicator",n?"message-chatbot-indicator--sender":"message-chatbot-indicator--receiver",l?"message-chatbot-indicator--attachment":"message-chatbot-indicator--text"].join(" "),h=t.jsx("span",{className:"message-chatbot-indicator__label",children:o}),f=t.jsx("span",{className:"message-chatbot-indicator__icon",children:t.jsx(Ca,{size:l?12:15})});return t.jsx("div",{className:d,"data-testid":"message-chatbot-indicator",children:n&&!l?t.jsxs(t.Fragment,{children:[h,f]}):t.jsxs(t.Fragment,{children:[f,h]})})},Ns=({selected:e,onVoteUp:s,onVoteDown:n})=>t.jsxs("div",{className:"message-vote-buttons",children:[t.jsx("button",{type:"button",className:S("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(y.ThumbsUpIcon,{size:16,weight:e==="up"?"fill":"regular"})}),t.jsx("button",{type:"button",className:S("message-vote-button focus-ring",{"message-vote-button--selected":e==="down"}),onClick:n,"aria-label":"Bad response","aria-pressed":e==="down","data-tooltip":"Bad response",children:t.jsx(y.ThumbsDownIcon,{size:16,weight:e==="down"?"fill":"regular"})})]}),ys=()=>{const{message:e}=w.useMessageContext("SentMessageDeliveryStatus"),{messages:s}=w.useChannelStateContext("SentMessageDeliveryStatus"),n=(()=>{if(s)for(let a=s.length-1;a>=0;a-=1){const r=s[a];if(!(r.type==="system"||r.type==="ephemeral"||r.type==="deleted"))return r.id}})();return e.id===n},Fe=()=>ys()?t.jsxs(t.Fragment,{children:[t.jsx(y.ChecksIcon,{weight:"bold","aria-hidden":"true"}),t.jsx("span",{"data-testid":"sent-message-delivery-status",children:"Delivered"})]}):null,Ta=()=>ys()?t.jsxs(t.Fragment,{children:[t.jsx(y.CircleNotchIcon,{className:"sent-message-status__spinner animate-spin",weight:"bold","aria-hidden":"true"}),t.jsx("span",{"data-testid":"sent-message-sending-status",children:"Sending"})]}):null,Ma=()=>t.jsxs("span",{className:"str-chat__message-status sent-message-status--failed",children:[t.jsx(y.WarningCircleIcon,{weight:"bold","aria-hidden":"true"}),t.jsx("span",{"data-testid":"sent-message-failed-status",children:"Failed to send"})]}),Aa=()=>{const{isMyMessage:e,message:s,threadList:n}=w.useMessageContext("SentMessageDeliveryStatus");return n?null:s.status==="failed"&&e()&&s.type!=="error"?t.jsx(Ma,{}):t.jsx(w.MessageStatus,{MessageSentStatus:Fe,MessageDeliveredStatus:Fe,MessageReadStatus:Fe,MessageSendingStatus:Ta})},La=/^([a-z][a-z0-9+.-]*):/i,Ra=new Set(["http","https","mailto","tel","sms"]);function ot(e){if(typeof e!="string")return;const s=e.trim();if(s==="")return;const n=La.exec(s);if(n){const a=n[1].toLowerCase();return Ra.has(a)?s:void 0}return s.startsWith("//")||s.startsWith("/")?s:`https://${s}`}const Da={dark:"bg-white text-[#121110] hover:bg-white/90",light:"bg-[#121110] text-white hover:bg-[#2a2928]"},Pa=({variant:e,cta:s})=>{const n=S("mt-2 inline-flex h-10 w-full items-center justify-center rounded-full px-4 text-sm font-medium leading-none transition-colors",Da[e]),a=ot(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})},Oa={dark:"text-white",light:"text-black/90"},Fa="text-white/30",za={dark:"text-white/55",light:"text-black/55"},Ba={dark:"bg-white/25",light:"bg-black/15"},lt=({variant:e,title:s,placeholderTitle:n,description:a,url:r,appIcon:i,cta:l,trailingAction:o,chinTextColor:d,isLoading:h=!1})=>{const f=e==="dark",u=s??(f?n:void 0)??"",x=u.trim()!=="",c=a!=null&&a.trim()!=="",v=typeof r=="string"?r.trim():"",j=v!=="",p=l!=null;if(!h&&!x&&!c&&!j&&!p)return null;const g=f&&!s,b=S("line-clamp-2 text-[14px] font-medium leading-5 tracking-[0.28px]",d==null&&(g?Fa:Oa[e])),_=S("truncate text-[12px] leading-4 tracking-[0.24px]",d==null&&za[e]),C=d?{color:d}:void 0;if(h){const L=S("animate-pulse rounded",Ba[e]);return t.jsx("div",{className:"shrink-0 px-4 py-3",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-[2px]",children:[t.jsx("div",{className:S("h-5 w-3/4",L),"aria-hidden":!0}),t.jsx("div",{className:S("h-4 w-1/2",L),"aria-hidden":!0})]})})}return t.jsxs("div",{className:"shrink-0 px-4 py-3",children:[t.jsxs("div",{className:"flex items-end gap-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-[2px]",children:[x&&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:S("min-w-0",b),style:C,children:u})]}),c&&t.jsx("p",{className:_,style:C,children:a}),!p&&j&&t.jsx("p",{className:_,style:C,children:v})]}),o&&t.jsx("div",{className:"shrink-0",children:o})]}),l&&t.jsx(Pa,{variant:e,cta:l})]})},$a="Loading link preview",Ua=S("relative w-[290px] select-none overflow-hidden","rounded-[20px]"),Va="flex h-[250px] flex-col",Se=({variant:e,children:s,href:n,onClick:a,ariaLabel:r,rootRef:i,topRight:l,bgClassName:o,accentStyle:d,fixedHeight:h=!1,busy:f=!1,"data-testid":u})=>{const x=n!=null||a!=null,c=S(Ua,h?Va:"block",o??(e==="dark"?"bg-shade":"bg-white"),x?"cursor-pointer no-underline focus-ring":null),v=f?{role:"status","aria-busy":!0,"aria-label":$a}:void 0,j=l?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-10",children:l}):null;return n?t.jsxs("a",{ref:i,href:n,target:"_blank",rel:"noopener noreferrer",onClick:a,"data-testid":u,className:c,style:d,...v,children:[s,j]}):a?t.jsxs("button",{ref:i,type:"button",onClick:a,"aria-label":r,"data-testid":u,className:S(c,"text-left"),style:d,...v,children:[s,j]}):t.jsxs("div",{ref:i,"data-testid":u,className:c,style:d,...v,children:[s,j]})},Dt={dark:"bg-white/10",light:"bg-black/5"},Ga={dark:"size-16 text-white/25",light:"size-16 text-black/25"},je=(e,s)=>!!s&&!!e&&ee(e)==="audio",ct=(e,s)=>{if(!s||!e)return!1;const n=ee(e);return n==="video"||n==="audio"},dt="bg-[#F2F3F4]",ke=({variant:e,thumbnailUrl:s,sourceUrl:n,title:a,mimeType:r="image/*",topLeft:i,topRight:l,isLoading:o=!1,onImageError:d})=>{const h=ee(r),f=!!n&&h==="video",u=ae(s);return!o&&je(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:S("relative min-h-0 w-full flex-1 overflow-hidden",f&&"bg-black"),children:[o?t.jsx("div",{className:S("h-full w-full animate-pulse",Dt[e]),"aria-hidden":!0}):f?t.jsxs(t.Fragment,{children:[t.jsx("video",{src:n,poster:u,controls:!0,playsInline:!0,preload:"metadata",className:"absolute inset-0 h-full w-full object-contain",children:t.jsx("track",{kind:"captions"})}),u&&d?t.jsx("img",{src:u,alt:"","aria-hidden":!0,onError:d,className:"hidden"}):null]}):s?t.jsx("img",{src:u??s,alt:a??"",draggable:!1,loading:"lazy",decoding:"async",onError:d,className:"absolute inset-0 h-full w-full object-cover"}):t.jsx("div",{className:S("flex h-full w-full items-center justify-center",Dt[e]),children:oe(r,{className:Ga[e],weight:"regular"})}),i?t.jsx("div",{className:"pointer-events-auto absolute left-3 top-3 z-10",children:i}):null,l?t.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-10",children:l}):null]})},Ne="#FFFFFF",Pt="#040403",Ha="#1e2330",Ya=3,qa=/^#?(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function Wa(e){if(typeof e!="string"||!qa.test(e.trim()))return;const s=e.trim().replace(/^#/,""),n=s.length===Ya?s.replace(/./g,a=>a+a):s;return[Number.parseInt(n.slice(0,2),16),Number.parseInt(n.slice(2,4),16),Number.parseInt(n.slice(4,6),16)]}function ze(e){const s=e/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4}function Ge(e){const s=Wa(e);return s?.2126*ze(s[0])+.7152*ze(s[1])+.0722*ze(s[2]):Number.NaN}function Ot(e,s){const n=Ge(e),a=Ge(s);if(Number.isNaN(n)||Number.isNaN(a))return Number.NaN;const r=Math.max(n,a),i=Math.min(n,a);return(r+.05)/(i+.05)}function Xa(e){if(e==null)return Ne;const s=Ot(e,Ne);return Number.isNaN(s)||s>=Ot(e,Pt)?Ne:Pt}function Ka(e){if(e==null||Number.isNaN(Ge(e)))return;const s=e.trim();return s.startsWith("#")?s:`#${s}`}const Za={dark:Ha,light:"#ffffff"};function ut({variant:e,accentColor:s,status:n="ready",layout:a="featured",thumbnailUrl:r,mimeType:i,sourceUrl:l}){const[o,d]=m.useState(!1);m.useEffect(()=>{d(!1)},[r]);const h=m.useCallback(()=>{d(!0)},[]),u=a==="featured"&&!!r&&!je(i,l)&&!o&&n==="ready"?Ka(s):void 0;return{thumbnailUrl:o?void 0:r,accentStyle:u?{backgroundColor:u}:void 0,chinTextColor:u?Xa(u):void 0,tailColor:u??Za[e],isLoading:n==="loading",onImageError:h}}const Ja="flex size-6 items-center justify-center rounded-full bg-[#121110] text-white focus-ring",Qa="relative before:absolute before:-inset-[10px] before:content-['']",er=({title:e,placeholderTitle:s,description:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:l,layout:o="featured",appIcon:d,cta:h,accentColor:f,status:u="ready",onDismiss:x,onEditClick:c,dismissLabel:v="Dismiss attachment"})=>{const j=o==="classic",p=je(r,l),g=ut({variant:"dark",accentColor:f,status:u,layout:o,thumbnailUrl:i,mimeType:r,sourceUrl:l}),b=x?t.jsx("button",{type:"button",onClick:x,"aria-label":v,className:S(Ja,!p&&Qa),children:t.jsx(y.XIcon,{className:"size-3",weight:"bold"})}):void 0,_=c?t.jsx("button",{type:"button",onClick:c,"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(y.PencilSimpleIcon,{className:"size-5",weight:"regular"})}):void 0;return p&&!g.isLoading?t.jsx(Se,{variant:"dark",bgClassName:dt,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(ke,{variant:"dark",sourceUrl:l,title:e,mimeType:r})}),b&&t.jsx("div",{className:"shrink-0",children:b})]})}):t.jsxs(Se,{variant:"dark",fixedHeight:!j,accentStyle:g.accentStyle,busy:g.isLoading,topRight:j?b:void 0,children:[!j&&t.jsx(ke,{variant:"dark",thumbnailUrl:g.thumbnailUrl,sourceUrl:l,title:e,mimeType:r,topRight:b,isLoading:g.isLoading,onImageError:g.onImageError}),t.jsx(lt,{variant:"dark",title:e,placeholderTitle:s,description:n,url:a,appIcon:d,cta:h,trailingAction:_,chinTextColor:g.chinTextColor,isLoading:g.isLoading})]})},Cs=({color:e,side:s,visible:n,children:a})=>n?t.jsxs("div",{className:"relative isolate w-fit",children:[a,t.jsx("span",{"aria-hidden":!0,"data-testid":"link-card-tail",style:{backgroundColor:e},className:S("messaging-link-card-tail",s==="receiver"&&"messaging-link-card-tail--received")})]}):t.jsx(t.Fragment,{children:a}),tr=({title:e,description:s,url:n,mimeType:a,thumbnailUrl:r,sourceUrl:i,layout:l="featured",appIcon:o,cta:d,accentColor:h,status:f="ready",onClick:u,groupPosition:x="single"})=>{const c=ct(a,i),v=ot(n),j=d==null&&v!=null&&!c?v:void 0,p=d==null&&!c?u:void 0,g=f!=="loading"&&je(a,i)?dt:void 0,b=d&&u?{...d,onClick:()=>{var C;u(),(C=d.onClick)==null||C.call(d)}}:d,_=ut({variant:"light",accentColor:h,status:f,layout:l,thumbnailUrl:r,mimeType:a,sourceUrl:i});return t.jsx(Cs,{color:_.tailColor,side:"receiver",visible:g==null&&(x==="single"||x==="end"),children:t.jsxs(Se,{variant:"light",href:j,onClick:p,ariaLabel:e??"Open attachment preview",fixedHeight:l==="featured"&&g==null,accentStyle:_.accentStyle,busy:_.isLoading,bgClassName:g,"data-testid":"link-attachment",children:[l==="featured"&&t.jsx(ke,{variant:"light",thumbnailUrl:_.thumbnailUrl,sourceUrl:i,title:e,mimeType:a,isLoading:_.isLoading,onImageError:_.onImageError}),t.jsx(lt,{variant:"light",title:e,description:s,url:n,appIcon:o,cta:b,chinTextColor:_.chinTextColor,isLoading:_.isLoading})]})})},sr=({title:e,placeholderTitle:s,description:n,url:a,mimeType:r,thumbnailUrl:i,sourceUrl:l,layout:o="featured",appIcon:d,cta:h,accentColor:f,status:u="ready",onClick:x,groupPosition:c="single"})=>{const v=ct(r,l),j=ot(a),p=h==null&&j!=null&&!v?j:void 0,g=h==null&&!v&&p!=null?x:void 0,b=u!=="loading"&&je(r,l),_=ut({variant:"dark",accentColor:f,status:u,layout:o,thumbnailUrl:i,mimeType:r,sourceUrl:l});return t.jsx(Cs,{color:_.tailColor,side:"sender",visible:!b&&(c==="single"||c==="end"),children:t.jsxs(Se,{variant:"dark",href:p,onClick:g,fixedHeight:o==="featured"&&!b,accentStyle:_.accentStyle,busy:_.isLoading,bgClassName:b?dt:void 0,children:[o==="featured"&&t.jsx(ke,{variant:"dark",thumbnailUrl:_.thumbnailUrl,sourceUrl:l,title:e,mimeType:r,isLoading:_.isLoading,onImageError:_.onImageError}),t.jsx(lt,{variant:"dark",title:e,placeholderTitle:s,description:n,url:a,appIcon:d,cta:h,chinTextColor:_.chinTextColor,isLoading:_.isLoading})]})})},Ee={Composer:er,Sent:sr,Received:tr};function D(e){const s=e==null?void 0:e.trim();return s||void 0}function Ft(e){return e.trim().replace(/^https?:\/\//i,"").replace(/\/+$/,"").toLowerCase()}function nr(e,s){if(!(e!=null&&e.trim())||!(s!=null&&s.trim()))return!1;const n=Ft(e),a=Ft(s);if(n===a)return!0;if(!n.includes(a))return!1;const r=n.split(a).join("");return!/[^\p{P}\p{Z}\p{C}]/u.test(r)}function zt(e){const s=D(e.og_scrape_url)??D(e.title_link),n=D(e.image_url)??D(e.thumb_url),a=D(e.asset_url),r=D(e.mime_type);return{title:D(e.title),description:D(e.text),url:s,thumbnailUrl:ae(n),sourceUrl:a,layout:n||ct(r,a)?"featured":"classic",mimeType:r,accentColor:D(e.accent_color),status:"ready"}}function ar(e){var s;return Ss(e)?null:e.type==="image"?e.image_url||e.asset_url?"image":null:e.type==="video"&&e.asset_url?"video":e.type==="audio"&&e.asset_url?"audio":e.type==="file"&&e.asset_url?e.mime_type==="application/pdf"?"pdf":(s=e.mime_type)!=null&&s.startsWith("audio/")?"audio":"file":null}function Ss(e){const s=D(e.og_scrape_url);return e.type==="link"||!!s&&!e.asset_url}function ks(e){if(!(e!=null&&e.length))return[];const s=[],n=(r,i)=>{const l=s[s.length-1];if((l==null?void 0:l.type)==="media"&&l.kind===r){l.attachments.push(i);return}s.push({type:"media",kind:r,attachments:[i]})},a=r=>{const i=s[s.length-1];if((i==null?void 0:i.type)==="link"){i.attachments.push(r);return}s.push({type:"link",attachments:[r]})};for(const r of e){if(Ss(r)){a(r);continue}const i=ar(r);i&&n(i,r)}return s}function rr(e){return e.filter(s=>s.type==="media").length}function ir(e,s,n){return s<=1?n:e===0?"first":e===s-1?"end":"middle"}function Bt(e){return D(e.image_url)??D(e.asset_url)??""}function or(e){switch(e){case"image":return he.Image;case"video":return he.Video;case"audio":return he.Audio;case"pdf":return he.Pdf;default:return he.File}}function lr(e,s){if(s.length>1)switch(e){case"image":return{items:s.map(a=>({src:Bt(a),alt:D(a.title)}))};case"video":return{items:s.map(a=>({src:D(a.asset_url)??"",poster:D(a.thumb_url),mimeType:D(a.mime_type)}))};case"audio":return{items:s.map(a=>({src:D(a.asset_url)??"",mimeType:D(a.mime_type)??"audio/mpeg",filename:D(a.title)}))};case"pdf":return{items:s.map(a=>({src:D(a.asset_url)??"",filename:D(a.title),fileSize:a.file_size}))};case"file":return{items:s.map(a=>({src:D(a.asset_url)??"",filename:D(a.title),fileSize:a.file_size,mimeType:D(a.mime_type)??"application/octet-stream"}))}}const n=s[0];if(!n)return{};switch(e){case"image":return{src:Bt(n),alt:D(n.title)};case"video":return{src:D(n.asset_url)??"",poster:D(n.thumb_url),mimeType:D(n.mime_type)};case"audio":return{src:D(n.asset_url)??"",mimeType:D(n.mime_type)??"audio/mpeg",filename:D(n.title)};case"pdf":return{src:D(n.asset_url)??"",filename:D(n.title),fileSize:n.file_size};case"file":return{src:D(n.asset_url)??"",filename:D(n.title),fileSize:n.file_size,mimeType:D(n.mime_type)??"application/octet-stream"}}}function cr({groupPosition:e,isMyMessage:s,segment:n}){const a=or(n.kind),r={...lr(n.kind,n.attachments),groupPosition:e};return s?t.jsx(a.Sent,{...r}):t.jsx(a.Received,{...r})}const dr=({groupPosition:e,isMyMessage:s,message:n,renderText:a})=>{var j;const r=ks(n.attachments);if(r.length===0)return null;const i=rr(r),l=(j=n.text)==null?void 0:j.trim(),o=r.find(p=>p.type==="link"),d=(o==null?void 0:o.type)==="link"?zt(o.attachments[0]??{}).url:void 0,h=l&&nr(l,d)?void 0:l;let f=0;const u=[],x=h?"middle":e,c=(p,g,b)=>{const _=s?Ee.Sent:Ee.Received;u.push(t.jsx(_,{...zt(p),groupPosition:b?x:"middle"},g))},v=(p,g)=>{const b=ir(f,i,e);f+=1,u.push(t.jsx(cr,{groupPosition:b,isMyMessage:s,segment:p},g))};return r.forEach((p,g)=>{const b=g===r.length-1;if(p.type==="link"){p.attachments.forEach((_,C)=>{c(_,`link-${g}-${C}`,b&&C===p.attachments.length-1)});return}v(p,`media-${g}`)}),t.jsxs("div",{className:"str-chat__message-bubble-wrapper",children:[t.jsxs("div",{className:"str-chat__message-bubble","data-attachment-bubble":"true",style:{background:"transparent",borderRadius:0,overflow:"visible",padding:0},children:[u,!h&&t.jsx(w.MessageErrorIcon,{})]}),h?t.jsxs("div",{className:"str-chat__message-bubble",children:[t.jsx(w.MessageText,{message:n,renderText:a}),t.jsx(w.MessageErrorIcon,{})]}):null]})},ur=e=>{var vt,jt,_t,wt,Nt,yt,Ct,St,kt,Et;const{additionalMessageInputProps:s,chatbotVotingEnabled:n,editing:a,endOfGroup:r,firstOfGroup:i,groupedByUser:l,handleAction:o,handleOpenThread:d,handleRetry:h,highlighted:f,isMessageAIGenerated:u,isMyMessage:x,message:c,renderText:v,threadList:j,viewerLanguage:p}=e,{client:g}=w.useChatContext("CustomMessage"),{channel:b}=w.useChannelStateContext("CustomMessage"),{isUnlocking:_,onUnlockClick:C,onFetchSource:L,onDownloadClick:R}=js("LockedAttachment"),[F,B]=m.useState(!1),z=w.useMessageReminder(c.id),{selected:P,voteUp:E,voteDown:M}=Zt(c),{Attachment:I=w.Attachment,EditMessageModal:T=w.EditMessageModal,MessageActions:k,MessageBlocked:O=w.MessageBlocked,MessageBouncePrompt:G=w.MessageBouncePrompt,MessageDeleted:H=w.MessageDeleted,MessageIsThreadReplyInChannelButtonIndicator:q=w.MessageIsThreadReplyInChannelButtonIndicator,MessageRepliesCountButton:W=w.MessageRepliesCountButton,ReminderNotification:V=w.ReminderNotification,StreamedMessageText:N=w.StreamedMessageText,PinIndicator:A}=w.useComponentContext("CustomMessage"),$=w.messageHasAttachments(c),J=w.messageHasReactions(c),Y=m.useMemo(()=>u==null?void 0:u(c),[u,c]),U=m.useMemo(()=>{const ie=c.attachments??[],ue=c.shared_location?[c.shared_location,...ie]:ie;if(!Ce(c))return ue;const It=ue.filter(Tt=>!("type"in Tt)||!Qe(Tt));return It.length===ue.length?ue:It},[c]),X=m.useMemo(()=>ks(U),[U]),te=m.useMemo(()=>{const ie=Xe({message:c,viewerLanguage:p});return ie===c.text?c:{...c,text:ie}},[c,p]),_e=X.length>0,we=X.reduce((ie,ue)=>ie+ue.attachments.length,0)===((U==null?void 0:U.length)??0),se=as({endOfGroup:r,firstOfGroup:i,groupedByUser:l});if(w.isDateSeparatorMessage(c))return null;if(c.deleted_at||c.type==="deleted")return t.jsx(H,{message:c});if(w.isMessageBlocked(c))return t.jsx(O,{});const re=!j&&!!c.reply_count,ne=!j&&c.show_in_channel&&c.parent_id,ht=c.status==="failed"&&((vt=c.error)==null?void 0:vt.status)!==403,ft=w.isMessageBounced(c);let ce;ht?ce=()=>h(c):ft&&(ce=()=>B(!0));const K=x(),Ps=S("str-chat__message str-chat__message-simple",`str-chat__message--${c.type}`,`str-chat__message--${c.status}`,K?"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":J,"str-chat__message-send-can-be-retried":(c==null?void 0:c.status)==="failed"&&((jt=c==null?void 0:c.error)==null?void 0:jt.status)!==403,"str-chat__message-with-thread-link":re||ne,"str-chat__virtual-message__wrapper--end":r,"str-chat__virtual-message__wrapper--first":i,"str-chat__virtual-message__wrapper--group":l}),Le=c.poll_id&&g.polls.fromState(c.poll_id),xt=Ia(c),de=Ce(c),Os=it(c),Re=!!(U!=null&&U.length&&!c.quoted_message),gt=de&&K&&Re,Fs=_e&&we&&!c.quoted_message&&!Le&&!Y&&!de,pt={contentType:"text",amountText:(_t=c.metadata)==null?void 0:_t.amount_text,paymentStatus:(wt=c.metadata)==null?void 0:wt.payment_status,renderedText:c.text&&t.jsx(w.MessageText,{message:te,renderText:v})},bt={contentType:"media",title:(Nt=c.metadata)==null?void 0:Nt.attachment_title,mimeType:(yt=c.metadata)==null?void 0:yt.attachment_mime_type,thumbnailUrl:(Ct=c.metadata)==null?void 0:Ct.attachment_thumbnail,amountText:(St=c.metadata)==null?void 0:St.amount_text,detail:(kt=c.metadata)==null?void 0:kt.attachment_detail,paymentStatus:(Et=c.metadata)==null?void 0:Et.payment_status,onFetchSource:L?()=>L(c,b):void 0};return t.jsxs(t.Fragment,{children:[a&&t.jsx(T,{additionalMessageInputProps:s}),F&&t.jsx(w.MessageBounceModal,{MessageBouncePrompt:G,onClose:()=>B(!1),open:F}),t.jsxs("div",{className:Ps,"data-message-id":c.id,"data-dd-privacy":"mask",children:[A&&t.jsx(A,{}),!!z&&t.jsx(V,{reminder:z}),c.user&&t.jsx(le,{className:"str-chat__avatar str-chat__message-sender-avatar",id:c.user.id,image:c.user.image,name:c.user.name||c.user.id,size:24,shape:"circle",dmAgentEnabled:de}),t.jsx("div",{className:S("str-chat__message-inner",{"str-chat__simple-message--error-failed":ht||ft}),"data-testid":"message-inner",onClick:ce,onKeyDown:ce,role:ce?"button":void 0,tabIndex:ce?0:void 0,style:{marginInlineEnd:0,marginInlineStart:0},children:xt?t.jsx(Oe,{message:c,standalone:!0}):ka(c)?t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsxs("div",{className:"flex items-center gap-2",children:[K&&k&&t.jsx(k,{}),K?t.jsx(fe,{...pt,isMine:!0}):t.jsx(fe,{...pt,isMine:!1,isUnlocking:_(c.id),onUnlockClick:()=>C==null?void 0:C(c,b)}),!K&&k&&t.jsx(k,{})]})}):Ea(c)?t.jsxs("div",{className:"str-chat__message-bubble-wrapper",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[K&&k&&t.jsx(k,{}),K?t.jsx(fe,{...bt,isMine:!0,onPreviewClick:()=>C?C(c,b):void 0}):t.jsx(fe,{...bt,isMine:!1,isUnlocking:_(c.id),onUnlockClick:()=>C?C(c,b):void 0,onDownloadClick:()=>R?R(c,b):void 0}),!K&&k&&t.jsx(k,{})]}),c.text&&t.jsx("div",{className:"str-chat__message-bubble",children:t.jsx(w.MessageText,{message:te,renderText:v})})]}):Fs?t.jsx(dr,{groupPosition:se,isMyMessage:K,message:{...te,attachments:U,i18n:void 0},renderText:v}):t.jsx("div",{className:"str-chat__message-bubble-wrapper",children:t.jsxs("div",{className:"str-chat__message-bubble",children:[de&&!gt&&t.jsx(Oe,{message:c,hasAttachment:Re,isMyMessage:K}),Le&&t.jsx(w.Poll,{poll:Le}),U!=null&&U.length&&!c.quoted_message?t.jsx(I,{actionHandler:o,attachments:U}):null,Y?t.jsx(N,{message:te,renderText:v}):t.jsx(w.MessageText,{message:te,renderText:v}),t.jsx(w.MessageErrorIcon,{})]})})}),!Os&&!xt&&t.jsxs("div",{className:"str-chat__message-footer",children:[(!de||gt)&&t.jsx(Oe,{message:c,hasAttachment:Re,isMyMessage:K}),n&&de&&t.jsx(Ns,{selected:P,onVoteUp:E,onVoteDown:M})]}),t.jsx(Aa,{}),re&&t.jsx(W,{onClick:d,reply_count:c.reply_count}),ne&&t.jsx(q,{})]},c.id)]})},mr=m.memo(ur,(e,s)=>e.chatbotVotingEnabled!==s.chatbotVotingEnabled||e.viewerLanguage!==s.viewerLanguage?!1:w.areMessageUIPropsEqual(e,s)),hr=e=>{const s=w.useMessageContext("CustomMessage");return t.jsx(mr,{...s,...e})},fr=()=>{var n;const{handleDelete:e,message:s}=w.useMessageContext("CustomMessageActions");return((n=s.metadata)==null?void 0:n.payment_status)==="paid"?null:t.jsx(He.DefaultDropdownActionButton,{onClick:e,"aria-label":"Delete",title:"Delete",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:t.jsx(y.TrashSimpleIcon,{size:16,weight:"light","aria-hidden":!0})})},xr=()=>{const{handleFlag:e}=w.useMessageContext("CustomMessageActions");return t.jsx(He.DefaultDropdownActionButton,{onClick:e,"aria-label":"Report",title:"Report",className:"bg-marble rounded-full p-2 hover:bg-sand transition-all",children:t.jsx(y.FlagIcon,{size:16,weight:"light","aria-hidden":!0})})},gr=()=>{var s;const{message:e}=w.useMessageContext("CustomMessageActions");return((s=e.metadata)==null?void 0:s.custom_type)!==Z.MESSAGE_CUSTOM_TYPE.ATTACHMENT?null:t.jsx(He.MessageActions,{messageActionSet:[{Component:fr,placement:"quick",type:"delete"},{Component:xr,placement:"quick",type:"flag"}]})},pr=e=>({linkPreviews:Array.from(e.previews.values()).filter(s=>ye.LinkPreviewsManager.previewIsLoaded(s)||ye.LinkPreviewsManager.previewIsLoading(s))}),br=()=>{const{linkPreviewsManager:e}=w.useMessageComposer(),{linkPreviews:s}=w.useStateStore(e.state,pr),n=r=>{e.dismissPreview(r)};return s.length>0?t.jsx("div",{className:"messaging-link-preview-list flex min-h-0 flex-col items-stretch w-full gap-2 overflow-y-auto overscroll-contain",children:s.map(r=>{const i=ye.LinkPreviewsManager.previewIsLoading(r);return t.jsx("div",{className:"w-full shrink-0",children:t.jsx(Ee.Composer,{title:r.title,url:r.og_scrape_url,thumbnailUrl:r.image_url,layout:i||r.image_url?"featured":"classic",status:i?"loading":"ready",onDismiss:()=>n(r.og_scrape_url)})},r.og_scrape_url)})}):null},Ie=m.createContext(!1),vr=200,jr=()=>m.useContext(Ie),_r=({sendMessage:e,disabled:s,...n})=>t.jsx("button",{...n,type:"button","aria-label":"Send",disabled:s,onPointerDown:a=>a.preventDefault(),onClick:e,children:t.jsx(y.ArrowUpIcon,{weight:"bold",className:"size-4"})}),$t=()=>{const e=m.useContext(Ie),{handleSubmit:s}=w.useMessageInputContext(),n=w.useMessageComposerHasSendableData(),a=e||!n,{SendButton:r=_r,AttachmentPreviewList:i=w.AttachmentPreviewList}=w.useComponentContext("CustomMessageInput");return t.jsxs("div",{className:"central-container flex min-h-0 flex-col min-w-0 w-full self-stretch bg-white rounded-[1.5rem] shadow-[0_4px_16px_0_rgba(0,0,0,0.08),0_1px_2px_0_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.04)] [&>:not(.messaging-composer-previews):not(.messaging-composer-row)]:p-2","data-dd-privacy":"mask",children:[t.jsxs("div",{className:"messaging-composer-previews empty:hidden flex min-h-0 flex-col gap-2 px-2 pt-2",children:[t.jsx(w.QuotedMessagePreview,{}),t.jsx(br,{}),t.jsx(i,{})]}),t.jsxs("div",{className:"messaging-composer-row flex shrink-0 items-start",children:[t.jsx(w.TextareaComposer,{"aria-disabled":e||void 0,containerClassName:"min-w-0 flex-1 leading-[0]",className:"w-full resize-none bg-transparent py-3.5 pl-4 pr-4 outline-none leading-5 placeholder:text-black/30 text-sm",autoFocus:!e,enterKeyHint:"send",maxRows:4,readOnly:e,tabIndex:e?-1:void 0}),t.jsx("div",{className:"mt-auto mb-2 mr-2 shrink-0",children:t.jsx(r,{sendMessage:s,"aria-label":"Send",className:"str-chat__send-button relative flex justify-center items-center rounded-full size-8 bg-[#121110] disabled:bg-[#F1F0EE] disabled:text-black/20 text-white focus-ring before:absolute before:-inset-2 before:content-['']","data-testid":"send-button",disabled:a,type:"button"})})]})]})},Ut=({renderActions:e,renderHeader:s,renderFooter:n,disabled:a=!1,disabledReason:r,composerInput:i})=>{var f;const{channel:l}=w.useChannelStateContext(),o=((f=l==null?void 0:l.data)==null?void 0:f.frozen)===!0,d=!!i,h=m.useRef(null);return m.useEffect(()=>{if(!d)return;const u=h.current,x=u==null?void 0:u.parentElement;if(!u||!x)return;let c=u.offsetHeight;const v=()=>{const p=u.offsetHeight,g=p>c;c=p;const b=Array.from(x.querySelectorAll(".str-chat__list")).find(C=>C.scrollHeight>C.clientHeight)??null,_=b?b.scrollHeight-b.scrollTop-b.clientHeight<vr:!1;x.style.setProperty("--messaging-composer-height",`${p}px`),g&&_&&b&&(b.scrollTop=b.scrollHeight)};if(v(),typeof ResizeObserver>"u")return;const j=new ResizeObserver(v);return j.observe(u),()=>{j.disconnect(),x.style.removeProperty("--messaging-composer-height")}},[d]),a?d?t.jsxs("div",{ref:h,className:"messaging-composer-chrome messaging-composer-chrome--floating",children:[t.jsxs("div",{className:"messaging-composer-backdrop","aria-hidden":"true",children:[t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-gradient"})]}),t.jsxs("div",{className:"relative z-10 flex flex-col",children:[s==null?void 0:s(),t.jsx("div",{className:"messaging-composer-locked-panel flex w-full flex-col items-center justify-center gap-3 px-6 py-4",children:r?t.jsx("p",{className:"max-w-[345px] text-center text-xs font-normal leading-[1.3] tracking-[0.12px] text-black/40",children:r}):null}),n==null?void 0:n()]})]}):t.jsxs(t.Fragment,{children:[s==null?void 0:s(),t.jsx("div",{className:"messaging-composer-locked-panel flex w-full flex-col items-center justify-center gap-3 px-6 py-4",children:r?t.jsx("p",{className:"max-w-[345px] text-center text-xs font-normal leading-[1.3] tracking-[0.12px] text-black/40",children:r}):null}),n==null?void 0:n()]}):d?t.jsxs("div",{ref:h,className:"messaging-composer-chrome messaging-composer-chrome--floating",children:[t.jsxs("div",{className:"messaging-composer-backdrop","aria-hidden":"true",children:[t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-blur"}),t.jsx("div",{className:"messaging-composer-backdrop-gradient"})]}),t.jsxs("div",{className:"relative z-10 flex min-h-0 flex-col",children:[s==null?void 0:s(),t.jsxs("div",{className:"flex min-h-0 flex-col gap-4 p-4",children:[t.jsxs("div",{inert:o?"":void 0,"aria-disabled":o||void 0,className:"message-input flex min-h-0 items-end gap-4 aria-disabled:opacity-40",children:[e&&t.jsx("div",{className:"flex h-12 shrink-0 items-center justify-center",children:e()}),t.jsx(Ie.Provider,{value:o,children:t.jsx(w.MessageInput,{Input:i??$t})})]}),n==null?void 0:n()]})]})]}):t.jsxs("div",{className:"flex min-h-0 flex-col gap-4 p-4",children:[s==null?void 0:s(),t.jsxs("div",{inert:o?"":void 0,"aria-disabled":o||void 0,className:"message-input flex min-h-0 items-end gap-4 aria-disabled:opacity-40",children:[e&&t.jsx("div",{className:"flex h-12 shrink-0 items-center justify-center",children:e()}),t.jsx(Ie.Provider,{value:o,children:t.jsx(w.MessageInput,{Input:$t})})]}),n==null?void 0:n()]})},wr=["SYSTEM_DM_AGENT_PAUSED","SYSTEM_DM_AGENT_RESUMED"],Nr={SYSTEM_DM_AGENT_PAUSED:"DM Agent has left the conversation",SYSTEM_DM_AGENT_RESUMED:"DM Agent has rejoined the conversation"},yr=["SYSTEM_AGE_SAFETY_BLOCKED"],Cr=["SYSTEM_AGE_SAFETY_BLOCKED"],Sr={SYSTEM_AGE_SAFETY_BLOCKED:"This user isn’t able to reply because they don’t meet our age safety guidelines."},Be="age safety guidelines.",kr="https://linktr.ee/s/about/contact",Vt=e=>wr.includes(e),Er=e=>yr.includes(e),Ir=e=>Cr.includes(e),Tr=e=>{var s;return Ir((s=e.metadata)==null?void 0:s.custom_type)},Mr=e=>{var a;const s=(a=e.metadata)==null?void 0:a.custom_type;if(Vt(s))return{kind:"dm-agent",type:s};if(Er(s))return{kind:"age-safety",type:s};const n=e.dm_agent_system_type;if(Vt(n))return{kind:"dm-agent",type:n}},Ar=e=>{const s=e.indexOf(Be);if(s===-1)return e;const n=s+Be.length;return t.jsxs(t.Fragment,{children:[e.slice(0,s),t.jsx("a",{href:kr,target:"_blank",rel:"noopener noreferrer",className:"mes-age-safety-system-message__emphasis font-medium text-inherit underline",children:Be}),e.slice(n)]})},Lr=e=>{var a,r;const s=!Tr(e.message),n=Mr(e.message);if((n==null?void 0:n.kind)==="dm-agent"){const i=((a=e.message.text)==null?void 0:a.trim())||Nr[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(y.SparkleIcon,{size:16,weight:"regular","aria-hidden":!0,className:"mes-dm-agent-system-message__sparkle shrink-0"}),t.jsx("p",{className:"mes-dm-agent-system-message__text m-0 text-center text-[14px] font-normal leading-5 tracking-[0.21px]",children:i})]}),!s&&t.jsx(w.MessageTimestamp,{message:e.message})]})}if((n==null?void 0:n.kind)==="age-safety"){const i=((r=e.message.text)==null?void 0:r.trim())||Sr[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(y.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:Ar(i)})})]}),!s&&t.jsx(w.MessageTimestamp,{message:e.message})]})}return t.jsxs("div",{className:"str-chat__message--system","data-testid":"message-system",children:[t.jsxs("div",{className:"str-chat__message--system__text",children:[t.jsx("div",{className:"str-chat__message--system__line"}),t.jsx("p",{children:e.message.text}),t.jsx("div",{className:"str-chat__message--system__line"})]}),!s&&t.jsx(w.MessageTimestamp,{message:e.message})]})},Es=m.createContext(!1),$e=({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"})}),Rr=new Set([w.AIStates.Thinking,w.AIStates.Generating,w.AIStates.ExternalSources]),Dr=({threadList:e})=>{var v,j;const{channel:s,channelConfig:n,thread:a}=w.useChannelStateContext(),{client:r}=w.useChatContext(),{typing:i={}}=w.useTypingContext(),{aiState:l}=w.useAIState(s),o=m.useContext(Es);if(!e&&o&&Rr.has(l)){const p=Pr(s,(v=r.user)==null?void 0:v.id);return t.jsx(Gt,{avatarId:(p==null?void 0:p.id)??"ai-agent",avatarName:(p==null?void 0:p.name)??(p==null?void 0:p.id)??"Agent",avatarImage:p==null?void 0:p.image,testId:"typing-indicator-ai"})}if((n==null?void 0:n.typing_events)===!1)return null;const h=e?[]:Object.values(i).filter(({parent_id:p,user:g})=>{var b;return(g==null?void 0:g.id)!==((b=r.user)==null?void 0:b.id)&&!p}),f=e?Object.values(i).filter(({parent_id:p,user:g})=>{var b;return(g==null?void 0:g.id)!==((b=r.user)==null?void 0:b.id)&&p===(a==null?void 0:a.id)}):[],u=e?f:h;if(!u.length)return null;const x=(j=u[0])==null?void 0:j.user,c=x!=null&&x.id&&s.state.members[x.id]?s.state.members[x.id].user:void 0;return t.jsx(Gt,{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"})},Gt=({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(le,{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($e,{cx:"4",index:0}),t.jsx($e,{cx:"16",index:1}),t.jsx($e,{cx:"28",index:2})]})})})})})})]})});function Pr(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 Is=()=>null,Or=({className:e,message:s})=>t.jsxs("div",{className:S("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})]}),Te=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(Or,{className:"w-6 h-6"}),t.jsx("span",{className:"text-sm text-stone",children:"Loading messages"})]})}));Te.displayName="LoadingState";const Fr=({onBack:e,showBackButton:s,renderMessageInputActions:n,renderMessageInputFooter:a,renderConversationFooter:r,onLeaveConversation:i,onBlockParticipant:l,showDeleteConversation:o=!0,onDeleteConversationClick:d,onBlockParticipantClick:h,onReportParticipantClick:f,showBlockParticipant:u=!0,showReportParticipant:x=!0,composerDisabled:c=!1,composerDisabledReason:v,showStarButton:j=!1,chatbotVotingEnabled:p=!1,renderChannelBanner:g,customChannelActions:b,renderChannelActions:_,renderMessage:C,viewerLanguage:L,showChannelInfo:R=!0,onParticipantNameClick:F,composerInput:B})=>{const{channel:z}=w.useChannelStateContext(),P=z.state.messages.some(T=>T.type!=="deleted"),E=g?t.jsx(m.Fragment,{children:g()},"lt-channel-banner"):null,M=t.jsx(Zs,{className:"-mx-[var(--str-chat\\_\\_spacing-2)] px-[var(--str-chat\\_\\_spacing-2)] md:-mx-[min(var(--str-chat\\_\\_spacing-10),4%)] md:px-[min(var(--str-chat\\_\\_spacing-10),4%)]",onBack:e,showBackButton:s,showChannelInfo:R,showStarButton:j,onLeaveConversation:i,onBlockParticipant:l,showDeleteConversation:o,showBlockParticipant:u,showReportParticipant:x,onDeleteConversationClick:d,onBlockParticipantClick:h,onReportParticipantClick:f,customChannelActions:b,renderChannelActions:_,onParticipantNameClick:F}),I=m.useCallback(T=>{const{message:k}=w.useMessageContext("ChannelView"),O=t.jsx(hr,{...T,chatbotVotingEnabled:p,viewerLanguage:L});return!C||!k?O:C(O,k)},[p,C,L]);return t.jsx(t.Fragment,{children:t.jsx(w.WithComponents,{overrides:{Message:I,MessageActions:gr,UnreadMessagesNotification:()=>null,UnreadMessagesSeparator:()=>null},children:t.jsx(w.Window,{children:B?t.jsxs("div",{className:"messaging-channel-layout relative flex min-h-0 flex-1 flex-col",children:[t.jsxs("div",{className:"messaging-channel-message-list messaging-channel-message-list--floating relative min-h-0 flex-1 overflow-hidden",children:[!P&&t.jsx("div",{className:"str-chat__list",children:t.jsxs("div",{className:"str-chat__message-list-scroll",children:[M,E]})}),t.jsx(w.MessageList,{head:P?t.jsxs("div",{className:"sticky top-0 z-10",children:[M,E]}):void 0,hideDeletedMessages:!0,hideNewMessageSeparator:!1})]},"lt-channel-message-list"),t.jsx(Ut,{...n&&{renderActions:()=>n==null?void 0:n(z)},...r&&{renderHeader:()=>r(z)},renderFooter:()=>a==null?void 0:a(z),disabled:c,disabledReason:v,composerInput:B},"lt-channel-message-input")]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[!P&&t.jsx("div",{className:"str-chat__list",children:t.jsxs("div",{className:"str-chat__message-list-scroll",children:[M,E]})}),t.jsx(w.MessageList,{head:P?t.jsxs("div",{className:"sticky top-0 z-10",children:[M,E]}):void 0,hideDeletedMessages:!0,hideNewMessageSeparator:!1})]},"lt-channel-message-list"),r?t.jsx(m.Fragment,{children:r(z)},"lt-channel-conversation-footer"):null,t.jsx(Ut,{...n&&{renderActions:()=>n==null?void 0:n(z)},renderFooter:()=>a==null?void 0:a(z),disabled:c,disabledReason:v,composerInput:B},"lt-channel-message-input")]})})})})},mt=m.memo(({channel:e,onBack:s,showBackButton:n=!1,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:l,onBlockParticipant:o,className:d,CustomChannelEmptyState:h=Is,showDeleteConversation:f=!0,onDeleteConversationClick:u,onBlockParticipantClick:x,onReportParticipantClick:c,showBlockParticipant:v=!0,showReportParticipant:j=!0,composerDisabled:p=!1,composerDisabledReason:g,dmAgentEnabled:b,messageMetadata:_,onMessageSent:C,showStarButton:L=!1,chatbotVotingEnabled:R=!1,renderChannelBanner:F,customChannelActions:B,renderChannelActions:z,renderMessage:P,onMessageLinkClick:E,sendButton:M,attachmentPreviewList:I,viewerLanguage:T,showChannelInfo:k=!0,onParticipantNameClick:O,composerInput:G})=>{const H=m.useCallback(async(W,V,N)=>{var X;const A=((X=e.data)==null?void 0:X.chatbot_paused)===!0,$=b&&!A,J={...V,...$&&{silent:!0},..._&&{metadata:{...V.metadata??{},..._}}},Y={...N,...$&&{skip_push:!0}},U=await e.sendMessage(J,Y);return C==null||C(U),U},[e,b,_,C]),q=m.useRef(null);return m.useEffect(()=>{if(!E)return;const W=q.current;if(!W)return;const V=N=>{const A=N.target,$=A==null?void 0:A.closest("a[href]"),J=$==null?void 0:$.getAttribute("href");if(!J)return;const Y=$==null?void 0:$.closest("[data-message-id]"),U=Y==null?void 0:Y.getAttribute("data-message-id"),X=U?e.state.messages.find(te=>te.id===U):void 0;E(J,X)};return W.addEventListener("click",V),()=>W.removeEventListener("click",V)},[E,e]),t.jsx("div",{ref:q,className:S("messaging-channel-view h-full flex flex-col",d),children:t.jsx(Es.Provider,{value:b??!1,children:t.jsx(w.Channel,{channel:e,MessageSystem:Lr,EmptyStateIndicator:h,LoadingIndicator:Te,DateSeparator:Js,TypingIndicator:Dr,doSendMessageRequest:H,...M?{SendButton:M}:{},...I?{AttachmentPreviewList:I}:{},children:t.jsx(Fr,{onBack:s,showBackButton:n,renderMessageInputActions:a,renderMessageInputFooter:r,renderConversationFooter:i,onLeaveConversation:l,onBlockParticipant:o,CustomChannelEmptyState:h,showDeleteConversation:f,onDeleteConversationClick:u,onBlockParticipantClick:x,onReportParticipantClick:c,showBlockParticipant:v,showReportParticipant:j,composerDisabled:p,composerDisabledReason:g,showStarButton:L,chatbotVotingEnabled:R,renderChannelBanner:F,customChannelActions:B,renderChannelActions:z,renderMessage:P,viewerLanguage:T,showChannelInfo:k,onParticipantNameClick:O,composerInput:G})})})})});mt.displayName="ChannelView";const xe=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"})]})}));xe.displayName="ErrorState";const zr=({capabilities:e={},renderMessageInputActions:s,renderConversationFooter:n,onChannelSelect:a,onExitConversation:r,initialParticipantFilter:i,initialParticipantData:l,CustomChannelEmptyState:o,onBlockParticipantClick:d,onReportParticipantClick:h,dmAgentEnabled:f,onMessageSent:u,chatbotVotingEnabled:x=!1,viewerLanguage:c,renderChannelBanner:v,customChannelActions:j,renderChannelActions:p,onParticipantNameClick:g,renderMessage:b,onMessageLinkClick:_,showChannelInfo:C,composerInput:L})=>{const{client:R,isConnected:F,isLoading:B,error:z,refreshConnection:P,service:E,debug:M}=qt(),[I,T]=m.useState(null),[k,O]=m.useState(null),[G,H]=m.useState(!1),{showDeleteConversation:q=!0}=e,W=m.useRef(l);W.current=l;const V=m.useRef(a);V.current=a;const N=m.useRef(null),A=m.useRef(null);m.useEffect(()=>{A.current=I},[I]),m.useEffect(()=>{if(!R||!F)return;const Y=R.userID;if(!Y)return;const U=`${Y}::${i}`;if(N.current===U)return;N.current=U;const X=()=>{N.current===U&&(N.current=null)};(async()=>{var _e,we;try{M&&console.log("[MessagingShell] Loading initial conversation with:",i);const se=await R.queryChannels({type:"messaging",members:{$eq:[Y,i]}},{},{limit:1});if(se.length>0){T(se[0]),O(null),(_e=V.current)==null||_e.call(V,se[0]),M&&console.log("[MessagingShell] Initial conversation loaded:",se[0].id);return}const re=W.current;if(!re||!E){X(),O("No conversation found with this account"),M&&console.log("[MessagingShell] No conversation found for:",i);return}try{const ne=await E.startChannelWithParticipant({id:re.id,name:re.name,phone:re.phone});T(ne),O(null),(we=V.current)==null||we.call(V,ne),M&&console.log("[MessagingShell] Channel created and loaded:",ne.id)}catch(ne){console.error("[MessagingShell] Failed to create conversation:",ne),X(),O("Failed to create conversation")}}catch(se){console.error("[MessagingShell] Failed to load initial conversation:",se),X(),A.current||O("Failed to load conversation")}})()},[i,R,F,E,M]);const $=m.useRef(r);$.current=r;const J=m.useCallback(()=>{var Y;T(null),H(!0),(Y=$.current)==null||Y.call($)},[]);return B?t.jsx(Te,{}):z?t.jsx(xe,{message:z,onBack:P}):!F||!R?t.jsx(xe,{message:"Not connected to messaging service",onBack:P}):k?t.jsx(xe,{message:k}):G&&!I?t.jsx(xe,{message:"Conversation ended"}):I?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(mt,{channel:I,renderMessageInputActions:s,renderConversationFooter:n,renderChannelBanner:v,onLeaveConversation:J,onBlockParticipant:J,CustomChannelEmptyState:o,showDeleteConversation:q,onBlockParticipantClick:d,onReportParticipantClick:h,dmAgentEnabled:f,onMessageSent:u,chatbotVotingEnabled:x,viewerLanguage:c,customChannelActions:j,renderChannelActions:p,onParticipantNameClick:g,renderMessage:b,onMessageLinkClick:_,showChannelInfo:C,composerInput:L},I.id)})}):t.jsx(Te,{})};function Br(e){const s=e.state.pending_messages;if(s!=null&&s.length)for(const n of s)e.state.addMessageSorted(n.message)}const Ts=m.createContext({selectedChannel:void 0,onChannelSelect:()=>{},debug:!1,renderMessagePreview:void 0,channelPreview:void 0,viewerLanguage:void 0}),$r=Ts.Provider,Ur=()=>m.useContext(Ts),Vr=(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))},Ms=e=>{const s=new Date;if(Math.floor((s.getTime()-e.getTime())/1e3)<60)return"Just now";const a=Vr(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(void 0,{day:"numeric",month:"short",year:"2-digit"})},As=m.memo(e=>{var B,z,P;const{channel:s,unread:n}=e,{selectedChannel:a,onChannelSelect:r,debug:i,channelPreview:l,renderMessagePreview:o,viewerLanguage:d}=Ur(),{client:h}=w.useChatContext(),f=(a==null?void 0:a.id)===(s==null?void 0:s.id),u=Wt(s);if(l){const E=l;return t.jsx(E,{...e,active:f,selectedChannel:a,onChannelSelect:r,viewerLanguage:d})}const x=()=>{s&&r(s)},c=E=>{const M=E.key==="Enter"||E.key===" ",I=E.repeat;!M||I||(E.preventDefault(),x())},v=qe((B=s==null?void 0:s.state)==null?void 0:B.members,h==null?void 0:h.userID,s==null?void 0:s.type),j=We(v==null?void 0:v.user),p=(z=v==null?void 0:v.user)==null?void 0:z.image,g=(()=>{var M;const E=(M=s==null?void 0:s.state)==null?void 0:M.messages;if(E!=null&&E.length){for(let I=E.length-1;I>=0;I--)if(E[I].type!=="system")return E[I]}})(),_=(()=>{var k;const E=Xe({message:g,viewerLanguage:d}),{custom_type:M,attachment_content_type:I}=(g==null?void 0:g.metadata)||{};if(M===Z.MESSAGE_CUSTOM_TYPE.TIP)return E||"Sent a tip";if(M===Z.MESSAGE_CUSTOM_TYPE.PAID)return E||"Sent a message";if(M===Z.MESSAGE_CUSTOM_TYPE.ATTACHMENT){if(I==="text")return"🔒 Sent a locked message";if(I==="media")return"🔒 Sent a locked attachment"}if(E)return E;const T=(k=g==null?void 0:g.attachments)==null?void 0:k[0];return T?T.og_scrape_url?T.og_scrape_url:T.type==="image"?"📷 Sent an image":T.type==="video"?"🎥 Sent a video":T.type==="audio"?"🎵 Sent audio":T.type==="file"?"📎 Sent a file":"📎 Sent an attachment":"No messages yet"})(),C=g!=null&&g.created_at?Ms(new Date(g.created_at)):"",L=g?Ce(g):!1,R=o?o(g,_):`${L?"✨ ":""}${_}`,F=n??0;return i&&console.log("📺 [ChannelList] 📋 CHANNEL PREVIEW RENDER",{channelId:s==null?void 0:s.id,isSelected:f,participantName:j,unreadCount:F,hasTimestamp:!!C}),t.jsx("div",{role:"button",tabIndex:0,onClick:x,onKeyDown:c,className:S("group w-full px-4 py-3 transition-colors text-left max-w-full overflow-hidden focus-ring rounded-[12px] [&+&]:mt-2",{"bg-black/[0.04]":f,"hover:bg-black/[0.02]":!f}),"data-dd-privacy":"mask",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx(le,{id:((P=v==null?void 0:v.user)==null?void 0:P.id)||s.id||"unknown",name:j,image:p,size:48,starred:u}),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:S("text-sm font-medium truncate text-[#191918]"),children:[u&&t.jsx("span",{className:"sr-only",children:"Starred conversation. "}),j]}),C&&t.jsx("span",{className:"text-xs text-[#717070] flex-shrink-0",children:C})]}),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:R}),F>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:F>99?"99+":F})]})]})]})})});As.displayName="CustomChannelPreview";const Gr={last_message_at:-1},Ls=m.memo(({onChannelSelect:e,selectedChannel:s,filters:n,allowNewMessagesFromUnfilteredChannels:a=!1,channelRenderFilterFn:r,sort:i=Gr,className:l,customEmptyStateIndicator:o,channelListPaginator:d=w.InfiniteScroll,channelPreview:h,renderMessagePreview:f,viewerLanguage:u,lockChannelOrder:x,onMessageNewHandler:c,onMessageNew:v,onChannelVisible:j,onAddedToChannel:p,onChannelUpdated:g})=>{const b=m.useRef(0);b.current++;const{debug:_=!1}=Ye(),C=m.useCallback(R=>{for(const F of R)Br(F);return r?r(R):R},[r]);_&&console.log("📺 [ChannelList] 🔄 RENDER START",{renderCount:b.current,selectedChannelId:s==null?void 0:s.id,filters:n});const L=m.useMemo(()=>({selectedChannel:s,onChannelSelect:e,debug:_,channelPreview:h,renderMessagePreview:f,viewerLanguage:u}),[s,e,_,h,f,u]);return t.jsx("div",{className:S("messaging-channel-list h-full flex flex-col min-w-0 overflow-hidden",l),children:t.jsx("div",{className:"flex-1 overflow-hidden min-w-0",children:t.jsx($r,{value:L,children:t.jsx(w.ChannelList,{filters:n,sort:i,options:{limit:30},allowNewMessagesFromUnfilteredChannels:a,channelRenderFilterFn:C,lockChannelOrder:x,onMessageNewHandler:c,onMessageNew:v,onChannelVisible:j,onAddedToChannel:p,onChannelUpdated:g,Paginator:d,Preview:As,EmptyStateIndicator:o},`${JSON.stringify(n)}:${JSON.stringify(i)}`)})})})});Ls.displayName="ChannelList";const Ht=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='23' fill='none'%3E%3Cpath fill='black' d='M0 0H15C15 10.1934 15.859 15.2345 19.168 21.4893C19.527 22.168 19.039 22.9917 18.274 22.9178C5.176 21.6506 0.32 6.0737 0 0Z'/%3E%3C/svg%3E") no-repeat center / 100% 100%`,Hr={sent:"var(--str-chat__own-message-bubble-background-color, #1e2330)",received:"var(--str-chat__message-bubble-background-color, #f1f0ee)"},Yr=({variant:e})=>t.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute bottom-0 z-[-1] h-[1.4375rem] w-5",style:{insetInlineEnd:e==="sent"?"calc(-1 * 0.25rem)":void 0,insetInlineStart:e==="received"?"calc(-1 * 0.25rem)":void 0,transform:e==="received"?"scaleX(-1)":void 0,transformOrigin:"center",backgroundColor:Hr[e],WebkitMask:Ht,mask:Ht}}),qr={sent:{backgroundColor:"var(--str-chat__own-message-bubble-background-color, #1e2330)",color:"var(--str-chat__own-message-bubble-color, #fff)"},received:{backgroundColor:"var(--str-chat__message-bubble-background-color, #f1f0ee)",color:"var(--str-chat__message-bubble-color, #000000)"}},Rs=({variant:e,text:s,tail:n=!0,header:a,className:r})=>t.jsxs("div",{"data-dd-privacy":"mask",className:S("relative px-4 py-3","text-[0.875rem] leading-[1.3125rem] tracking-[0.14px]",r),style:{...qr[e],borderRadius:"var(--str-chat__message-bubble-border-radius, 1.5rem)",isolation:"isolate"},children:[a!=null&&t.jsx("div",{className:"mb-1 font-medium","data-testid":"message-bubble-header",children:a}),t.jsx("p",{className:"m-0 whitespace-pre-wrap break-words",children:s}),n&&t.jsx(Yr,{variant:e})]}),Wr=({text:e,tail:s,header:n,className:a})=>t.jsx(Rs,{variant:"received",text:e,tail:s,header:n,className:a}),Xr=({text:e,tail:s,className:n})=>t.jsx(Rs,{variant:"sent",text:e,tail:s,className:n}),Kr={Sent:Xr,Received:Wr},Ds=({question:e,onClick:s,loading:n=!1,className:a})=>t.jsx("button",{type:"button",onClick:s,disabled:n,style:{backgroundColor:"#E6E5E3"},className:S("w-full text-center p-4 rounded-xl text-charcoal font-medium transition-colors focus-ring",{"hover:brightness-95 active:brightness-90":!n,"opacity-50 cursor-not-allowed":n},a),children:e}),Zr=({faqs:e,onFaqClick:s,loadingFaqId:n,headerText:a,className:r,avatarImage:i,avatarName:l})=>{const o=Z.selectEnabledFaqs(e);return o.length===0?null:t.jsx("div",{className:r,children:t.jsxs("div",{className:"flex gap-3 items-end",children:[(i||l)&&t.jsx("div",{className:"flex-none",children:t.jsx(le,{id:l||"account",name:l||"Account",image:i,size:24,shape:"circle"})}),t.jsxs("div",{className:"flex-1 flex flex-col gap-3 rounded-lg p-4",style:{backgroundColor:"#F1F0EE"},children:[a&&t.jsx("p",{className:"text-md text-charcoal mb-4",children:a}),o.map(d=>t.jsx(Ds,{question:d.question,onClick:()=>s(d.id),loading:n===d.id},d.id))]})]})})};exports.ActionButton=me;exports.AttachmentThumbnail=Ke;exports.Avatar=le;exports.ChannelEmptyState=Is;exports.ChannelList=Ls;exports.ChannelView=mt;exports.CustomMessageProvider=_a;exports.FaqList=Zr;exports.FaqListItem=Ds;exports.LinkAttachment=Ee;exports.LockedAttachment=fe;exports.MediaMessage=_n;exports.MessageAttachment=he;exports.MessageBubble=Kr;exports.MessageVoteButtons=Ns;exports.MessagingProvider=Bs;exports.MessagingShell=zr;exports.bubbleGroupPositionFromStream=as;exports.buildCompactMetaLabel=os;exports.formatFileSize=rs;exports.formatRelativeTime=Ms;exports.getFileExtensionLabel=is;exports.getMessageDisplayText=Xe;exports.getSourceType=ee;exports.isLinkAttachment=Qe;exports.isUuidLike=Xt;exports.normalizeLanguageCode=Jt;exports.optimizeMessagingAttachmentUrl=ae;exports.renderTypeIcon=oe;exports.resolveConversationParticipant=qe;exports.resolveLinkAttachment=Me;exports.resolveMediaFromMessage=Ae;exports.resolveParticipantDisplayName=We;exports.useComposerLocked=jr;exports.useCustomMessage=js;exports.useMessageVote=Zt;exports.useMessaging=qt;
2
- //# sourceMappingURL=index-CcUtwsNq.cjs.map