@sendbird/ai-agent-messenger-react 1.1.2 → 1.2.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.
@@ -0,0 +1,4090 @@
1
+ import * as r from "react";
2
+ import { createContext as Se, useContext as te, useEffect as N, useState as _, useId as fn, useRef as F, useCallback as U, useLayoutEffect as ae, forwardRef as Le, useImperativeHandle as vr, Suspense as Me, lazy as S, useMemo as ye, Component as Cr, Fragment as Pt, useReducer as yr, Children as _r } from "react";
3
+ import Tr, { SendbirdProduct as Sr, DeviceOsPlatform as Bt, SendbirdPlatform as wr, ConnectionHandler as Je, SendbirdError as kr, SessionHandler as Ar, LogLevel as bn, ConnectionState as Ir } from "@sendbird/chat";
4
+ import m, { css as I, ThemeProvider as $r, useTheme as bt, createGlobalStyle as Mr, StyleSheetManager as Or, keyframes as xn } from "styled-components";
5
+ import { format as En, isSameMinute as Ft, isSameDay as Lr } from "date-fns";
6
+ import { enUS as Rr } from "date-fns/locale/en-US";
7
+ import { AIAgentModule as Nr, ConversationStatus as W, ConversationType as Dr } from "@sendbird/chat/aiAgent";
8
+ import { useGroupChannelMessages as Pr, useGroupChannelHandler as vn, useForceUpdate as Br } from "@sendbird/uikit-tools";
9
+ import { GroupChannelModule as Fr, GroupChannelListOrder as Cn, GroupChannelHandler as Ur } from "@sendbird/chat/groupChannel";
10
+ import { MessageMetaArray as Hr, SendingStatus as zr } from "@sendbird/chat/message";
11
+ import { isSameDay as Vr } from "date-fns/isSameDay";
12
+ import { renderer as Wr, parser as Gr, MessageProvider as jr } from "@sendbird/react-uikit-message-template-view";
13
+ import { createMessageTemplate as Zr } from "@sendbird/uikit-message-template";
14
+ import yn from "dompurify";
15
+ import { createPortal as Kr } from "react-dom";
16
+ import Yr from "@emotion/is-prop-valid";
17
+ const j = (e, t) => {
18
+ const n = Se(null), o = ({ children: s, value: l }) => /* @__PURE__ */ r.createElement(n.Provider, { value: l }, typeof s == "function" ? s(l) : s), i = ({ children: s }) => /* @__PURE__ */ r.createElement(n.Consumer, null, (l) => l ? typeof s == "function" ? s(l) : s : null), a = () => {
19
+ const s = te(n);
20
+ if (!s)
21
+ throw new Error(`use${e}Context must be used within a ${e}Provider`);
22
+ return s;
23
+ };
24
+ return n.displayName = `${e}Context`, o.displayName = `${e}Provider`, i.displayName = `${e}Consumer`, a.displayName = `use${e}Context`, { Context: n, Provider: o, Consumer: i, useContext: a };
25
+ };
26
+ function we(e) {
27
+ const t = Se({
28
+ Template: e.template,
29
+ updateTemplate: () => {
30
+ },
31
+ components: e.components,
32
+ updateComponent: () => {
33
+ }
34
+ });
35
+ function n({ children: a }) {
36
+ const [s, l] = _(() => e.template), [c, d] = _(e.components), u = {
37
+ Template: s,
38
+ updateTemplate: (p) => l(() => p),
39
+ components: c,
40
+ updateComponent: (p, g) => d((b) => ({ ...b, [p]: g }))
41
+ };
42
+ return /* @__PURE__ */ r.createElement(t.Provider, { value: u }, a);
43
+ }
44
+ function o({ template: a, children: s }) {
45
+ const { updateTemplate: l } = te(t);
46
+ return N(() => {
47
+ a && l(a);
48
+ }, [a]), /* @__PURE__ */ r.createElement(r.Fragment, null, s);
49
+ }
50
+ function i({ children: a }) {
51
+ return /* @__PURE__ */ r.createElement(n, null, a);
52
+ }
53
+ return i.defaults = e, i.useContext = () => te(t), i.Context = t, i.Template = o, Object.keys(e.components).forEach((a) => {
54
+ i[a] = function({
55
+ component: l
56
+ }) {
57
+ const { updateComponent: c } = te(t);
58
+ return N(() => {
59
+ l && c(a, l);
60
+ }, [l]), null;
61
+ };
62
+ }), i;
63
+ }
64
+ function qr(...e) {
65
+ return function({ children: n }) {
66
+ return e.reduce((o, i) => /* @__PURE__ */ r.createElement(i, null, o), n);
67
+ };
68
+ }
69
+ function ct() {
70
+ }
71
+ function Jr() {
72
+ const e = /iPad|iPhone|iPod/.test(navigator.userAgent), t = /Android/.test(navigator.userAgent);
73
+ return e || t;
74
+ }
75
+ class _n {
76
+ constructor(t) {
77
+ this.logger = t, this.subscribers = {};
78
+ }
79
+ async send(t) {
80
+ const n = Xr(), o = this.subscribers[t.type];
81
+ if (o) {
82
+ this.logger.debug(`messenger.dispatcher: dispatching command: ${t.type}`, t.payload);
83
+ const i = o.map((a) => a(t.payload));
84
+ await Promise.all(i).catch((a) => {
85
+ this.logger.error(`messenger.dispatcher: error in callback for command: ${t.type}`, a);
86
+ });
87
+ }
88
+ return n.resolve(), n.promise;
89
+ }
90
+ subscribe(t, n) {
91
+ this.subscribers[t] || (this.subscribers[t] = []), this.subscribers[t].push(n);
92
+ }
93
+ unsubscribe(t, n) {
94
+ this.subscribers[t] && (this.subscribers[t] = this.subscribers[t].filter((o) => o !== n));
95
+ }
96
+ }
97
+ const Xr = () => {
98
+ let e = ct, t = ct;
99
+ return { promise: new Promise((o, i) => {
100
+ e = o, t = i;
101
+ }), resolve: e, reject: t };
102
+ }, Qr = "1.2.0", Ie = "sb-agent", eo = Qr;
103
+ var Tn = /* @__PURE__ */ ((e) => (e[e.VERBOSE = 0] = "VERBOSE", e[e.DEBUG = 1] = "DEBUG", e[e.INFO = 2] = "INFO", e[e.WARN = 3] = "WARN", e[e.ERROR = 4] = "ERROR", e[e.NONE = 5] = "NONE", e))(Tn || {});
104
+ class Sn {
105
+ constructor(t) {
106
+ this.level = t;
107
+ }
108
+ verbose(...t) {
109
+ this.level <= 0 && console.log(`[${Ie}/verbose]`, ...t);
110
+ }
111
+ debug(...t) {
112
+ this.level <= 1 && console.log(`[${Ie}/debug]`, ...t);
113
+ }
114
+ info(...t) {
115
+ this.level <= 2 && console.log(`[${Ie}/info]`, ...t);
116
+ }
117
+ warn(...t) {
118
+ this.level <= 3 && console.warn(`[${Ie}/warn]`, ...t);
119
+ }
120
+ error(...t) {
121
+ this.level <= 4 && console.error(`[${Ie}/error]`, ...t);
122
+ }
123
+ }
124
+ function Ut(e, t, n) {
125
+ const o = Tr.init({
126
+ appId: e,
127
+ modules: [new Fr(), new Nr()],
128
+ localCacheEnabled: !0,
129
+ ...n
130
+ });
131
+ return o.addSendbirdExtensions(
132
+ [{ version: eo, product: Sr.AI_AGENT, platform: t.platform }],
133
+ { platform: t.deviceOSPlatform, version: t.deviceOSVersion },
134
+ t.customData
135
+ ) || console.warn("Invalid Sendbird Extensions", t), o;
136
+ }
137
+ const {
138
+ Provider: to,
139
+ useContext: Xe
140
+ } = j("AIAgent");
141
+ function no({
142
+ appId: e,
143
+ aiAgentId: t,
144
+ language: n,
145
+ countryCode: o,
146
+ context: i,
147
+ chatSDK: a,
148
+ chatParams: s,
149
+ dispatcher: l,
150
+ logger: c,
151
+ children: d,
152
+ extensions: u = {
153
+ platform: wr.JS,
154
+ deviceOSPlatform: Jr() ? Bt.MOBILE_WEB : Bt.WEB
155
+ }
156
+ }) {
157
+ const [p, g] = _(() => {
158
+ const b = c ?? new Sn(Tn.WARN), x = l ?? new _n(b);
159
+ return {
160
+ appId: e,
161
+ aiAgentId: t,
162
+ language: n,
163
+ countryCode: o,
164
+ context: i,
165
+ chatSDK: a ?? Ut(e, u, s),
166
+ logger: b,
167
+ dispatcher: x
168
+ };
169
+ });
170
+ return (n !== p.language || o !== p.countryCode) && g((b) => ({ ...b, language: n, countryCode: o, context: i })), a && a !== p.chatSDK ? g((b) => ({ ...b, aiAgentId: t, chatSDK: a })) : !a && p.chatSDK.appId !== e && g((b) => ({
171
+ ...b,
172
+ aiAgentId: t,
173
+ chatSDK: Ut(e, u, { newInstance: !0, ...s })
174
+ })), N(() => () => {
175
+ p.chatSDK.disconnectWebSocket();
176
+ }, [p.chatSDK]), /* @__PURE__ */ r.createElement(to, { value: p }, d);
177
+ }
178
+ const ro = (e, t, n) => Pr(e, t, { ...n, strictStreamingOrder: !0 });
179
+ var dt = /* @__PURE__ */ ((e) => (e.ConversationClose = "conv.close", e))(dt || {});
180
+ class oo {
181
+ constructor(t = {}) {
182
+ this.payload = t;
183
+ }
184
+ toJSON() {
185
+ return JSON.stringify({ type: this.type, payload: this.payload });
186
+ }
187
+ }
188
+ const io = {
189
+ CloseConversation: (e) => new so(e)
190
+ };
191
+ class so extends oo {
192
+ constructor() {
193
+ super(...arguments), this.type = "conv.close";
194
+ }
195
+ }
196
+ const {
197
+ Provider: ao
198
+ } = j("AIAgentConversation");
199
+ function lo({
200
+ children: e,
201
+ channelUrl: t,
202
+ onChannelDeleted: n,
203
+ onMessagesUpdated: o,
204
+ onConversationClosedViaDispatcher: i,
205
+ onBeforeSendMessage: a,
206
+ onAfterSendMessage: s = ct
207
+ }) {
208
+ var E;
209
+ const { chatSDK: l, logger: c, dispatcher: d } = Xe(), { channel: u, channelFetchError: p, fetchChannel: g } = co(t), b = ro(l, u, {
210
+ shouldCountNewMessages: () => !1,
211
+ onChannelDeleted: n,
212
+ onMessagesReceived: o,
213
+ onMessagesUpdated: o,
214
+ logger: c
215
+ });
216
+ N(() => {
217
+ const f = async (v) => {
218
+ const y = typeof (v == null ? void 0 : v.channelUrl) == "string";
219
+ u && y && v.channelUrl !== u.url || (c.debug("conversation.dispatcher: try to close conversation", u), u != null && u.conversation && u.conversation.status === W.OPEN && (await u.closeConversation(), i == null || i()));
220
+ };
221
+ return d.subscribe(dt.ConversationClose, f), () => {
222
+ d.unsubscribe(dt.ConversationClose, f);
223
+ };
224
+ }, [d, (E = u == null ? void 0 : u.conversation) == null ? void 0 : E.status, i]);
225
+ const x = {
226
+ conversation: (u == null ? void 0 : u.conversation) ?? void 0,
227
+ channelSource: {
228
+ channel: u,
229
+ error: p,
230
+ refetch: () => g()
231
+ },
232
+ messageSource: {
233
+ messages: b.messages,
234
+ initialized: b.initialized,
235
+ loadPrevious: () => b.loadPrevious(),
236
+ loadNext: () => b.loadNext(),
237
+ sendUserMessage: async (f) => {
238
+ var y;
239
+ if (((y = u == null ? void 0 : u.conversation) == null ? void 0 : y.status) === W.CLOSED)
240
+ throw new Error("Conversation is closed");
241
+ a && (f = await a(f));
242
+ const v = await b.sendUserMessage(f, s);
243
+ return s == null || s(v), v;
244
+ },
245
+ sendFileMessage: async (f) => {
246
+ var y;
247
+ if (((y = u == null ? void 0 : u.conversation) == null ? void 0 : y.status) === W.CLOSED)
248
+ throw new Error("Conversation is closed");
249
+ a && (f = await a(f));
250
+ const v = await b.sendFileMessage(f, s);
251
+ return s == null || s(v), v;
252
+ }
253
+ }
254
+ };
255
+ return /* @__PURE__ */ r.createElement(ao, { value: x }, e);
256
+ }
257
+ function co(e) {
258
+ const { chatSDK: t, logger: n } = Xe(), [o, i] = _(void 0), [a, s] = _(void 0);
259
+ async function l() {
260
+ if (n.debug("conversation.fetchChannel: start"), i(void 0), s(void 0), e)
261
+ try {
262
+ n.debug("conversation.fetchChannel: get channel", e);
263
+ const c = await t.groupChannel.getChannel(e);
264
+ i(c);
265
+ const d = new Je({ onReconnectSucceeded: () => c.refresh() });
266
+ t.addConnectionHandler("sba-refresh", d), n.debug("conversation.fetchChannel: fetched channel", c);
267
+ } catch (c) {
268
+ c instanceof kr && s(c), n.error("conversation.fetchChannel: error", c);
269
+ }
270
+ }
271
+ return N(() => {
272
+ l();
273
+ }, [e, t]), {
274
+ channel: o,
275
+ channelFetchError: a,
276
+ fetchChannel: l
277
+ };
278
+ }
279
+ class uo {
280
+ /**
281
+ * Creates a new ConversationListCollection instance.
282
+ * @param sdk - The Sendbird Chat SDK instance
283
+ * @param params - Configuration parameters for the collection
284
+ */
285
+ constructor(t, { filter: n, limit: o = 20 }) {
286
+ var i, a, s, l, c;
287
+ this._isDisposed = !1, this._handlerId = `handler-id-${Date.now()}`, this._order = Cn.LATEST_LAST_MESSAGE, this.filter = n, this._sdk = t, this._pinnedChannels = [], this._channels = [], this._limit = o, this._query = this._sdk.aiAgent.createMyGroupChannelListQuery({
288
+ aiAgentChannelFilter: (i = this.filter) == null ? void 0 : i.aiAgentChannelFilter,
289
+ aiAgentConversationStatusFilter: (a = this.filter) == null ? void 0 : a.aiAgentConversationStatusFilter,
290
+ aiAgentIds: (s = this.filter) == null ? void 0 : s.aiAgentIds,
291
+ deskChannelFilter: (l = this.filter) == null ? void 0 : l.deskChannelFilter,
292
+ pinnedChannelUrls: (c = this.filter) == null ? void 0 : c.pinnedChannelUrls,
293
+ limit: this._limit
294
+ }), this._token = "", this._timestamp = Number.MAX_SAFE_INTEGER, this._isSyncing = !1, this._channelHandler = new Ur({
295
+ onChannelChanged: (d) => {
296
+ d.isGroupChannel() && (this._query.belongsTo(d) ? this._addChannelsToView([d], !1) : this._removeChannelsFromView([d.url]));
297
+ },
298
+ onChannelDeleted: (d) => {
299
+ this._removeChannelsFromView([d]);
300
+ }
301
+ }), this._connectionHandler = new Je({
302
+ onReconnectSucceeded: () => {
303
+ this._isDefaultChangelogSyncTimestampUpdated && this._syncChannelChangelogs();
304
+ }
305
+ }), this._sdk.addConnectionHandler(this._handlerId, this._connectionHandler), this._sdk.groupChannel.addGroupChannelHandler(this._handlerId, this._channelHandler);
306
+ }
307
+ /**
308
+ * Checks if the default changelog sync timestamp has been updated.
309
+ */
310
+ get _isDefaultChangelogSyncTimestampUpdated() {
311
+ return this._timestamp !== Number.MAX_SAFE_INTEGER;
312
+ }
313
+ /**
314
+ * Sets the default changelog sync timestamp based on the first non-pinned channel.
315
+ * @param channels - Array of channels to analyze
316
+ */
317
+ _setDefaultChangelogsSyncTimestamp(t) {
318
+ var a, s;
319
+ const n = new Set(((a = this.filter) == null ? void 0 : a.pinnedChannelUrls) ?? []), o = t.find((l) => !n.has(l.url));
320
+ let i;
321
+ o ? i = ((s = o.lastMessage) == null ? void 0 : s.createdAt) ?? o.createdAt : i = this._query.lastResponseAt, this._timestamp > i && (this._timestamp = i);
322
+ }
323
+ /**
324
+ * Synchronizes channel changelogs to keep the collection up-to-date.
325
+ * @returns Promise that resolves to an empty array
326
+ */
327
+ async _syncChannelChangelogs() {
328
+ if (this._isDisposed) return [];
329
+ if (this._isSyncing) return [];
330
+ try {
331
+ this._isSyncing = !0;
332
+ let t;
333
+ for (this._token ? t = await this._sdk.aiAgent.getMyGroupChannelChangeLogsByToken(this._token, this.filter) : t = await this._sdk.aiAgent.getMyGroupChannelChangeLogsByTimestamp(this._timestamp, this.filter), this._token = t.token, this._addChannelsToView(t.updatedChannels), this._removeChannelsFromView(t.deletedChannelUrls); t.hasMore && t.token; )
334
+ t = await this._sdk.aiAgent.getMyGroupChannelChangeLogsByToken(this._token, this.filter), this._token = t.token, this._addChannelsToView(t.updatedChannels), this._removeChannelsFromView(t.deletedChannelUrls);
335
+ } catch {
336
+ } finally {
337
+ this._isSyncing = !1;
338
+ }
339
+ return [];
340
+ }
341
+ /**
342
+ * Upserts pinned channels maintaining the order specified in pinnedChannelUrls.
343
+ * @param channels - Pinned channels to upsert
344
+ * @returns Object containing added, updated channels and unmatched URLs
345
+ */
346
+ _upsertPinnedChannelsToArray(t) {
347
+ var l;
348
+ const n = ((l = this.filter) == null ? void 0 : l.pinnedChannelUrls) ?? [], o = new Map(n.map((c, d) => [c, d])), i = [], a = [], s = [];
349
+ for (const c of t) {
350
+ if (!this._query.belongsTo(c)) {
351
+ s.push(c.url);
352
+ continue;
353
+ }
354
+ const d = o.get(c.url);
355
+ if (d === void 0) continue;
356
+ const u = ut(this._pinnedChannels, c);
357
+ u >= 0 ? (this._pinnedChannels.splice(u, 1), a.push(c)) : i.push(c);
358
+ const g = this._pinnedChannels.findIndex((x) => (o.get(x.url) ?? 1 / 0) > d), b = g === -1 ? this._pinnedChannels.length : g;
359
+ this._pinnedChannels.splice(b, 0, c);
360
+ }
361
+ return { addedChannels: i, updatedChannels: a, unmatchedChannelUrls: s };
362
+ }
363
+ /**
364
+ * Upserts regular (non-pinned) channels with time-based sorting.
365
+ * @param channels - Regular channels to upsert
366
+ * @param forceAppend - Whether to force append channels at the end regardless of hasMore status
367
+ * @returns Object containing added, updated channels and unmatched URLs
368
+ */
369
+ _upsertRegularChannelsToArray(t, n = !1) {
370
+ const o = [], i = [], a = [];
371
+ for (const s of t) {
372
+ if (!this._query.belongsTo(s)) {
373
+ o.push(s.url);
374
+ continue;
375
+ }
376
+ const l = ut(this._channels, s), c = l < 0;
377
+ !c && this._channels.splice(l, 1);
378
+ const u = mo(this._channels, s, this._order).place, p = u === this._channels.length;
379
+ c ? p ? (n || !this.hasMore) && (this._channels.push(s), i.push(s)) : (this._channels.splice(u, 0, s), i.push(s)) : (this._channels.splice(u, 0, s), a.push(s));
380
+ }
381
+ return { addedChannels: i, updatedChannels: a, unmatchedChannelUrls: o };
382
+ }
383
+ /**
384
+ * Adds or updates channels in the collection, separating pinned and non-pinned channels.
385
+ * @param channels - Channels to add or update
386
+ * @param forceAppend - Whether to force append channels at the end
387
+ */
388
+ _addChannelsToView(t, n = !1) {
389
+ var p, g, b, x, E;
390
+ const o = new Set(((p = this.filter) == null ? void 0 : p.pinnedChannelUrls) ?? []), i = [], a = [];
391
+ for (const f of t)
392
+ o.has(f.url) ? i.push(f) : a.push(f);
393
+ const s = this._upsertPinnedChannelsToArray(i), l = this._upsertRegularChannelsToArray(a, n), c = s.addedChannels.concat(l.addedChannels), d = s.updatedChannels.concat(l.updatedChannels), u = s.unmatchedChannelUrls.concat(l.unmatchedChannelUrls);
394
+ c.length > 0 && ((b = (g = this._collectionEventHandler) == null ? void 0 : g.onChannelsAdded) == null || b.call(g, c)), d.length > 0 && ((E = (x = this._collectionEventHandler) == null ? void 0 : x.onChannelsUpdated) == null || E.call(x, d)), u.length > 0 && this._removeChannelsFromView(u);
395
+ }
396
+ /**
397
+ * Removes channels from the collection by their URLs.
398
+ * @param channelUrls - Array of channel URLs to remove
399
+ */
400
+ _removeChannelsFromView(t) {
401
+ var i, a, s;
402
+ const n = new Set(((i = this.filter) == null ? void 0 : i.pinnedChannelUrls) ?? []), o = [];
403
+ for (const l of t)
404
+ if (n.has(l)) {
405
+ const c = this._pinnedChannels.findIndex((d) => d.url === l);
406
+ c >= 0 && (o.push(l), this._pinnedChannels.splice(c, 1));
407
+ } else {
408
+ const c = this._channels.findIndex((d) => d.url === l);
409
+ c >= 0 && (o.push(l), this._channels.splice(c, 1));
410
+ }
411
+ o.length > 0 && ((s = (a = this._collectionEventHandler) == null ? void 0 : a.onChannelsDeleted) == null || s.call(a, o));
412
+ }
413
+ /**
414
+ * Gets all channels in the collection.
415
+ * Pinned channels are always returned first, followed by non-pinned channels.
416
+ * @returns Array of GroupChannel objects
417
+ */
418
+ get channels() {
419
+ return this._isDisposed ? [] : [...this._pinnedChannels, ...this._channels];
420
+ }
421
+ /**
422
+ * Indicates whether the collection has more channels to load.
423
+ * @returns True if more channels can be loaded, false otherwise
424
+ */
425
+ get hasMore() {
426
+ return this._isDisposed ? !1 : this._query.hasNext;
427
+ }
428
+ /**
429
+ * Loads the next batch of channels from the server.
430
+ * @returns Promise that resolves to an array of newly loaded channels
431
+ */
432
+ async loadMore() {
433
+ if (this._isDisposed) return [];
434
+ if (this.hasMore) {
435
+ const t = await this._query.next();
436
+ return this._setDefaultChangelogsSyncTimestamp(t), this._addChannelsToView(t, !0), t;
437
+ }
438
+ return [];
439
+ }
440
+ /**
441
+ * Sets the event handler for collection updates.
442
+ * @param handler - Event handler for channel collection changes
443
+ */
444
+ setGroupChannelCollectionHandler(t) {
445
+ this._collectionEventHandler = t;
446
+ }
447
+ /**
448
+ * Disposes the collection and cleans up all resources.
449
+ * Stops all event handlers and clears all channels.
450
+ */
451
+ dispose() {
452
+ this._isDisposed || (this._isDisposed = !0, this._collectionEventHandler = void 0, this._sdk.removeConnectionHandler(this._handlerId), this._sdk.groupChannel.removeGroupChannelHandler(this._handlerId), this._pinnedChannels.length = 0, this._channels.length = 0);
453
+ }
454
+ }
455
+ const ut = (e, t) => e.findIndex((n) => n.isIdentical(t)), mo = (e, t, n) => {
456
+ if (e.length > 0) {
457
+ const o = ut(e, t);
458
+ let i = 0, a = e.length - 1, s = Math.floor((i + a) / 2);
459
+ for (; i < a; ) {
460
+ const c = Ht(e[s], t, n);
461
+ if (c > 0)
462
+ a = s, s = Math.floor((i + a) / 2);
463
+ else if (c < 0)
464
+ i = s + 1, s = Math.floor((i + a) / 2);
465
+ else
466
+ return { place: s, oldPosition: o };
467
+ }
468
+ return { place: Ht(e[s], t, n) >= 0 ? s : s + 1, oldPosition: o };
469
+ }
470
+ return { place: e.length, oldPosition: -1 };
471
+ }, Ht = (e, t, n) => {
472
+ switch (n) {
473
+ case Cn.LATEST_LAST_MESSAGE:
474
+ if (e.lastMessage && t.lastMessage) {
475
+ const o = t.lastMessage.createdAt - e.lastMessage.createdAt;
476
+ return o === 0 ? t.createdAt - e.createdAt : o;
477
+ } else return e.lastMessage ? -1 : t.lastMessage ? 1 : t.createdAt - e.createdAt;
478
+ default:
479
+ return 0;
480
+ }
481
+ };
482
+ function ho(e, t) {
483
+ var x, E, f, v, y, $, T, Y;
484
+ const n = fn(), [o, i] = _(!1), [a, s] = _(null), [l, c] = _([]), [d, u] = _(null), p = F(!1), g = U(async () => {
485
+ if (!p.current && e.currentUser) {
486
+ p.current = !0, i(!1), s(null), c([]);
487
+ try {
488
+ d == null || d.dispose();
489
+ const L = new uo(e, t);
490
+ L.setGroupChannelCollectionHandler({
491
+ onChannelsAdded: () => {
492
+ c(L.channels);
493
+ },
494
+ onChannelsUpdated: () => {
495
+ c(L.channels);
496
+ },
497
+ onChannelsDeleted: () => {
498
+ c(L.channels);
499
+ }
500
+ }), await L.loadMore(), u(L), s(null);
501
+ } catch (L) {
502
+ u(null), s(L);
503
+ } finally {
504
+ i(!0), p.current = !1;
505
+ }
506
+ }
507
+ }, [
508
+ e,
509
+ (x = t.filter) == null ? void 0 : x.aiAgentChannelFilter,
510
+ (f = (E = t.filter) == null ? void 0 : E.aiAgentConversationStatusFilter) == null ? void 0 : f.join(),
511
+ (y = (v = t.filter) == null ? void 0 : v.aiAgentIds) == null ? void 0 : y.join(),
512
+ ($ = t.filter) == null ? void 0 : $.deskChannelFilter,
513
+ (Y = (T = t.filter) == null ? void 0 : T.pinnedChannelUrls) == null ? void 0 : Y.join(),
514
+ t.limit
515
+ ]), b = U(async () => {
516
+ if (d)
517
+ try {
518
+ await d.loadMore();
519
+ } catch (L) {
520
+ s(L);
521
+ }
522
+ }, [d]);
523
+ return N(() => (e.addConnectionHandler(n, new Je({ onConnected: () => g() })), () => e.removeConnectionHandler(n)), [e, n, g]), N(() => {
524
+ g();
525
+ }, [g]), N(() => () => {
526
+ p.current = !1, d == null || d.dispose();
527
+ }, [d]), {
528
+ initialized: o,
529
+ error: a,
530
+ channels: l,
531
+ loadMore: b
532
+ };
533
+ }
534
+ const {
535
+ Provider: go
536
+ } = j("AIAgentConversationList");
537
+ function po({ conversationListFilter: e, children: t }) {
538
+ const { chatSDK: n, aiAgentId: o } = Xe(), i = ho(n, {
539
+ filter: {
540
+ aiAgentIds: [o],
541
+ aiAgentConversationStatusFilter: [W.CLOSED],
542
+ ...e
543
+ }
544
+ }), a = {
545
+ listSource: {
546
+ initialized: i.initialized,
547
+ error: i.error ?? void 0,
548
+ channels: i.channels,
549
+ loadMore: () => i.loadMore()
550
+ }
551
+ };
552
+ return /* @__PURE__ */ r.createElement(go, { value: a }, t);
553
+ }
554
+ const mt = {
555
+ DEFAULT_BOT_MSG_BG: "#eeeeee",
556
+ WHITE: "#ffffff",
557
+ BLACK: "#000000"
558
+ };
559
+ function wn(e) {
560
+ return e.length === 4 ? `#${[...e.slice(1)].map((t) => t + t).join("")}` : e;
561
+ }
562
+ function fo(e) {
563
+ const t = wn(e);
564
+ return [
565
+ parseInt(t.slice(1, 3), 16),
566
+ // r
567
+ parseInt(t.slice(3, 5), 16),
568
+ // g
569
+ parseInt(t.slice(5, 7), 16)
570
+ // b
571
+ ];
572
+ }
573
+ function bo(e) {
574
+ return `#${e.map((t) => t.toString(16).padStart(2, "0")).join("")}`;
575
+ }
576
+ function xo(e, t, n) {
577
+ e /= 255, t /= 255, n /= 255;
578
+ const o = Math.max(e, t, n), i = Math.min(e, t, n), a = o - i;
579
+ let s = 0, l = 0;
580
+ const c = (o + i) / 2;
581
+ return o !== i && (l = c > 0.5 ? a / (2 - o - i) : a / (o + i)), o === e ? s = (t - n) / a + (t < n ? 6 : 0) : o === t ? s = (n - e) / a + 2 : o === n && (s = (e - t) / a + 4), s /= 6, [s, l, c];
582
+ }
583
+ function Eo(e, t, n) {
584
+ let o, i, a;
585
+ if (t === 0)
586
+ o = i = a = n;
587
+ else {
588
+ const s = function(u, p, g) {
589
+ return g < 0 && (g += 1), g > 1 && (g -= 1), g < 0.16666666666666666 ? u + (p - u) * 6 * g : g < 0.5 ? p : g < 0.6666666666666666 ? u + (p - u) * (0.6666666666666666 - g) * 6 : u;
590
+ }, l = n < 0.5 ? n * (1 + t) : n + t - n * t, c = 2 * n - l;
591
+ o = s(c, l, e + 1 / 3), i = s(c, l, e), a = s(c, l, e - 1 / 3);
592
+ }
593
+ return [Math.round(o * 255), Math.round(i * 255), Math.round(a * 255)];
594
+ }
595
+ function Fe(e, t, n) {
596
+ const [o, i, a] = fo(e), [s, l, c] = xo(o, i, a), d = Math.max(0, Math.min(1, c * t)), u = Math.max(0, Math.min(1, l * n)), [p, g, b] = Eo(s, u, d);
597
+ return bo([Math.round(p), Math.round(g), Math.round(b)]);
598
+ }
599
+ function vo(e, t = "light") {
600
+ return {
601
+ extraDark: Fe(e, 0.6, 1.2),
602
+ dark: Fe(e, 0.85, 1.1),
603
+ main: e,
604
+ light: Fe(e, t === "dark" ? 1.1 : 1.5, t === "dark" ? 0.95 : 0.9),
605
+ extraLight: Fe(e, t === "dark" ? 1.2 : 1.75, t === "dark" ? 0.9 : 0.8)
606
+ };
607
+ }
608
+ function ht(e) {
609
+ const t = wn(e), n = 149, o = +`0x${t[1]}${t[2]}`, i = +`0x${t[3]}${t[4]}`, a = +`0x${t[5]}${t[6]}`;
610
+ return o * 0.299 + i * 0.587 + a * 0.114 > n ? mt.BLACK : mt.WHITE;
611
+ }
612
+ function Co(e, t, n, o, i) {
613
+ return {
614
+ base: {
615
+ primary: t,
616
+ primaryContrastContent: n,
617
+ background: e.background50,
618
+ headerBackground: e.background50,
619
+ modalContentBackground: e.background50
620
+ },
621
+ metadata: {
622
+ errorContent: e.ondark.textHighEmphasis,
623
+ placeholderText: e.onlight.textLowEmphasis
624
+ },
625
+ messageInput: {
626
+ background: e.background100
627
+ },
628
+ messageIncoming: {
629
+ text: i,
630
+ background: o
631
+ },
632
+ messageOutgoing: {
633
+ text: n,
634
+ background: t
635
+ },
636
+ csat: {
637
+ background: e.background100
638
+ }
639
+ };
640
+ }
641
+ const yo = (e, t, n, o, i) => ({
642
+ base: {
643
+ primary: t,
644
+ primaryContrastContent: n,
645
+ background: e.background600,
646
+ headerBackground: e.background500,
647
+ modalContentBackground: e.background500
648
+ },
649
+ metadata: {
650
+ errorContent: e.ondark.textHighEmphasis,
651
+ placeholderText: e.ondark.textLowEmphasis
652
+ },
653
+ messageInput: {
654
+ background: e.background400
655
+ },
656
+ messageIncoming: {
657
+ text: i,
658
+ background: o
659
+ },
660
+ messageOutgoing: {
661
+ text: n,
662
+ background: t
663
+ },
664
+ csat: {
665
+ background: e.background400
666
+ }
667
+ }), Ue = {
668
+ primary: {
669
+ extraDark: "#491389",
670
+ dark: "#6211c8",
671
+ main: "#742ddd",
672
+ light: "#c2a9fa",
673
+ extraLight: "#dbd1ff"
674
+ },
675
+ secondary: {
676
+ extraDark: "#066858",
677
+ dark: "#027d69",
678
+ main: "#259c72",
679
+ light: "#69c085",
680
+ extraLight: "#a8e2ab"
681
+ },
682
+ error: {
683
+ extraDark: "#9d091e",
684
+ dark: "#bf0711",
685
+ main: "#de360b",
686
+ light: "#f66161",
687
+ extraLight: "#fdaaaa"
688
+ },
689
+ information: {
690
+ extraDark: "#241389",
691
+ dark: "#362ca9",
692
+ main: "#4a48cd",
693
+ light: "#a9bbfa",
694
+ extraLight: "#d1dbff"
695
+ },
696
+ background700: "#000000",
697
+ background600: "#161616",
698
+ background500: "#2c2c2c",
699
+ background400: "#393939",
700
+ background300: "#bdbdbd",
701
+ background200: "#e0e0e0",
702
+ background100: "#eeeeee",
703
+ background50: "#ffffff",
704
+ onlight: {
705
+ textHighEmphasis: "rgba(0, 0, 0, 0.88)",
706
+ textMidEmphasis: "rgba(0, 0, 0, 0.5)",
707
+ textLowEmphasis: "rgba(0, 0, 0, 0.38)",
708
+ textDisabled: "rgba(0, 0, 0, 0.12)"
709
+ },
710
+ ondark: {
711
+ textHighEmphasis: "rgba(255, 255, 255, 0.88)",
712
+ textMidEmphasis: "rgba(255, 255, 255, 0.5)",
713
+ textLowEmphasis: "rgba(255, 255, 255, 0.38)",
714
+ textDisabled: "rgba(255, 255, 255, 0.12)"
715
+ },
716
+ overlay: {
717
+ dark: "rgba(0, 0, 0, 0.55)",
718
+ light: "rgba(22, 22, 22, 0.32)"
719
+ }
720
+ }, it = {
721
+ h1: { fontSize: 18, fontWeight: 700 },
722
+ h2: { fontSize: 16, fontWeight: 700 },
723
+ subtitle1: { fontSize: 16, fontWeight: 500 },
724
+ subtitle2: { fontSize: 16, fontWeight: 400 },
725
+ body1: { fontSize: 16, fontWeight: 400 },
726
+ body2: { fontSize: 14, fontWeight: 500 },
727
+ body3: { fontSize: 14, fontWeight: 400 },
728
+ button: { fontSize: 14, fontWeight: 700 },
729
+ caption1: { fontSize: 12, fontWeight: 700 },
730
+ caption2: { fontSize: 12, fontWeight: 400 },
731
+ caption3: { fontSize: 11, fontWeight: 700 },
732
+ caption4: { fontSize: 11, fontWeight: 400 }
733
+ };
734
+ function zt(e) {
735
+ const t = _o(e), { colors: n, aiAgentColorVariables: o } = To(e, t), i = wo(e);
736
+ return {
737
+ selectedTheme: e.selectedTheme,
738
+ palette: t,
739
+ colors: n,
740
+ aiAgentColorVariables: o,
741
+ typography: i
742
+ };
743
+ }
744
+ function _o({ selectedTheme: e, palette: t, primary: n }) {
745
+ const o = t != null && t.primary ? t.primary : n ? n === Ue.primary.main ? Ue.primary : vo(n, e) : Ue.primary;
746
+ return {
747
+ ...Ue,
748
+ primary: o,
749
+ ...t
750
+ };
751
+ }
752
+ function To({ selectedTheme: e, primaryContrast: t, botMessageBackground: n, botMessageBackgroundContrast: o }, i) {
753
+ const a = i.primary.main, s = t ?? ht(a), l = n ?? mt.DEFAULT_BOT_MSG_BG, c = o ?? ht(l);
754
+ return {
755
+ colors: (e === "light" ? Co : yo)(
756
+ i,
757
+ a,
758
+ s,
759
+ l,
760
+ c
761
+ ),
762
+ aiAgentColorVariables: {
763
+ primary_color: a,
764
+ bot_message_bg_color: l,
765
+ primary_contrast_color: s,
766
+ bot_message_bg_contrast_color: c
767
+ }
768
+ };
769
+ }
770
+ function So(e, t, n) {
771
+ const o = { ...e };
772
+ return n.forEach((i) => {
773
+ const a = t[i];
774
+ a != null && (o[i] = a);
775
+ }), o;
776
+ }
777
+ function wo({ typography: e }) {
778
+ if (!e)
779
+ return it;
780
+ const t = { ...it };
781
+ return Object.keys(e).forEach((n) => {
782
+ const o = e[n];
783
+ if (o && typeof o == "object") {
784
+ const i = it[n], a = ["fontSize", "fontWeight", "fontFamily", "lineHeight"];
785
+ t[n] = So(i, o, a);
786
+ }
787
+ }), t;
788
+ }
789
+ const {
790
+ Provider: ko,
791
+ useContext: kn
792
+ } = j("AIAgentTheme");
793
+ function Ao({ logger: e, palette: t, typography: n, appearance: o, children: i }) {
794
+ const [a, s] = _(
795
+ () => zt({
796
+ selectedTheme: (o == null ? void 0 : o.theme) ?? "light",
797
+ palette: t,
798
+ typography: n,
799
+ primary: o == null ? void 0 : o.primaryColor,
800
+ botMessageBackground: o == null ? void 0 : o.botMessageBackgroundColor
801
+ })
802
+ ), l = U(
803
+ (c, d) => {
804
+ const u = (o == null ? void 0 : o.theme) ?? c, p = d == null ? void 0 : d(u), g = {
805
+ primary: o == null ? void 0 : o.primaryColor,
806
+ primaryContrast: void 0,
807
+ botMessageBackground: o == null ? void 0 : o.botMessageBackgroundColor,
808
+ botMessageBackgroundContrast: void 0
809
+ };
810
+ !g.primary && (p != null && p.primaryColor) && (g.primary = p.primaryColor, g.primaryContrast = p.primaryContrastColor), !g.botMessageBackground && (p != null && p.botMessageBackgroundColor) && (g.botMessageBackground = p.botMessageBackgroundColor, g.botMessageBackgroundContrast = p.botMessageBackgroundContrastColor);
811
+ const b = zt({ selectedTheme: u, palette: t, typography: n, ...g });
812
+ s(b), e == null || e.info("theme.update:", u);
813
+ },
814
+ [o == null ? void 0 : o.theme, o == null ? void 0 : o.primaryColor, o == null ? void 0 : o.botMessageBackgroundColor, t, n, e]
815
+ );
816
+ return N(() => {
817
+ (o != null && o.theme || o != null && o.primaryColor || o != null && o.botMessageBackgroundColor) && l(a.selectedTheme);
818
+ }, [o == null ? void 0 : o.theme, o == null ? void 0 : o.primaryColor, o == null ? void 0 : o.botMessageBackgroundColor]), /* @__PURE__ */ r.createElement(ko, { value: { theme: a, updateTheme: l } }, i);
819
+ }
820
+ const An = (e) => {
821
+ try {
822
+ const t = JSON.parse(e);
823
+ return typeof t == "string" ? JSON.stringify(t).slice(1, -1) : e.trim();
824
+ } catch {
825
+ return JSON.stringify(e).slice(1, -1);
826
+ }
827
+ }, Re = (e) => JSON.parse(e), Qe = (e) => JSON.parse(e);
828
+ function Io(e, t) {
829
+ const [n, o] = t.split(",").map((i) => i.trim());
830
+ return e === "dark" && o || n;
831
+ }
832
+ function $o(e) {
833
+ const t = {};
834
+ function n(o, i = "") {
835
+ for (const [a, s] of Object.entries(o)) {
836
+ const l = i ? `${i}.${a}` : a;
837
+ s && typeof s == "object" && !Array.isArray(s) ? n(s, l) : t[l] = s;
838
+ }
839
+ }
840
+ return n(e), t;
841
+ }
842
+ function xt({
843
+ template: e,
844
+ variables: t,
845
+ variableKeyPattern: n,
846
+ variableValueTransformer: o
847
+ }) {
848
+ return Object.entries(t).reduce((i, [a, s]) => {
849
+ if (!o && !["number", "boolean", "string"].includes(typeof s))
850
+ throw new Error("If transformer is not provided, value must be a {string, number, or boolean}");
851
+ const l = o ? o(s) : String(s), c = n(a);
852
+ return i.replace(c, An(l));
853
+ }, e);
854
+ }
855
+ async function Mo({
856
+ template: e,
857
+ variables: t,
858
+ variableKeyPattern: n,
859
+ variableValueTransformer: o
860
+ }) {
861
+ return (await Promise.all(
862
+ Object.entries(t).map(async ([a, s]) => {
863
+ const l = await o(s);
864
+ return { regex: n(a), transformedValue: l };
865
+ })
866
+ )).reduce((a, { regex: s, transformedValue: l }) => a.replace(s, An(l)), e);
867
+ }
868
+ const Oo = (e) => ({
869
+ setTemplate: (t, n) => e.onSetTemplate(t, n),
870
+ getTemplate: (t) => e.onGetTemplate(t),
871
+ setCachedToken: (t) => e.onSetCachedToken(t),
872
+ getCachedToken: () => e.onGetCachedToken(),
873
+ clear: () => e.onClear()
874
+ }), {
875
+ Provider: Lo,
876
+ useContext: In
877
+ } = j("MessageCacheTemplate");
878
+ function Ro({ logger: e, storage: t, children: n }) {
879
+ const o = U(
880
+ (s) => {
881
+ var d, u;
882
+ const l = (u = (d = s.appInfo) == null ? void 0 : d.aiAgentInfo) == null ? void 0 : u.templateListToken;
883
+ if (!l) return !1;
884
+ const c = t.getCachedToken();
885
+ return c ? l !== c : !0;
886
+ },
887
+ [t]
888
+ ), i = U(
889
+ async (s) => {
890
+ try {
891
+ const { templates: l, token: c } = await s.aiAgent.getMessageTemplates({ limit: 20 });
892
+ for (const { template: d } of l) {
893
+ const { key: u } = Re(d);
894
+ t.setTemplate(u, d);
895
+ }
896
+ t.setCachedToken(c);
897
+ } catch (l) {
898
+ e == null || e.error("messageTemplateContext.syncCachedTemplates: error:", l);
899
+ }
900
+ },
901
+ [t, e]
902
+ ), a = U(() => {
903
+ t.clear();
904
+ }, [t]);
905
+ return /* @__PURE__ */ r.createElement(Lo, { value: { shouldSyncCachedTemplate: o, syncCachedTemplates: i, clearCachedTemplates: a, storage: t } }, n);
906
+ }
907
+ function No(e) {
908
+ let t = "pending", n = e.then((o) => {
909
+ t = "resolved", n = o;
910
+ }).catch((o) => {
911
+ t = "rejected", n = o;
912
+ });
913
+ return {
914
+ get value() {
915
+ if (t === "resolved")
916
+ return n;
917
+ throw n;
918
+ }
919
+ };
920
+ }
921
+ const {
922
+ Provider: Do,
923
+ useContext: $n
924
+ } = j("MessageTemplateFetching");
925
+ function Po({ children: e, internalVariables: t }) {
926
+ const n = F({}), o = F({}), [i, a] = _({}), s = U((d, u) => {
927
+ a((p) => ({
928
+ ...p,
929
+ [d]: { fetching: !1, error: !1, ...p[d], ...u }
930
+ }));
931
+ }, []), l = U(
932
+ async ({
933
+ onRequestTemplate: d,
934
+ onGetCachedTemplate: u,
935
+ templateKey: p,
936
+ suspense: g = !1
937
+ }) => {
938
+ const b = u(p);
939
+ if (b) return b;
940
+ const x = o.current[p];
941
+ if (x) return x;
942
+ g || s(p, { fetching: !0 });
943
+ const E = d(p).catch((f) => {
944
+ throw g || s(p, { error: !0 }), f;
945
+ }).finally(() => {
946
+ g || s(p, { fetching: !1 }), delete o.current[p];
947
+ });
948
+ return o.current[p] = E, E;
949
+ },
950
+ [s]
951
+ ), c = {
952
+ internalVariables: t,
953
+ fetchTemplate: l,
954
+ suspend: (d, u) => {
955
+ if (n.current[d])
956
+ return n.current[d];
957
+ const p = No(u());
958
+ return n.current[d] = p, p;
959
+ },
960
+ getIsFetching: (d) => {
961
+ var u;
962
+ return ((u = i[d]) == null ? void 0 : u.fetching) ?? !1;
963
+ },
964
+ getHasError: (d) => {
965
+ var u;
966
+ return ((u = i[d]) == null ? void 0 : u.error) ?? !1;
967
+ }
968
+ };
969
+ return /* @__PURE__ */ r.createElement(Do, { value: c }, e);
970
+ }
971
+ const et = {
972
+ VARIABLE: (e) => new RegExp(`\\{${e}\\}`, "g"),
973
+ VIEW_VARIABLE: (e) => new RegExp(`"{@${e}}"`, "g")
974
+ };
975
+ function le({ uiTemplateString: e, variables: t = {} }) {
976
+ const n = $o(t);
977
+ return xt({
978
+ template: e,
979
+ variables: n,
980
+ variableKeyPattern: (o) => et.VARIABLE(o)
981
+ });
982
+ }
983
+ function ce({
984
+ theme: e,
985
+ uiTemplateString: t,
986
+ colorVariables: n = {}
987
+ }) {
988
+ return xt({
989
+ template: t,
990
+ variables: n,
991
+ variableKeyPattern: (o) => et.VARIABLE(o),
992
+ variableValueTransformer: (o) => Io(e, o)
993
+ });
994
+ }
995
+ function Bo({
996
+ theme: e,
997
+ uiTemplateString: t,
998
+ viewVariables: n = {},
999
+ aiAgentColorVariables: o,
1000
+ internalVariables: i,
1001
+ onRequestTemplate: a
1002
+ }) {
1003
+ const l = Object.values(n).flat().map((d) => d.key);
1004
+ return [...new Set(l)].some((d) => !a(d)) ? null : xt({
1005
+ template: t,
1006
+ variables: n,
1007
+ variableKeyPattern: (d) => et.VIEW_VARIABLE(d),
1008
+ variableValueTransformer: (d) => {
1009
+ const u = d.map(({ key: p, variables: g }) => {
1010
+ const b = a(p), { ui_template: x, color_variables: E } = Re(b);
1011
+ let f = JSON.stringify(x);
1012
+ return f = le({
1013
+ uiTemplateString: f,
1014
+ variables: i
1015
+ }), f = ce({
1016
+ theme: e,
1017
+ uiTemplateString: f,
1018
+ colorVariables: E
1019
+ }), f = ce({
1020
+ theme: e,
1021
+ uiTemplateString: f,
1022
+ colorVariables: o
1023
+ }), f = le({
1024
+ uiTemplateString: f,
1025
+ variables: g
1026
+ }), Qe(f);
1027
+ });
1028
+ return JSON.stringify(u);
1029
+ }
1030
+ });
1031
+ }
1032
+ async function Fo({
1033
+ theme: e,
1034
+ uiTemplateString: t,
1035
+ viewVariables: n = {},
1036
+ aiAgentColorVariables: o,
1037
+ internalVariables: i,
1038
+ onRequestTemplate: a
1039
+ }) {
1040
+ return Mo({
1041
+ template: t,
1042
+ variables: n,
1043
+ variableKeyPattern: (s) => et.VIEW_VARIABLE(s),
1044
+ variableValueTransformer: async (s) => {
1045
+ const l = s.map(async ({ key: d, variables: u }) => {
1046
+ const p = await a(d), { ui_template: g, color_variables: b } = Re(p);
1047
+ let x = JSON.stringify(g);
1048
+ return x = le({
1049
+ uiTemplateString: x,
1050
+ variables: i
1051
+ }), x = ce({
1052
+ theme: e,
1053
+ uiTemplateString: x,
1054
+ colorVariables: b
1055
+ }), x = ce({
1056
+ theme: e,
1057
+ uiTemplateString: x,
1058
+ colorVariables: o
1059
+ }), x = le({
1060
+ uiTemplateString: x,
1061
+ variables: u
1062
+ }), Qe(x);
1063
+ }), c = await Promise.all(l);
1064
+ return JSON.stringify(c);
1065
+ }
1066
+ });
1067
+ }
1068
+ const Uo = ({
1069
+ rawTemplate: e,
1070
+ aiAgentColorVariables: t,
1071
+ internalVariables: n,
1072
+ ...o
1073
+ }) => {
1074
+ const { ui_template: i, color_variables: a } = Re(e);
1075
+ let s = JSON.stringify(i);
1076
+ if (Object.keys(o.viewVariables ?? {}).length > 0) {
1077
+ const c = Bo({
1078
+ ...o,
1079
+ uiTemplateString: s,
1080
+ aiAgentColorVariables: t,
1081
+ internalVariables: n
1082
+ });
1083
+ if (c === null) return null;
1084
+ s = c;
1085
+ }
1086
+ return s = le({ ...o, uiTemplateString: s, variables: n }), s = ce({ ...o, uiTemplateString: s, colorVariables: a }), s = ce({ ...o, uiTemplateString: s, colorVariables: t }), s = le({ ...o, uiTemplateString: s }), Qe(s);
1087
+ }, Ho = async ({
1088
+ rawTemplate: e,
1089
+ aiAgentColorVariables: t,
1090
+ internalVariables: n,
1091
+ ...o
1092
+ }) => {
1093
+ const { ui_template: i, color_variables: a } = Re(e);
1094
+ let s = JSON.stringify(i);
1095
+ return Object.keys(o.viewVariables ?? {}).length > 0 && (s = await Fo({
1096
+ ...o,
1097
+ uiTemplateString: s,
1098
+ aiAgentColorVariables: t,
1099
+ internalVariables: n
1100
+ })), s = le({ ...o, uiTemplateString: s, variables: n }), s = ce({ ...o, uiTemplateString: s, colorVariables: a }), s = ce({ ...o, uiTemplateString: s, colorVariables: t }), s = le({ ...o, uiTemplateString: s }), Qe(s);
1101
+ }, zo = (e) => {
1102
+ const { aiAgentColorVariables: t = {} } = e, { internalVariables: n } = $n();
1103
+ return _(() => {
1104
+ const o = e.onGetCachedTemplate(e.templateKey);
1105
+ return o ? Uo({
1106
+ ...e,
1107
+ rawTemplate: o,
1108
+ aiAgentColorVariables: t,
1109
+ internalVariables: n,
1110
+ onRequestTemplate: e.onGetCachedTemplate
1111
+ }) : null;
1112
+ });
1113
+ }, Vo = (e) => {
1114
+ const [t] = zo(e);
1115
+ if (t) return t;
1116
+ const { aiAgentColorVariables: n = {} } = e, { internalVariables: o, fetchTemplate: i, suspend: a } = $n();
1117
+ return a(e.templateKey, async () => {
1118
+ const l = await i({ ...e, suspense: !0 });
1119
+ return await Ho({
1120
+ ...e,
1121
+ rawTemplate: l,
1122
+ aiAgentColorVariables: n,
1123
+ internalVariables: o
1124
+ });
1125
+ }).value;
1126
+ }, Wo = '@import"https://fonts.googleapis.com/css?family=Roboto:400,500,600,700&display=swap";.sb-message-template__border{position:relative}.sb-message-template__border:after{content:"";position:absolute;top:0;bottom:0;left:0;right:0;z-index:1;box-shadow:inset 0 0 0 var(--border-width) var(--border-color);border-radius:var(--border-radius);pointer-events:none}.sb-message-template__action{cursor:pointer}.sb-message-template__parent{font-family:Roboto,serif}.sb-message-template__text{font-family:inherit;font-size:14px;font-weight:400;font-stretch:normal;font-style:normal;letter-spacing:normal;text-align:left}.sb-message-template__text-button{font-family:inherit;background-color:#e0e0e0;text-align:center;padding:10px;border-radius:6px;font-size:14px;font-weight:600;font-stretch:normal;font-style:normal;letter-spacing:normal}.sendbird-theme--light .sb-message-template__text-button{color:#742ddd}.sendbird-theme--dark .sb-message-template__text-button{color:#c2a9fa}.sb-message-template__text-button:hover{opacity:1;box-shadow:#0000001a 0 1px 3px,#0000000f 0 1px 2px}.sb-message-template__text-button,.sb-message-template__image-button{cursor:pointer;border-style:none}.sb-message-template__parent{border-radius:unset;background-color:transparent;overflow:hidden}.sb-message-template__parent *{box-sizing:border-box;line-height:1.3}.sb-message-template__carousel{display:flex;width:100%;box-sizing:border-box;touch-action:pan-y}', Ne = "en", Go = /* @__PURE__ */ new Set([
1127
+ Ne,
1128
+ "ko",
1129
+ "es",
1130
+ "pt",
1131
+ "fr",
1132
+ "hi",
1133
+ "it",
1134
+ "de",
1135
+ "tr",
1136
+ "ja"
1137
+ ]), jo = (e, t, n) => {
1138
+ const o = e[t];
1139
+ return o ? typeof o == "function" ? o() : Promise.resolve(o) : new Promise((i, a) => {
1140
+ (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(
1141
+ a.bind(
1142
+ null,
1143
+ new Error(
1144
+ "Unknown variable dynamic import: " + t + (t.split("/").length !== n ? ". Note that variables only represent file names one level deep." : "")
1145
+ )
1146
+ )
1147
+ );
1148
+ });
1149
+ }, Zo = Rr, Ko = {
1150
+ // Channel - Common
1151
+ CHANNEL_FROZEN: "Channel frozen",
1152
+ PLACE_HOLDER__WRONG: "Something went wrong",
1153
+ PLACE_HOLDER__NO_MESSAGES: "No messages",
1154
+ UNKNOWN__UNKNOWN_MESSAGE_TYPE: "(Unknown message type)",
1155
+ // Channel - Header
1156
+ HEADER_BUTTON__AGENT_HANDOFF: "Connect with an agent",
1157
+ // Message Input
1158
+ MESSAGE_INPUT__PLACE_HOLDER: "Ask a question",
1159
+ MESSAGE_INPUT__PLACE_HOLDER__WAIT_AI_AGENT_RESPONSE: "Waiting for the agent’s reply…",
1160
+ MESSAGE_INPUT__PLACE_HOLDER__DISABLED: "Chat is unavailable in this channel",
1161
+ // Common UI
1162
+ BUTTON__CANCEL: "Cancel",
1163
+ BUTTON__SAVE: "Save",
1164
+ BUTTON__OK: "OK",
1165
+ NO_NAME: "(No name)",
1166
+ RETRY: "Retry",
1167
+ // Date format
1168
+ DATE_FORMAT__MESSAGE_LIST__DATE_SEPARATOR: "MMMM dd, yyyy",
1169
+ DATE_FORMAT__MESSAGE_TIMESTAMP: "p",
1170
+ // File Upload
1171
+ FILE_UPLOAD_NOTIFICATION__COUNT_LIMIT: "You can't upload more than one image",
1172
+ FILE_UPLOAD_NOTIFICATION__SIZE_LIMIT: "The maximum size per file is %d MB.",
1173
+ // File Viewer
1174
+ FILE_VIEWER__UNSUPPORT: "Unsupported message",
1175
+ // CSAT
1176
+ CSAT_TITLE_UNSUBMITTED: "Your feedback matters to us",
1177
+ CSAT_TITLE_SUBMITTED: "Successfully submitted!",
1178
+ CSAT_CRE_TITLE: "Was your issue resolved?",
1179
+ CSAT_CRE_SOLVED: "Yes, thank you! 👍",
1180
+ CSAT_CRE_NOT_SOLVED: "No, that didn’t help.",
1181
+ CSAT_REASON_PLACEHOLDER: "Share your feedback",
1182
+ CSAT_RATING_TITLE: "How would you rate your experience?",
1183
+ CSAT5_RATING_SCORE_1: "Terrible",
1184
+ CSAT5_RATING_SCORE_2: "Bad",
1185
+ CSAT5_RATING_SCORE_3: "Okay",
1186
+ CSAT5_RATING_SCORE_4: "Good",
1187
+ CSAT5_RATING_SCORE_5: "Great",
1188
+ CSAT_SUBMIT_LABEL: "Submit",
1189
+ CSAT_SUBMISSION_EXPIRED: "We’re sorry, the survey period has ended.",
1190
+ POWERED_BY: "Powered by",
1191
+ // Conversation list
1192
+ CONVERSATION_CLOSED_FOOTER_LABEL: "Your conversation has ended",
1193
+ START_NEW_CONVERSATION: "💬 Start a new conversation",
1194
+ RETURN_TO_CONVERSATION: "💬 Return to conversation",
1195
+ CONVERSATION_LIST__HEADER_TITLE: "Conversation history",
1196
+ CONVERSATION_LIST__TOPICS_FALLBACK: "No category",
1197
+ CONVERSATION_LIST__NO_CONVERSATIONS: "No conversations yet",
1198
+ DATE_FORMAT__CONVERSATION_LIST__LIST_ITEM_TITLE: "MM/dd/yyyy",
1199
+ DATE_FORMAT__CONVERSATION_LIST__LIST_ITEM_TITLE_CAPTION: "h:mma"
1200
+ }, Et = { language: "en", dateLocale: Zo, stringSet: Ko }, Yo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1201
+ __proto__: null,
1202
+ default: Et
1203
+ }, Symbol.toStringTag, { value: "Module" })), Ze = /* @__PURE__ */ new Map([[Ne, Et]]);
1204
+ async function qo(e) {
1205
+ if (Ze.has(e))
1206
+ return Ze.get(e);
1207
+ const t = Go.has(e) ? e : Ne;
1208
+ try {
1209
+ const { default: n } = await jo(/* @__PURE__ */ Object.assign({ "./languages/de.ts": () => import("./DvjrAXLD.js"), "./languages/en.ts": () => Promise.resolve().then(() => Yo), "./languages/es.ts": () => import("./zI14HLvP.js"), "./languages/fr.ts": () => import("./B9V0T5ZP.js"), "./languages/hi.ts": () => import("./YRQ0vk5Q.js"), "./languages/it.ts": () => import("./BQWJPfGp.js"), "./languages/ja.ts": () => import("./sl-YrKkN.js"), "./languages/ko.ts": () => import("./B8c_rqvH.js"), "./languages/pt.ts": () => import("./BSz49qaD.js"), "./languages/tr.ts": () => import("./D_eZyIAR.js") }), `./languages/${t}.ts`, 3);
1210
+ return Ze.set(e, n), n;
1211
+ } catch {
1212
+ return Et;
1213
+ }
1214
+ }
1215
+ const {
1216
+ Provider: Jo,
1217
+ useContext: R
1218
+ } = j("Localization");
1219
+ function Xo(e) {
1220
+ var t;
1221
+ return ((t = e.split("-")) == null ? void 0 : t[0]) ?? Ne;
1222
+ }
1223
+ function Qo({
1224
+ language: e = navigator.language,
1225
+ logger: t,
1226
+ stringSet: n,
1227
+ children: o
1228
+ }) {
1229
+ const [i, a] = _(Ze.get(Ne));
1230
+ return N(() => {
1231
+ const s = Xo(e);
1232
+ i.language !== s && (t == null || t.debug("localization.useEffect: update language", `${i.language} -> ${s}`), qo(s).then(a));
1233
+ }, [e]), /* @__PURE__ */ r.createElement(
1234
+ Jo,
1235
+ {
1236
+ value: {
1237
+ language: i.language,
1238
+ stringSet: { ...i.stringSet, ...n },
1239
+ dateLocale: i.dateLocale,
1240
+ format: (s, l, c) => En(s, l, { locale: i.dateLocale, ...c })
1241
+ }
1242
+ },
1243
+ o
1244
+ );
1245
+ }
1246
+ const Ke = "data-sb-agent-theme", Vt = (e) => (t, ...n) => {
1247
+ let o = "";
1248
+ return t.forEach((i, a) => {
1249
+ o += i + (n[a] ?? "");
1250
+ }), `[${Ke}='${e}'] & { ${o} }`;
1251
+ }, D = {
1252
+ light: Vt("light"),
1253
+ dark: Vt("dark")
1254
+ }, ei = I(({ theme: e }) => {
1255
+ const { palette: t } = e;
1256
+ return `
1257
+ :root,
1258
+ :host {
1259
+ --sendbird-primary-extra-dark: ${t.primary.extraDark};
1260
+ --sendbird-primary-dark: ${t.primary.dark};
1261
+ --sendbird-primary-main: ${t.primary.main};
1262
+ --sendbird-primary-light: ${t.primary.light};
1263
+ --sendbird-primary-extra-light: ${t.primary.extraLight};
1264
+
1265
+ --sendbird-secondary-extra-dark: ${t.secondary.extraDark};
1266
+ --sendbird-secondary-dark: ${t.secondary.dark};
1267
+ --sendbird-secondary-main: ${t.secondary.main};
1268
+ --sendbird-secondary-light: ${t.secondary.light};
1269
+ --sendbird-secondary-extra-light: ${t.secondary.extraLight};
1270
+
1271
+ --sendbird-information-extra-dark: ${t.information.extraDark};
1272
+ --sendbird-information-dark: ${t.information.dark};
1273
+ --sendbird-information-main: ${t.information.main};
1274
+ --sendbird-information-light: ${t.information.light};
1275
+ --sendbird-information-extra-light: ${t.information.extraLight};
1276
+
1277
+ --sendbird-error-extra-dark: ${t.error.extraDark};
1278
+ --sendbird-error-dark: ${t.error.dark};
1279
+ --sendbird-error-main: ${t.error.main};
1280
+ --sendbird-error-light: ${t.error.light};
1281
+ --sendbird-error-extra-light: ${t.error.extraLight};
1282
+
1283
+ --sendbird-background-700: ${t.background700};
1284
+ --sendbird-background-600: ${t.background600};
1285
+ --sendbird-background-500: ${t.background500};
1286
+ --sendbird-background-400: ${t.background400};
1287
+ --sendbird-background-300: ${t.background300};
1288
+ --sendbird-background-200: ${t.background200};
1289
+ --sendbird-background-100: ${t.background100};
1290
+ --sendbird-background-50: ${t.background50};
1291
+
1292
+ --sendbird-onlight-text-high-emphasis: ${t.onlight.textHighEmphasis};
1293
+ --sendbird-onlight-text-mid-emphasis: ${t.onlight.textMidEmphasis};
1294
+ --sendbird-onlight-text-low-emphasis: ${t.onlight.textLowEmphasis};
1295
+ --sendbird-onlight-text-disabled: ${t.onlight.textDisabled};
1296
+
1297
+ --sendbird-ondark-text-high-emphasis: ${t.ondark.textHighEmphasis};
1298
+ --sendbird-ondark-text-mid-emphasis: ${t.ondark.textMidEmphasis};
1299
+ --sendbird-ondark-text-low-emphasis: ${t.ondark.textLowEmphasis};
1300
+ --sendbird-ondark-text-disabled: ${t.ondark.textDisabled};
1301
+
1302
+ --sendbird-overlay-dark: ${t.overlay.dark};
1303
+ --sendbird-overlay-light: ${t.overlay.light};
1304
+ }
1305
+ `;
1306
+ }), ti = I`[${Ke}='light'] &{--sb-text-high-emphasis:var(--sendbird-onlight-text-high-emphasis);--sb-text-mid-emphasis:var(--sendbird-onlight-text-mid-emphasis);--sb-text-low-emphasis:var(--sendbird-onlight-text-low-emphasis);--sb-text-disabled:var(--sendbird-onlight-text-disabled);--sb-text-high-emphasis-inverse:var(--sendbird-ondark-text-high-emphasis);--sb-text-mid-emphasis-inverse:var(--sendbird-ondark-text-mid-emphasis);--sb-text-low-emphasis-inverse:var(--sendbird-ondark-text-low-emphasis);--sb-text-disabled-inverse:var(--sendbird-ondark-text-disabled);--sb-bg-50-600:var(--sendbird-background-50);--sb-bg-100-500:var(--sendbird-background-100);--sb-bg-200-400:var(--sendbird-background-200);--sb-primary:var(--sendbird-primary-main);--sb-secondary:var(--sendbird-secondary-main);--sb-error:var(--sendbird-error-main);--sb-information:var(--sendbird-information-light);}[${Ke}='dark'] &{--sb-text-high-emphasis:var(--sendbird-ondark-text-high-emphasis);--sb-text-mid-emphasis:var(--sendbird-ondark-text-mid-emphasis);--sb-text-low-emphasis:var(--sendbird-ondark-text-low-emphasis);--sb-text-disabled:var(--sendbird-ondark-text-disabled);--sb-text-high-emphasis-inverse:var(--sendbird-onlight-text-high-emphasis);--sb-text-mid-emphasis-inverse:var(--sendbird-onlight-text-mid-emphasis);--sb-text-low-emphasis-inverse:var(--sendbird-onlight-text-low-emphasis);--sb-text-disabled-inverse:var(--sendbird-onlight-text-disabled);--sb-bg-50-600:var(--sendbird-background-600);--sb-bg-100-500:var(--sendbird-background-500);--sb-bg-200-400:var(--sendbird-background-400);--sb-primary:var(--sendbird-primary-light);--sb-secondary:var(--sendbird-secondary-light);--sb-error:var(--sendbird-error-light);--sb-information:var(--sendbird-information-light);}`, h = {
1307
+ color: {
1308
+ primary: {
1309
+ dark: "var(--sendbird-primary-dark)",
1310
+ main: "var(--sendbird-primary-main)"
1311
+ },
1312
+ error: {
1313
+ extraDark: "var(--sendbird-error-extra-dark)",
1314
+ dark: "var(--sendbird-error-dark)"
1315
+ },
1316
+ information: {
1317
+ main: "var(--sendbird-information-main)",
1318
+ light: "var(--sendbird-information-light)"
1319
+ },
1320
+ background700: "var(--sendbird-background-700)",
1321
+ background500: "var(--sendbird-background-500)",
1322
+ background400: "var(--sendbird-background-400)",
1323
+ background200: "var(--sendbird-background-200)",
1324
+ background100: "var(--sendbird-background-100)",
1325
+ background50: "var(--sendbird-background-50)",
1326
+ ondark: {
1327
+ textMidEmphasis: "var(--sendbird-ondark-text-mid-emphasis)",
1328
+ textLowEmphasis: "var(--sendbird-ondark-text-low-emphasis)",
1329
+ textDisabled: "var(--sendbird-ondark-text-disabled)"
1330
+ },
1331
+ overlay: {
1332
+ dark: "var(--sendbird-overlay-dark)"
1333
+ }
1334
+ },
1335
+ themedColor: {
1336
+ textHighEmphasis: "var(--sb-text-high-emphasis)",
1337
+ textMidEmphasis: "var(--sb-text-mid-emphasis)",
1338
+ textLowEmphasis: "var(--sb-text-low-emphasis)",
1339
+ textDisabled: "var(--sb-text-disabled)",
1340
+ textHighEmphasisInverse: "var(--sb-text-high-emphasis-inverse)",
1341
+ bg_50_600: "var(--sb-bg-50-600)",
1342
+ bg_100_500: "var(--sb-bg-100-500)",
1343
+ bg_200_400: "var(--sb-bg-200-400)",
1344
+ error: "var(--sb-error)"
1345
+ }
1346
+ }, {
1347
+ Provider: ni,
1348
+ useContext: ri
1349
+ } = j("AIAgentTheme");
1350
+ function oi(e) {
1351
+ const { theme: t, appearance: n, logger: o } = e;
1352
+ return /* @__PURE__ */ r.createElement(
1353
+ Ao,
1354
+ {
1355
+ appearance: n,
1356
+ palette: t == null ? void 0 : t.palette,
1357
+ typography: t == null ? void 0 : t.typography,
1358
+ logger: o
1359
+ },
1360
+ /* @__PURE__ */ r.createElement(ii, { ...e })
1361
+ );
1362
+ }
1363
+ function ii({ rootElement: e = document.body, children: t }) {
1364
+ const { theme: n, updateTheme: o } = kn();
1365
+ return ae(() => {
1366
+ e.setAttribute(Ke, n.selectedTheme);
1367
+ }, [e, n.selectedTheme]), /* @__PURE__ */ r.createElement($r, { theme: n }, /* @__PURE__ */ r.createElement(ni, { value: { theme: n, updateTheme: o } }, t));
1368
+ }
1369
+ function pe(e, t) {
1370
+ const n = e.getRootNode({ composed: t });
1371
+ return n instanceof ShadowRoot || n instanceof Document ? n : document;
1372
+ }
1373
+ const si = (e, t) => {
1374
+ N(() => {
1375
+ const n = pe(t) instanceof ShadowRoot, o = pe(t, !0);
1376
+ if (!(n ? t : o).querySelector(`link[href*='${e}']`)) {
1377
+ const a = o.createElement("link");
1378
+ a.rel = "stylesheet", a.href = e, (n ? t : o.head).appendChild(a);
1379
+ }
1380
+ }, [e, t]);
1381
+ }, ai = (e, t = document.body) => {
1382
+ N(() => {
1383
+ const n = pe(t), i = n instanceof ShadowRoot ? t : n.head;
1384
+ if (!i) return;
1385
+ const a = `sba-${btoa(e).slice(0, 10)}`;
1386
+ let s = i.querySelector(`style#${a}`);
1387
+ s ? s.textContent !== e && (s.textContent = e) : (s = i.ownerDocument.createElement("style"), s.id = a, s.textContent = e, i.appendChild(s));
1388
+ }, [e, t]);
1389
+ }, vt = /iPad|iPhone|iPod/.test(navigator.userAgent), li = /Android/.test(navigator.userAgent), De = (e) => vt || li, X = "sb-agent", ne = {
1390
+ ENTRY: `${X}-entry`,
1391
+ MODAL_ROOT: `${X}-modal-root`,
1392
+ WINDOW: `${X}-window`,
1393
+ LAUNCHER: `${X}-launcher`
1394
+ }, He = 2147483647, fe = {
1395
+ MODAL: He - 1,
1396
+ // FIXME: need to cover the case where the tooltip is on the top of the modal
1397
+ TOOLTIP: He - 2,
1398
+ WINDOW: He - 3,
1399
+ LAUNCHER: He - 4
1400
+ }, Mn = {
1401
+ SESSION: `@${X}-session`,
1402
+ USER_DATA: `@${X}-udata`
1403
+ }, On = {
1404
+ DEFAULT_PRIMARY: "#742ddd",
1405
+ WHITE: "#ffffff"
1406
+ }, Ln = 36, ci = 100, di = 25 * 1024 * 1024, Rn = ["application/pdf", "image/jpeg", "image/jpg", "image/png"], Ct = "noopener noreferrer nofollow", ze = {}, ee = {
1407
+ getItem: (e) => {
1408
+ try {
1409
+ return localStorage.getItem(e);
1410
+ } catch {
1411
+ return ze[e] ?? null;
1412
+ }
1413
+ },
1414
+ setItem: (e, t) => {
1415
+ try {
1416
+ localStorage.setItem(e, t);
1417
+ } catch {
1418
+ ze[e] = t;
1419
+ }
1420
+ },
1421
+ deleteItem: (e) => {
1422
+ try {
1423
+ localStorage.removeItem(e);
1424
+ } catch {
1425
+ delete ze[e];
1426
+ }
1427
+ },
1428
+ getKeys: (e) => {
1429
+ try {
1430
+ const t = [];
1431
+ for (let n = 0; n < localStorage.length; n++) {
1432
+ const o = localStorage.key(n);
1433
+ o && o.startsWith(e) && t.push(o);
1434
+ }
1435
+ return t;
1436
+ } catch {
1437
+ return Object.keys(ze).filter((t) => t.startsWith(e));
1438
+ }
1439
+ }
1440
+ };
1441
+ function Nn(e) {
1442
+ const { keyGenerator: t, keyParamsValidator: n } = e;
1443
+ function o(s) {
1444
+ try {
1445
+ n && n(s);
1446
+ const l = t(s), c = ee.getItem(l);
1447
+ return c ? JSON.parse(c) : null;
1448
+ } catch {
1449
+ return null;
1450
+ }
1451
+ }
1452
+ function i(s, l) {
1453
+ try {
1454
+ n && n(s);
1455
+ const c = t(s), d = JSON.stringify(l);
1456
+ ee.setItem(c, d);
1457
+ } catch {
1458
+ }
1459
+ }
1460
+ function a(s) {
1461
+ try {
1462
+ n && n(s);
1463
+ const l = t(s);
1464
+ ee.deleteItem(l);
1465
+ } catch {
1466
+ }
1467
+ }
1468
+ return { get: o, set: i, clear: a };
1469
+ }
1470
+ const Ve = Nn({
1471
+ keyGenerator: ({ appId: e, aiAgentId: t, userId: n }) => {
1472
+ const o = ui(`${e}/${t}/${n}`);
1473
+ return `${Mn.USER_DATA}/${o}`;
1474
+ },
1475
+ keyParamsValidator: ({ appId: e, aiAgentId: t, userId: n }) => {
1476
+ if (!e || !t || !n)
1477
+ throw new Error("Invalid parameters for user data cache");
1478
+ }
1479
+ });
1480
+ function ui(e) {
1481
+ let t = 0;
1482
+ for (let n = 0; n < e.length; n++)
1483
+ t = (t << 5) - t + e.charCodeAt(n), t |= 0;
1484
+ return t.toString(16);
1485
+ }
1486
+ const st = Nn({
1487
+ keyGenerator: ({ appId: e, aiAgentId: t }) => `${Mn.SESSION}/${e}/${t}`
1488
+ }), {
1489
+ Provider: mi,
1490
+ Consumer: Dn,
1491
+ useContext: P
1492
+ } = j("Agent");
1493
+ function hi({
1494
+ children: e,
1495
+ state: t,
1496
+ enableCloseConversationButton: n = !1,
1497
+ enableExpandButton: o = !0,
1498
+ enableAutoDisconnectInLauncher: i = !0,
1499
+ ...a
1500
+ }) {
1501
+ const s = Xe(), [l, c] = _(!1), [d, u] = _(!1), p = {
1502
+ opened: (t == null ? void 0 : t.opened) ?? l,
1503
+ setOpened: (t == null ? void 0 : t.setOpened) ?? c,
1504
+ expanded: (t == null ? void 0 : t.expanded) ?? d,
1505
+ setExpanded: (t == null ? void 0 : t.setExpanded) ?? u
1506
+ };
1507
+ return /* @__PURE__ */ r.createElement(
1508
+ mi,
1509
+ {
1510
+ value: {
1511
+ ...a,
1512
+ ...s,
1513
+ state: p,
1514
+ enableCloseConversationButton: n,
1515
+ enableExpandButton: o,
1516
+ enableAutoDisconnectInLauncher: i
1517
+ }
1518
+ },
1519
+ e
1520
+ );
1521
+ }
1522
+ function gi() {
1523
+ const { chatSDK: e, logger: t } = P(), { shouldSyncCachedTemplate: n, syncCachedTemplates: o, clearCachedTemplates: i } = In(), a = U(
1524
+ async (l, c, d) => {
1525
+ if (t.debug("authManager.authenticate: session:", l.userId), c) {
1526
+ const u = new Ar({
1527
+ ...c,
1528
+ onSessionTokenRequired: pi(c.onSessionTokenRequired, d)
1529
+ });
1530
+ e.setSessionHandler(u);
1531
+ }
1532
+ await e.connect(l.userId, l.authToken), t.debug("authManager.authenticate: user:", e.currentUser), n(e) && await o(e);
1533
+ },
1534
+ [e, t, n, o]
1535
+ ), s = U(async () => {
1536
+ t.debug("authManager.deauthenticate: disconnect"), await e.disconnect(), i();
1537
+ }, [e, t, i]);
1538
+ return {
1539
+ authenticate: a,
1540
+ deauthenticate: s
1541
+ };
1542
+ }
1543
+ function pi(e, t) {
1544
+ if (e)
1545
+ return async (n, o) => {
1546
+ new Promise((i, a) => e == null ? void 0 : e(i, a)).then((i) => {
1547
+ i && (t == null || t(i)), n(i);
1548
+ }).catch((i) => {
1549
+ o(i);
1550
+ });
1551
+ };
1552
+ }
1553
+ const fi = 24 * 60 * 60 * 1e3, {
1554
+ Provider: bi,
1555
+ useContext: z
1556
+ } = j("MessengerSession"), xi = Le(function({ userSessionInfo: e, children: t }, n) {
1557
+ const { appId: o, aiAgentId: i, chatSDK: a, agentPreviewConfigs: s, state: l, logger: c, language: d, countryCode: u, context: p, handlers: g } = P(), { updateTheme: b } = kn(), { authenticate: x, deauthenticate: E } = gi(), [f, v] = _(
1558
+ void 0
1559
+ ), [y, $] = _(void 0), [T, Y] = _(null), [L, be] = _(null), [xe, C] = _(null), B = s == null ? void 0 : s.forceCreateChannel;
1560
+ function Ee() {
1561
+ if (e && e.userId) {
1562
+ c.debug("messengerSession.initialize: manual session info detected");
1563
+ const A = ["authToken", "sessionHandler"].filter((M) => !(M in e));
1564
+ return A.length > 0 && c.error(
1565
+ `messengerSession.initialize: missing required keys in userSessionInfo: ${A.join(", ")}`
1566
+ ), e;
1567
+ }
1568
+ const k = st.get({ appId: o, aiAgentId: i });
1569
+ return k ? k.expireAt - fi <= Date.now() ? (c.debug("messengerSession.initialize: auto session expired, clear cache"), st.clear({ appId: o, aiAgentId: i }), Ve.clear({ appId: o, aiAgentId: i, userId: k.userId }), null) : (c.debug("messengerSession.initialize: auto session info detected"), k) : null;
1570
+ }
1571
+ const J = U(
1572
+ (k, A) => {
1573
+ Ve.set({ appId: o, aiAgentId: i, userId: k }, { knownActiveChannelUrl: A });
1574
+ },
1575
+ [o, i]
1576
+ ), Ae = U(
1577
+ (k) => {
1578
+ const A = Ve.get({ appId: o, aiAgentId: i, userId: k });
1579
+ return A == null ? void 0 : A.knownActiveChannelUrl;
1580
+ },
1581
+ [o, i]
1582
+ ), rt = U(async () => {
1583
+ if (T) {
1584
+ c.debug("messengerSession.refreshActiveChannel: try to refresh active channel"), v(void 0);
1585
+ const k = await a.aiAgent.requestMessengerSettings({
1586
+ aiAgentId: i,
1587
+ userId: T.userId,
1588
+ language: d,
1589
+ country: u,
1590
+ context: p,
1591
+ forceCreateChannel: B,
1592
+ knownActiveChannelUrl: Ae(T.userId)
1593
+ });
1594
+ return J(T.userId, k.active_channel.channel_url), v({ url: k.active_channel.channel_url, status: W.OPEN }), c.info(
1595
+ "messengerSession.refreshActiveChannel: refreshed active channel",
1596
+ k.active_channel.channel_url
1597
+ ), k.active_channel.channel_url;
1598
+ } else
1599
+ throw c.error("messengerSession.refreshActiveChannel: userSession is not ready"), new Error("userSession is not ready");
1600
+ }, [
1601
+ a,
1602
+ o,
1603
+ i,
1604
+ T == null ? void 0 : T.userId,
1605
+ d,
1606
+ u,
1607
+ p,
1608
+ B,
1609
+ Ae,
1610
+ J
1611
+ ]), ot = U(
1612
+ async (k) => {
1613
+ if (!(T != null && T.userId))
1614
+ throw new Error("Current user is not authenticated. Please authenticate first.");
1615
+ const M = (await a.aiAgent.requestMessengerSettings({
1616
+ ...k,
1617
+ userId: T.userId,
1618
+ knownActiveChannelUrl: void 0
1619
+ })).active_channel.channel_url;
1620
+ return Ve.set(
1621
+ { userId: T.userId, appId: o, aiAgentId: k.aiAgentId },
1622
+ { knownActiveChannelUrl: M }
1623
+ ), M;
1624
+ },
1625
+ [T == null ? void 0 : T.userId]
1626
+ );
1627
+ return vn(a, {
1628
+ onChannelChanged: (k) => {
1629
+ var A;
1630
+ k.isGroupChannel() && k.url === (f == null ? void 0 : f.url) && (c.info("messengerSession.channelChanged: channel.conversation", k.conversation), v({ url: k.url, status: ((A = k.conversation) == null ? void 0 : A.status) ?? W.OPEN }));
1631
+ },
1632
+ async onUserJoined(k, A) {
1633
+ var H, ve;
1634
+ if (k.conversation && k.conversation.type === Dr.PROACTIVE && A.userId === ((H = a.currentUser) == null ? void 0 : H.userId)) {
1635
+ c.info("messengerSession.onUserJoined: proactive channel joined", k.url);
1636
+ const oe = ((ve = k.conversation) == null ? void 0 : ve.status) ?? W.OPEN;
1637
+ v({ url: k.url, status: oe }), l.setOpened(!0), Ei({
1638
+ sound: document.hidden || !l.opened
1639
+ });
1640
+ }
1641
+ }
1642
+ }), vr(n, () => {
1643
+ const k = async () => {
1644
+ if (!f) throw new Error("No active conversation. Please start a conversation first.");
1645
+ return await a.groupChannel.getChannel(f.url);
1646
+ };
1647
+ return {
1648
+ updateContext: async (A) => {
1649
+ const H = await (await k()).updateContext(i, A);
1650
+ return { ...H, context: H.context ?? {} };
1651
+ },
1652
+ patchContext: async (A) => {
1653
+ const H = await (await k()).patchContext(i, A);
1654
+ return { ...H, context: H.context ?? {} };
1655
+ },
1656
+ getContextObject: async () => {
1657
+ const M = await (await k()).getContextObject(i);
1658
+ return { ...M, context: M.context ?? {} };
1659
+ }
1660
+ };
1661
+ }, [f, a, i]), N(() => {
1662
+ async function k() {
1663
+ c.debug("messengerSession.initialize: start");
1664
+ const A = Ee(), M = await a.aiAgent.requestMessengerSettings({
1665
+ aiAgentId: i,
1666
+ userId: A == null ? void 0 : A.userId,
1667
+ language: d,
1668
+ country: u,
1669
+ context: p,
1670
+ forceCreateChannel: B,
1671
+ knownActiveChannelUrl: Ae(A == null ? void 0 : A.userId)
1672
+ });
1673
+ c.debug("messengerSession.initialize: messenger settings response", M);
1674
+ let H = null;
1675
+ if (M.auto_created_user) {
1676
+ const { user_id: Z, session_token: ie, expire_at: Q } = M.auto_created_user;
1677
+ st.set({ appId: o, aiAgentId: i }, { userId: Z, authToken: ie, expireAt: Q }), H = { userId: Z, authToken: ie };
1678
+ } else
1679
+ H = {
1680
+ userId: (A == null ? void 0 : A.userId) ?? "",
1681
+ authToken: (A == null ? void 0 : A.authToken) ?? ""
1682
+ };
1683
+ J(H.userId, M.active_channel.channel_url);
1684
+ function ve() {
1685
+ const Z = M.appearance.selected_theme;
1686
+ b(Z, (Q) => {
1687
+ const G = M.appearance.themes[Q];
1688
+ return {
1689
+ primaryColor: G.primary_color,
1690
+ botMessageBackgroundColor: G.bot_message_bg_color,
1691
+ primaryContrastColor: G.primary_contrast_color,
1692
+ botMessageBackgroundContrastColor: G.bot_message_bg_contrast_color
1693
+ };
1694
+ }), $(void 0), Y(H), be({
1695
+ userId: M.bot.bot_userid,
1696
+ profileUrl: M.bot.bot_profile_url,
1697
+ nickname: M.bot.bot_nickname,
1698
+ replyToFile: M.bot.reply_to_file,
1699
+ specialNotice: M.bot.special_notice,
1700
+ specialNoticeEnabled: M.bot.is_special_notice_enabled,
1701
+ showHandoffButton: M.bot.show_handoff_button ?? !0
1702
+ }), C({
1703
+ type: M.launcher.image_type || "default_icon",
1704
+ imageUrl: M.launcher.image_url
1705
+ }), M.launcher.auto_open && !De() && setTimeout(() => l.setOpened(!0), 500);
1706
+ }
1707
+ function oe() {
1708
+ v({ url: M.active_channel.channel_url, status: W.OPEN });
1709
+ }
1710
+ try {
1711
+ ve();
1712
+ const Z = (ie) => Y((Q) => Q ? { ...Q, authToken: ie } : null);
1713
+ await x(H, e == null ? void 0 : e.sessionHandler, Z), oe();
1714
+ } catch (Z) {
1715
+ Z instanceof Error && (c.error("messengerSession.initialize: failed to connect", Z), $(Z));
1716
+ }
1717
+ }
1718
+ k().catch((A) => {
1719
+ c.error("messengerSession: failed to initialize", A);
1720
+ });
1721
+ }, [a, o, i, e == null ? void 0 : e.userId, e == null ? void 0 : e.authToken]), N(() => {
1722
+ g != null && g.onRegisterDeauthenticateHandler && (c.debug("messengerSession: registering deauthenticate handler"), g.onRegisterDeauthenticateHandler(E));
1723
+ }, [g == null ? void 0 : g.onRegisterDeauthenticateHandler, E]), !T || !L || !xe ? null : /* @__PURE__ */ r.createElement(
1724
+ bi,
1725
+ {
1726
+ value: {
1727
+ userSession: T,
1728
+ activeChannel: f,
1729
+ refreshActiveChannel: rt,
1730
+ createConversation: ot,
1731
+ connectionError: y,
1732
+ aiAgentInfo: { ...L, ...s == null ? void 0 : s.bot },
1733
+ launcherInfo: { ...xe, ...s == null ? void 0 : s.launcher }
1734
+ }
1735
+ },
1736
+ t
1737
+ );
1738
+ });
1739
+ function Ei({ sound: e }) {
1740
+ const t = "🔔You have received a new message", n = document.title, o = setInterval(() => {
1741
+ document.title = document.title === t ? n : t;
1742
+ }, 750);
1743
+ setTimeout(() => clearInterval(o), 5e3), e && import("./DP0MwObA.js").then((i) => {
1744
+ new Audio(i.default).play();
1745
+ });
1746
+ }
1747
+ const vi = ({ publishSynchronous: e = !1 }) => {
1748
+ const t = /* @__PURE__ */ new Set();
1749
+ return {
1750
+ publish: (n) => {
1751
+ t.forEach((o) => {
1752
+ e ? o(n) : setTimeout(() => o(n), 0);
1753
+ });
1754
+ },
1755
+ subscribe: (n) => (t.add(n), () => t.delete(n))
1756
+ };
1757
+ };
1758
+ function Ci(e, t = []) {
1759
+ const n = F(null), o = F(0), i = F(0), [a] = _(() => vi({ publishSynchronous: !0 })), [s, l] = _(!0);
1760
+ return ae(() => {
1761
+ o.current = 0, i.current = 0, l(!0), n.current && (n.current.scrollTop = n.current.scrollHeight);
1762
+ }, t), ae(() => a.subscribe(({ type: c, data: d }) => {
1763
+ const { resolve: u, animated: p } = d ?? {};
1764
+ if (!n.current) return u == null ? void 0 : u();
1765
+ if (c === "scrollToBottom" && (n.current.scroll ? n.current.scroll({
1766
+ top: n.current.scrollHeight,
1767
+ behavior: Wt(e, p)
1768
+ }) : n.current.scrollTop = n.current.scrollHeight, i.current = 0, l(!0), u == null || u()), c === "scroll") {
1769
+ const g = d == null ? void 0 : d.top, { scrollTop: b, scrollHeight: x, clientHeight: E } = n.current;
1770
+ n.current.scroll ? n.current.scroll({ top: g, behavior: Wt(e, p) }) : typeof g == "number" && (n.current.scrollTop = g), i.current = Math.max(0, x - b - E), l(i.current === 0), u == null || u();
1771
+ }
1772
+ }), [e]), {
1773
+ scrollRef: n,
1774
+ scrollPubSub: a,
1775
+ isScrollBottomReached: s,
1776
+ setIsScrollBottomReached: l,
1777
+ scrollDistanceFromBottomRef: i,
1778
+ scrollPositionRef: o
1779
+ };
1780
+ }
1781
+ function Wt(e, t) {
1782
+ return typeof t == "boolean" ? t ? "smooth" : "auto" : e;
1783
+ }
1784
+ function yi(e) {
1785
+ return new Promise((t) => {
1786
+ const n = new Image();
1787
+ n.onload = function() {
1788
+ const o = String(n.width), i = String(n.height);
1789
+ URL.revokeObjectURL(n.src), t({ width: o, height: i });
1790
+ }, n.src = URL.createObjectURL(e);
1791
+ });
1792
+ }
1793
+ async function _i(e) {
1794
+ if ("file" in e && e.file instanceof File && e.file.type.startsWith("image/")) {
1795
+ const { width: t, height: n } = await yi(e.file);
1796
+ return new Hr({
1797
+ key: Pn,
1798
+ value: [t, n]
1799
+ });
1800
+ }
1801
+ }
1802
+ const Pn = "KEY_IMG_ASPECT_RATIO", Ti = ({ onScroll: e }) => {
1803
+ const { agentPreviewConfigs: t, handlers: n } = P(), o = F(t == null ? void 0 : t.agentAttributes);
1804
+ return o.current = t == null ? void 0 : t.agentAttributes, {
1805
+ onBeforeSendMessage: async (i) => {
1806
+ const a = await _i(i), s = {
1807
+ ...i,
1808
+ metaArrays: a ? [a] : void 0
1809
+ }, l = Si(o.current);
1810
+ return l ? { ...s, data: JSON.stringify(l) } : s;
1811
+ },
1812
+ onAfterSendMessage: (i) => {
1813
+ var a;
1814
+ e(), (a = n == null ? void 0 : n.onMessageSend) == null || a.call(n, i.message);
1815
+ }
1816
+ };
1817
+ }, Si = (e) => {
1818
+ if (!e) return null;
1819
+ const t = {};
1820
+ return e.ai && Object.keys(e.ai).length > 0 && (t.ai_attrs = e.ai), e.safeguard && Object.keys(e.safeguard).length > 0 && (t.safeguard_attrs = e.safeguard), typeof e.use_prompt_cache == "boolean" && (t.use_prompt_cache = e.use_prompt_cache), Object.keys(t).length > 0 ? t : null;
1821
+ }, {
1822
+ Provider: wi,
1823
+ useContext: q
1824
+ } = j("Conversation"), ki = ({
1825
+ closedChannelUrl: e,
1826
+ onClearClosedChannelUrl: t,
1827
+ onNavigateToConversationList: n,
1828
+ children: o
1829
+ }) => {
1830
+ const { activeChannel: i, refreshActiveChannel: a } = z(), s = Ci("smooth"), l = () => {
1831
+ setTimeout(() => s.scrollPubSub.publish({ type: "scrollToBottom" }), 25);
1832
+ }, { onBeforeSendMessage: c, onAfterSendMessage: d } = Ti({ onScroll: l }), u = U(async () => {
1833
+ await a(), e && (t == null || t());
1834
+ }, [a, e, t]);
1835
+ return /* @__PURE__ */ r.createElement(
1836
+ lo,
1837
+ {
1838
+ channelUrl: e || (i == null ? void 0 : i.url),
1839
+ onBeforeSendMessage: c,
1840
+ onAfterSendMessage: d,
1841
+ onMessagesUpdated: l,
1842
+ onChannelDeleted: u,
1843
+ onConversationClosedViaDispatcher: u
1844
+ },
1845
+ (p) => /* @__PURE__ */ r.createElement(
1846
+ wi,
1847
+ {
1848
+ value: { ...p, scrollSource: s, goToActiveConversation: u, onNavigateToConversationList: n }
1849
+ },
1850
+ o
1851
+ )
1852
+ );
1853
+ };
1854
+ function Oe() {
1855
+ }
1856
+ async function Bn(e) {
1857
+ let t = e;
1858
+ t && (!t.startsWith("http://") && !t.startsWith("https://") && (t = "https://" + t), window.open(t, "_blank", "noopener,noreferrer"));
1859
+ }
1860
+ function Gt(e) {
1861
+ try {
1862
+ return JSON.parse(e === "" ? "{}" : e);
1863
+ } catch {
1864
+ return {};
1865
+ }
1866
+ }
1867
+ function Fn(e) {
1868
+ return !e || !e.conversation ? !1 : e.conversation.status === W.CLOSED;
1869
+ }
1870
+ function Un(e) {
1871
+ return !e || !e.conversation ? !1 : e.conversation.status === W.OPEN;
1872
+ }
1873
+ function Hn(e) {
1874
+ var n;
1875
+ const t = (n = e == null ? void 0 : e.conversation) == null ? void 0 : n.handoff;
1876
+ return !!(t != null && t.timestamp);
1877
+ }
1878
+ function Ai(e) {
1879
+ return Un(e) && !Hn(e);
1880
+ }
1881
+ const yt = Se({
1882
+ onDrop: Oe,
1883
+ subscribe: () => Oe
1884
+ }), gt = ({ children: e }) => {
1885
+ const t = F(/* @__PURE__ */ new Set());
1886
+ return /* @__PURE__ */ r.createElement(
1887
+ yt.Provider,
1888
+ {
1889
+ value: {
1890
+ onDrop: (n) => {
1891
+ var o;
1892
+ if (n.preventDefault(), (o = n.dataTransfer) != null && o.files) {
1893
+ const i = Array.from(n.dataTransfer.files);
1894
+ i.length > 0 && t.current.forEach((a) => a(i));
1895
+ }
1896
+ },
1897
+ subscribe: (n) => (t.current.add(n), () => t.current.delete(n))
1898
+ }
1899
+ },
1900
+ e
1901
+ );
1902
+ }, Ii = ({ onDropFiles: e }) => {
1903
+ const { subscribe: t } = te(yt);
1904
+ N(() => t(e), [e]);
1905
+ };
1906
+ gt.Consumer = ({ children: e }) => {
1907
+ const { onDrop: t } = te(yt);
1908
+ return e({ onDrop: t, onDragOver: (i) => i.preventDefault() });
1909
+ };
1910
+ const K = (e) => {
1911
+ const t = e;
1912
+ return typeof t == "number" ? `${t}px` : t;
1913
+ }, $i = /* @__PURE__ */ new Set(["send", "chat", "message", "chevron-right"]), Mi = {
1914
+ spinner: S(() => import("./BcUGcaq2.js")),
1915
+ chat: S(() => import("./DcFCGVBm.js")),
1916
+ message: S(() => import("./DsGXnanX.js")),
1917
+ error: S(() => import("./B6fvrWGq.js")),
1918
+ info: S(() => import("./CAIYsKDy.js")),
1919
+ refresh: S(() => import("./B6xd54zt.js")),
1920
+ "chevron-down": S(() => import("./BsimU71m.js")),
1921
+ "chevron-right": S(() => import("./NmJl7zv3.js")),
1922
+ done: S(() => import("./D_q6g3Dd.js")),
1923
+ user: S(() => import("./CvqfQEhO.js")),
1924
+ "file-document": S(() => import("./BAr50pfO.js")),
1925
+ download: S(() => import("./B2CtcWp3.js")),
1926
+ attach: S(() => import("./DY2ULcTX.js")),
1927
+ delete: S(() => import("./DMruRpOm.js")),
1928
+ close: S(() => import("./CuaBI7kd.js")),
1929
+ "close-filled": S(() => import("./CxQFWLnW.js")),
1930
+ send: S(() => import("./DZJyDpNp.js")),
1931
+ menu: S(() => import("./BUYabNz7.js")),
1932
+ expand: S(() => import("./wBtIAuNm.js")),
1933
+ collapse: S(() => import("./C0RFfifL.js")),
1934
+ agent: S(() => import("./Cc7XmLN1.js")),
1935
+ question: S(() => import("./dqwvRBog.js")),
1936
+ actionbook: S(() => import("./CrjNuryZ.js")),
1937
+ function: S(() => import("./CvdSjw1c.js")),
1938
+ "radio-on": S(() => import("./nmdo2Fbj.js")),
1939
+ "radio-off": S(() => import("./BnZcRFmS.js")),
1940
+ confluence: S(() => import("./BOnlh2zd.js")),
1941
+ zendesk: S(() => import("./BAJ6LEKc.js")),
1942
+ salesforce: S(() => import("./CT2kv4lr.js")),
1943
+ sprinklr: S(() => import("./m2INcyV2.js")),
1944
+ website: S(() => import("./BgGVGNdg.js")),
1945
+ snippet: S(() => import("./BFcXPuf5.js")),
1946
+ template: S(() => import("./awO7aBCv.js"))
1947
+ }, O = ({ type: e, size: t = 24, className: n, color: o }) => {
1948
+ const i = Mi[e];
1949
+ return /* @__PURE__ */ r.createElement(
1950
+ Li,
1951
+ {
1952
+ className: n,
1953
+ $rtlFlip: $i.has(e),
1954
+ $size: t,
1955
+ $color: o ?? h.color.primary.main
1956
+ },
1957
+ /* @__PURE__ */ r.createElement(Me, { fallback: null }, /* @__PURE__ */ r.createElement(i, null))
1958
+ );
1959
+ }, Oi = I`[dir='rtl'] &{transform:scaleX(-1);}`, Li = m.div`width:${({ $size: e }) => K(e)};height:${({ $size: e }) => K(e)};display:inline-block;&:focus{outline:none;}svg{display:block;}[class*='fill']{fill:${({ $color: e }) => e};}[class*='stroke']{stroke:${({ $color: e }) => e};stroke-width:2px;stroke-linejoin:round;}${({ $rtlFlip: e }) => e && Oi};`, w = ({
1960
+ as: e,
1961
+ variant: t = "body1",
1962
+ color: n,
1963
+ className: o,
1964
+ ...i
1965
+ }) => /* @__PURE__ */ r.createElement(Ni, { as: e, $variant: t, className: o, $color: n, ...i }), jt = /* @__PURE__ */ new WeakMap(), Ri = (e, t) => {
1966
+ let n = jt.get(t);
1967
+ n || (n = /* @__PURE__ */ new Map(), jt.set(t, n));
1968
+ const o = n.get(e);
1969
+ if (o) return o;
1970
+ const i = t[e] ?? t.body1, a = I`font-size:${K(i.fontSize)};font-weight:${i.fontWeight};${i.fontFamily ? `font-family: ${i.fontFamily};` : ""}
1971
+ ${i.lineHeight ? `line-height: ${i.lineHeight};` : "line-height: 100%;"}
1972
+ `;
1973
+ return n.set(e, a), a;
1974
+ }, Ni = m.span`font-stretch:normal;font-style:normal;letter-spacing:normal;${({ $variant: e, theme: t }) => Ri(e, t.typography)}color:${({ $color: e }) => e};`, Kd = ({ iconSize: e = 64, icon: t, className: n, label: o, children: i }) => /* @__PURE__ */ r.createElement(Pi, { className: n }, /* @__PURE__ */ r.createElement(O, { type: t, size: e, color: h.themedColor.textLowEmphasis }), /* @__PURE__ */ r.createElement(w, { variant: "body1", color: h.themedColor.textMidEmphasis }, o), i), Di = m.div`position:relative;display:flex;justify-content:center;align-items:center;width:100%;height:100%;`, Pi = m.div`display:flex;flex-direction:column;min-height:104px;align-items:center;gap:20px;text-align:center;`, Bi = {
1975
+ loading: S(() => import("./7TbprxJ5.js")),
1976
+ error: S(() => import("./DN9viLrz.js")),
1977
+ noChannels: S(() => import("./Brq-oKo1.js")),
1978
+ noMessages: S(() => import("./rDKPgaCw.js"))
1979
+ }, _e = ({ className: e, type: t = "loading", ...n }) => {
1980
+ const o = Bi[t];
1981
+ return /* @__PURE__ */ r.createElement(Di, { className: e }, /* @__PURE__ */ r.createElement(Me, { fallback: null }, /* @__PURE__ */ r.createElement(o, { ...n })));
1982
+ }, Pe = 244, zn = 640, Ye = 26, Vn = 4, re = 12, ke = 2, Fi = 16, de = `${X}-incoming-msg`, Ui = `${X}-marked-text`;
1983
+ function _t(e) {
1984
+ switch (e) {
1985
+ case "top":
1986
+ case "middle":
1987
+ return ke;
1988
+ default:
1989
+ return Fi;
1990
+ }
1991
+ }
1992
+ function Tt(e, t) {
1993
+ if (t) {
1994
+ const [, n] = t.split("/");
1995
+ if (n)
1996
+ return n.toUpperCase();
1997
+ }
1998
+ if (e && !e.startsWith(".")) {
1999
+ const n = e.split(".").pop();
2000
+ if (n && n !== e)
2001
+ return n.toUpperCase();
2002
+ }
2003
+ return "FILE";
2004
+ }
2005
+ function Wn(e) {
2006
+ return e.messageType === "file" ? e.message.length > 0 && e.file.name !== e.message : e.message.length > 0;
2007
+ }
2008
+ function St({
2009
+ name: e,
2010
+ type: t = "FILE",
2011
+ iconColor: n,
2012
+ iconBackgroundColor: o,
2013
+ onClick: i
2014
+ }) {
2015
+ const { colors: a } = bt();
2016
+ return /* @__PURE__ */ r.createElement(Hi, { onClick: i, $clickable: !!i }, /* @__PURE__ */ r.createElement(Vi, { $bgColor: o ?? a.base.primary }, /* @__PURE__ */ r.createElement(O, { type: "file-document", size: 24, color: n ?? a.base.primaryContrastContent })), /* @__PURE__ */ r.createElement(Wi, null, /* @__PURE__ */ r.createElement(Gi, { variant: "button", color: h.themedColor.textHighEmphasis }, e), /* @__PURE__ */ r.createElement(w, { color: h.themedColor.textMidEmphasis, variant: "caption3" }, t)));
2017
+ }
2018
+ const Hi = m.div`border-radius:12px;gap:8px;width:${Pe}px;height:64px;display:flex;align-items:center;padding:12px;box-sizing:border-box;border:1px solid ${h.themedColor.textDisabled};background-color:${h.themedColor.bg_50_600};${({ $clickable: e }) => e && zi}`, zi = I`cursor:pointer;&:hover{background-color:${h.themedColor.bg_100_500};}`, Vi = m.div`border-radius:8px;width:40px;height:40px;display:flex;align-items:center;justify-content:center;background-color:${({ $bgColor: e }) => e};`, Wi = m.div`display:flex;flex:1;flex-direction:column;gap:4px;min-width:0;`, Gi = m(w)`text-overflow:ellipsis;white-space:nowrap;overflow:hidden;`;
2019
+ function ji({ file: e, children: t, onClickFile: n }) {
2020
+ return /* @__PURE__ */ r.createElement(Zi, null, /* @__PURE__ */ r.createElement(
2021
+ St,
2022
+ {
2023
+ name: e.name,
2024
+ type: Tt(e.name, e.type),
2025
+ onClick: n && (() => n == null ? void 0 : n(e))
2026
+ }
2027
+ ), t);
2028
+ }
2029
+ const Zi = m.div`display:flex;flex-direction:column;align-items:flex-start;gap:${ke}px;`;
2030
+ function Ki({ file: e, onClickMedia: t, children: n }) {
2031
+ const o = () => e.type.startsWith("image") ? /* @__PURE__ */ r.createElement(Ji, { src: e.url, alt: "image-message" }) : e.type.startsWith("video") ? /* @__PURE__ */ r.createElement(Xi, { controls: !0 }, /* @__PURE__ */ r.createElement("source", { src: e.url }), /* @__PURE__ */ r.createElement("track", { kind: "captions" })) : null;
2032
+ if (o) {
2033
+ const i = {
2034
+ id: `${de}-media-body`,
2035
+ onClick: () => t == null ? void 0 : t(e)
2036
+ };
2037
+ return /* @__PURE__ */ r.createElement(Yi, null, /* @__PURE__ */ r.createElement(qi, { ...i }, o()), n);
2038
+ }
2039
+ return null;
2040
+ }
2041
+ const Yi = m.div`display:flex;flex-direction:column;align-items:flex-start;gap:${ke}px;`, qi = m.div`width:${Pe}px;height:160px;border-radius:12px;overflow:hidden;cursor:pointer;${D.light`
2042
+ background-color: ${h.color.background100};
2043
+ `}
2044
+ ${D.dark`
2045
+ background-color: ${h.color.background400};
2046
+ `}
2047
+ `, Ji = m.img`width:100%;height:100%;object-fit:cover;`, Xi = m.video`width:100%;height:100%;object-fit:cover;`, Qi = "✱";
2048
+ function Gn(e) {
2049
+ const t = new RegExp(`${Qi}+`, "g");
2050
+ return e.replace(t, (n) => `<span id=${Ui} aria-label="masked-text">${n}</span>`);
2051
+ }
2052
+ function es(e) {
2053
+ const t = /```(\w+)?\n([\s\S]*?)```/g, n = [];
2054
+ let o = 0;
2055
+ return e.replace(t, (i, ...a) => {
2056
+ const [s, l, c] = a;
2057
+ return o < c && n.push({
2058
+ type: "text",
2059
+ value: e.slice(o, c).trim()
2060
+ }), n.push({
2061
+ type: "code",
2062
+ value: l.trim(),
2063
+ language: s ? s.trim() : "plaintext"
2064
+ }), o = c + i.length, i;
2065
+ }), o < e.length && n.push({
2066
+ type: "text",
2067
+ value: e.slice(o).trim()
2068
+ }), n.map((i) => i.type !== "text" ? i : { ...i, value: Gn(i.value) });
2069
+ }
2070
+ const ts = S(async () => ({ default: (await import("./CD9aZhSJ.js")).MarkdownText })), ns = S(async () => ({ default: (await import("./DH2PekOm.js")).CodeBlock }));
2071
+ function Zt(e) {
2072
+ var i, a;
2073
+ const t = e.maxBodyWidth ?? Pe, n = ye(() => es(e.message), [e.message]), o = {
2074
+ id: `${de}-text-body`,
2075
+ $maxWidth: t,
2076
+ $color: (i = e.customStyle) == null ? void 0 : i.bubbleContentColor,
2077
+ $bgColor: (a = e.customStyle) == null ? void 0 : a.bubbleBackgroundColor
2078
+ };
2079
+ return n.length === 0 ? e.children ? /* @__PURE__ */ r.createElement(Kt, { ...o }, e.children) : null : /* @__PURE__ */ r.createElement(Kt, { ...o }, n.map((s, l) => s.type === "text" ? /* @__PURE__ */ r.createElement(Yt, { key: l, variant: "body3" }, /* @__PURE__ */ r.createElement(Me, { fallback: s.value }, /* @__PURE__ */ r.createElement(ts, null, s.value))) : s.type === "code" ? /* @__PURE__ */ r.createElement(Me, { key: l, fallback: /* @__PURE__ */ r.createElement(Yt, { variant: "body3" }, s.value) }, /* @__PURE__ */ r.createElement(ns, { code: s.value, language: s.language })) : null), e.children);
2080
+ }
2081
+ const Kt = m.div`display:flex;flex-direction:column;border-radius:12px;overflow:hidden;max-width:${({ $maxWidth: e }) => e}px;${({ theme: e, $color: t, $bgColor: n }) => I`
2082
+ color: ${t || e.colors.messageIncoming.text};
2083
+ background-color: ${n || e.colors.messageIncoming.background};
2084
+ `}
2085
+ padding: 12px 0;
2086
+ transition: max-width 0.3s;
2087
+ overflow-wrap: break-word;
2088
+ `, Yt = m(w)`align-items:flex-start;line-height:140%;white-space:pre-wrap;padding:0 12px;`;
2089
+ function rs(e) {
2090
+ const { stringSet: t } = R(), n = Wn(e) ? /* @__PURE__ */ r.createElement(Zt, { ...e }) : null;
2091
+ if (e.messageType === "user")
2092
+ return n;
2093
+ if (e.messageType === "file") {
2094
+ const o = e.file;
2095
+ return o.type.startsWith("image") || o.type.startsWith("video") ? /* @__PURE__ */ r.createElement(Ki, { ...e }, n) : /* @__PURE__ */ r.createElement(ji, { ...e }, n);
2096
+ }
2097
+ return /* @__PURE__ */ r.createElement(Zt, { ...e, message: t.UNKNOWN__UNKNOWN_MESSAGE_TYPE });
2098
+ }
2099
+ const wt = (e) => /* @__PURE__ */ r.createElement("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ r.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M12.0008 0.973633C10.6172 0.973633 9.49558 2.09527 9.49558 3.47888C9.49558 4.50705 10.115 5.39055 11.0009 5.77664V7.47887H13.0009V5.77653C13.8868 5.3904 14.5061 4.50696 14.5061 3.47888C14.5061 2.09527 13.3844 0.973633 12.0008 0.973633ZM0.250977 16.5788L0.250977 10.5789H2.25098L2.25098 16.5788H0.250977ZM21.7511 10.5789V16.5788H23.7511V10.5789H21.7511ZM18.251 7.47888H3.25097V18.9789C3.25097 20.3596 4.37026 21.4789 5.75097 21.4789H18.251C19.6317 21.4789 20.751 20.3596 20.751 18.9789V9.97887C20.751 8.59816 19.6317 7.47888 18.251 7.47888ZM9.78434 11.9539V15.2038C9.78434 15.7561 9.33663 16.2038 8.78434 16.2038C8.23206 16.2038 7.78434 15.7561 7.78434 15.2038V11.9539C7.78434 11.4016 8.23206 10.9539 8.78434 10.9539C9.33663 10.9539 9.78434 11.4016 9.78434 11.9539ZM16.2677 11.9539V15.2038C16.2677 15.7561 15.82 16.2038 15.2677 16.2038C14.7154 16.2038 14.2677 15.7561 14.2677 15.2038V11.9539C14.2677 11.4016 14.7154 10.9539 15.2677 10.9539C15.82 10.9539 16.2677 11.4016 16.2677 11.9539Z", fill: "#0D0D0D" }));
2100
+ function kt({ id: e, src: t, size: n = 56, onClick: o, style: i }) {
2101
+ return /* @__PURE__ */ r.createElement(os, { id: e, tabIndex: 0, onClick: o, $size: K(n), style: i }, t ? /* @__PURE__ */ r.createElement(is, { src: t }) : /* @__PURE__ */ r.createElement(O, { type: "user", size: n }));
2102
+ }
2103
+ const os = m.div`border-radius:50%;display:inline-block;overflow:hidden;position:relative;flex-shrink:0;height:${(e) => e.$size};width:${(e) => e.$size};background-color:${h.themedColor.bg_100_500};&:focus{outline:none;}`, is = m.img`object-fit:cover;width:100%;height:100%;position:absolute;`;
2104
+ function ss({ sender: e, isBotMessage: t }) {
2105
+ const n = `${de}-sender-avatar`;
2106
+ return !e.profileUrl && t ? /* @__PURE__ */ r.createElement(as, { id: n }, /* @__PURE__ */ r.createElement(wt, null)) : /* @__PURE__ */ r.createElement(kt, { id: n, size: Ye, src: e.profileUrl });
2107
+ }
2108
+ const as = m.div`flex-shrink:0;width:${Ye}px;height:${Ye}px;box-sizing:border-box;padding:6px;border-radius:50%;display:flex;justify-content:center;align-items:center;background-color:${({ theme: e }) => e.colors.base.primary};path{fill:${({ theme: e }) => e.colors.base.primaryContrastContent};}}`;
2109
+ function ls({ sender: e }) {
2110
+ return /* @__PURE__ */ r.createElement(cs, { id: `${de}-sender-name`, variant: "caption1", color: h.themedColor.textMidEmphasis }, e.nickname);
2111
+ }
2112
+ const cs = m(w)`text-align:start;width:100%;box-sizing:border-box;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding-block:5px;padding-inline:0 7px;`;
2113
+ function ds({ createdAt: e }) {
2114
+ const { stringSet: t, format: n } = R();
2115
+ return e ? /* @__PURE__ */ r.createElement(w, { id: `${de}-sent-time`, variant: "caption4", color: h.themedColor.textLowEmphasis }, n(e, t.DATE_FORMAT__MESSAGE_TIMESTAMP)) : null;
2116
+ }
2117
+ function us({ customStyle: e }) {
2118
+ return /* @__PURE__ */ r.createElement(ms, { $bgColor: e == null ? void 0 : e.bubbleBackgroundColor }, [0, 1, 2].map((t) => /* @__PURE__ */ r.createElement(hs, { key: t, $color: e == null ? void 0 : e.bubbleContentColor })));
2119
+ }
2120
+ const ms = m.div`align-items:center;border-radius:12px;display:flex;gap:6px;justify-content:center;padding:16px 12px;background-color:${({ theme: e, $bgColor: t }) => t || e.colors.messageIncoming.background};`, hs = m.span`animation:blink 1.4s infinite;animation-fill-mode:both;border-radius:50%;height:8px;width:8px;background:${({ theme: e, $color: t }) => t || e.colors.messageIncoming.text};@keyframes blink{0%{opacity:0.12;transform:scale(1);}21.43%{opacity:0.38;transform:scale(1.2);}42.86%{opacity:0.12;transform:scale(1);}100%{opacity:0.12;transform:scale(1);}}&:nth-child(1){animation-delay:0.4s;}&:nth-child(2){animation-delay:0.6s;}&:nth-child(3){animation-delay:0.8s;}`;
2121
+ function gs({
2122
+ extendedMessagePayload: e,
2123
+ onClickCTA: t = ({ url: n }) => Bn(n)
2124
+ }) {
2125
+ const n = e == null ? void 0 : e.cta_button;
2126
+ return n ? /* @__PURE__ */ r.createElement(ps, { id: `${de}-ext-cta-button`, role: "button", onClick: () => t(n) }, /* @__PURE__ */ r.createElement(fs, { variant: "button" }, n.label)) : null;
2127
+ }
2128
+ const ps = m.div`display:flex;align-items:center;justify-content:center;cursor:pointer;border-radius:6px;padding:8px;color:${h.themedColor.textHighEmphasis};background-color:${h.color.background50};${D.dark`
2129
+ background-color: ${h.color.ondark.textDisabled};
2130
+ `}
2131
+ `, fs = m(w)`overflow:hidden;text-overflow:ellipsis;white-space:nowrap;`;
2132
+ function bs(e) {
2133
+ return /* @__PURE__ */ r.createElement(r.Fragment, null);
2134
+ }
2135
+ class xs extends Cr {
2136
+ constructor(t) {
2137
+ super(t), this.state = {
2138
+ hasError: !1
2139
+ };
2140
+ }
2141
+ static getDerivedStateFromError() {
2142
+ return { hasError: !0 };
2143
+ }
2144
+ render() {
2145
+ return this.state.hasError ? this.props.errorFallback : /* @__PURE__ */ r.createElement(Me, { fallback: this.props.loadingFallback }, this.props.children);
2146
+ }
2147
+ }
2148
+ const Es = /* @__PURE__ */ new Set(["default"]), { MessageTemplate: vs } = Zr({
2149
+ parser: Gr,
2150
+ renderer: Wr,
2151
+ Container: (e) => /* @__PURE__ */ r.createElement("div", { ...e })
2152
+ });
2153
+ function Cs(e) {
2154
+ return /* @__PURE__ */ r.createElement(
2155
+ xs,
2156
+ {
2157
+ errorFallback: e.messageTemplateErrorFallback,
2158
+ loadingFallback: e.messageTemplateLoadingFallback
2159
+ },
2160
+ /* @__PURE__ */ r.createElement(ys, { ...e })
2161
+ );
2162
+ }
2163
+ const ys = ({
2164
+ extendedMessagePayload: e,
2165
+ onGetCachedMessageTemplate: t = () => null,
2166
+ onRequestMessageTemplate: n,
2167
+ onHandleTemplateInternalAction: o = Oe
2168
+ }) => {
2169
+ const i = e == null ? void 0 : e.message_template;
2170
+ if (!Es.has((i == null ? void 0 : i.type) ?? "default")) throw new Error("Unsupported template type");
2171
+ if (!n) throw new Error("onRequestMessageTemplate is required");
2172
+ const { theme: s } = ri(), l = Vo({
2173
+ onRequestTemplate: n,
2174
+ onGetCachedTemplate: t,
2175
+ theme: s.selectedTheme,
2176
+ templateKey: (i == null ? void 0 : i.key) ?? "invalid",
2177
+ variables: i == null ? void 0 : i.variables,
2178
+ viewVariables: i == null ? void 0 : i.view_variables,
2179
+ aiAgentColorVariables: s.aiAgentColorVariables
2180
+ });
2181
+ return /* @__PURE__ */ r.createElement(_s, { id: `${de}-ext-message-template` }, /* @__PURE__ */ r.createElement(
2182
+ jr,
2183
+ {
2184
+ handleInternalAction: (c, d) => {
2185
+ c.stopPropagation(), o == null || o(d);
2186
+ }
2187
+ },
2188
+ /* @__PURE__ */ r.createElement(vs, { templateItems: l.body.items, templateVersion: l.version })
2189
+ ));
2190
+ }, _s = m.div`box-sizing:border-box;overflow:hidden;width:100%;`;
2191
+ function Ts({
2192
+ extendedMessagePayload: e,
2193
+ onClickSuggestedReply: t,
2194
+ suggestedRepliesDirection: n = "vertical"
2195
+ }) {
2196
+ const [o, i] = _(!1), a = (e == null ? void 0 : e.suggested_replies) ?? [];
2197
+ return a.length === 0 || o ? null : /* @__PURE__ */ r.createElement(Ss, { id: `${de}-ext-suggested-replies`, $type: n }, a.map((s, l) => /* @__PURE__ */ r.createElement(
2198
+ ws,
2199
+ {
2200
+ key: l,
2201
+ $type: n,
2202
+ variant: "body3",
2203
+ onClick: () => {
2204
+ t && (t == null || t({ reply: s }), i(!0));
2205
+ }
2206
+ },
2207
+ s
2208
+ )));
2209
+ }
2210
+ const Ss = m.div`margin:16px 0;padding:0 ${re}px;position:relative;display:flex;gap:8px;${({ $type: e }) => e === "vertical" ? ks : As};`, ws = m(w)`box-sizing:border-box;padding:8px 12px;display:flex;align-items:center;border-radius:20px / clamp(20px,5%,100px);cursor:pointer;word-break:break-word;color:${h.color.primary.main};border:1px solid ${h.color.primary.main};background-color:${h.themedColor.bg_50_600};&:hover{background-color:${h.themedColor.bg_100_500};}${({ $type: e, theme: t }) => I`
2211
+ ${e === "vertical" ? Is : $s};
2212
+ &:active {
2213
+ background-color: ${t.colors.base.primary};
2214
+ color: ${t.colors.base.primaryContrastContent};
2215
+ }
2216
+ `}
2217
+ `, ks = I`flex-direction:column;align-items:flex-end;`, As = I`flex-direction:row;overflow-x:scroll;-ms-overflow-style:none;scrollbar-width:none;&::-webkit-scrollbar{display:none;}`, Is = I`max-width:calc(100% - 70px);white-space:pre-wrap;`, $s = I`white-space:nowrap;`;
2218
+ function At(e) {
2219
+ return e();
2220
+ }
2221
+ const Te = we({
2222
+ template: Ms,
2223
+ components: {
2224
+ SenderName: ls,
2225
+ SenderAvatar: ss,
2226
+ SentTime: ds,
2227
+ MessageBody: rs,
2228
+ TypingIndicator: us,
2229
+ SuggestedReplies: Ts,
2230
+ MessageTemplate: Cs,
2231
+ CTAButton: gs,
2232
+ MessageLogs: bs
2233
+ }
2234
+ });
2235
+ function Ms(e) {
2236
+ return /* @__PURE__ */ r.createElement(jn, { ...e, testerMode: !1 });
2237
+ }
2238
+ function jn(e) {
2239
+ var p, g, b, x;
2240
+ const { components: t } = Te.useContext(), n = !!e.isTyping, o = e.testerMode, i = !!((p = e.extendedMessagePayload) != null && p.message_template), a = !!((g = e.extendedMessagePayload) != null && g.cta_button), s = !!e.createdAt, l = At(() => e.messageType === "user" ? e.message.length > 0 : !0), c = e.groupType === "top" || e.groupType === "single", d = e.groupType === "bottom" || e.groupType === "single", u = o ? 0 : Ye;
2241
+ return /* @__PURE__ */ r.createElement(Os, { $marginBottom: n ? 0 : _t(e.groupType) }, c && /* @__PURE__ */ r.createElement(Ls, null, !o && /* @__PURE__ */ r.createElement(t.SenderAvatar, { ...e }), /* @__PURE__ */ r.createElement(t.SenderName, { ...e })), /* @__PURE__ */ r.createElement(Pt, null, /* @__PURE__ */ r.createElement(at, { $extraStartPadding: u }, n && /* @__PURE__ */ r.createElement(t.TypingIndicator, { ...e }), /* @__PURE__ */ r.createElement(t.MessageBody, { ...e }, a && /* @__PURE__ */ r.createElement("div", { style: { marginTop: 12, marginInline: 12 } }, /* @__PURE__ */ r.createElement(t.CTAButton, { ...e })))), i && /* @__PURE__ */ r.createElement(qt, { $startPadding: 0, $endPadding: 0, style: { marginTop: l ? ke : 0 } }, /* @__PURE__ */ r.createElement(
2242
+ t.MessageTemplate,
2243
+ {
2244
+ ...e,
2245
+ messageTemplateErrorFallback: e.messageTemplateErrorFallback ?? /* @__PURE__ */ r.createElement(at, { $extraStartPadding: u }, /* @__PURE__ */ r.createElement(
2246
+ t.MessageBody,
2247
+ {
2248
+ ...e,
2249
+ messageType: "user",
2250
+ message: ((x = (b = e.extendedMessagePayload) == null ? void 0 : b.message_template) == null ? void 0 : x.fallback_message) ?? "Cannot read this template."
2251
+ }
2252
+ )),
2253
+ messageTemplateLoadingFallback: e.messageTemplateLoadingFallback ?? /* @__PURE__ */ r.createElement(at, { $extraStartPadding: u }, /* @__PURE__ */ r.createElement(t.TypingIndicator, { ...e }))
2254
+ }
2255
+ ))), d && s && /* @__PURE__ */ r.createElement(Rs, { $extraStartPadding: u + 8 }, /* @__PURE__ */ r.createElement(t.SentTime, { ...e })), /* @__PURE__ */ r.createElement(Pt, null, e.suggestedRepliesVisible && /* @__PURE__ */ r.createElement(qt, null, /* @__PURE__ */ r.createElement(t.SuggestedReplies, { ...e })), /* @__PURE__ */ r.createElement(t.MessageLogs, { ...e })));
2256
+ }
2257
+ const Os = m.div`display:flex;flex-direction:column;align-items:flex-start;margin-bottom:${({ $marginBottom: e }) => `${e}px`};
2258
+ `, tt = m.div`display:flex;align-self:stretch;justify-content:flex-start;${({ $startPadding: e = re, $endPadding: t = re, $extraStartPadding: n = 0 }) => `
2259
+ padding-inline: ${e + n}px ${t}px;
2260
+ `}
2261
+ `, Ls = m(tt)`display:flex;flex-direction:row;align-items:center;gap:8px;`, at = m(tt)`display:flex;`, Rs = m(tt)`margin-top:${Vn}px;display:flex;align-items:flex-start;justify-content:flex-start;`, qt = m(tt)`display:flex;flex-direction:column;${({ $startPadding: e = re, $endPadding: t = re, $extraStartPadding: n = 0 }) => `
2262
+ padding-inline: ${e + n}px ${t}px;
2263
+ `}
2264
+ `;
2265
+ function Ns({ file: e, children: t, onClickFile: n }) {
2266
+ return /* @__PURE__ */ r.createElement(Ds, null, /* @__PURE__ */ r.createElement(
2267
+ St,
2268
+ {
2269
+ name: e.name,
2270
+ type: Tt(e.name, e.type),
2271
+ onClick: n && (() => n == null ? void 0 : n(e))
2272
+ }
2273
+ ), t);
2274
+ }
2275
+ const Ds = m.div`display:flex;flex-direction:column;align-items:flex-end;gap:${ke}px;`, Zn = ({ className: e, children: t, size: n = 26 }) => /* @__PURE__ */ r.createElement(Ps, { className: e, $size: n }, t ?? /* @__PURE__ */ r.createElement(O, { type: "spinner", size: n })), Ps = m.div`display:flex;align-items:center;justify-content:center;width:${({ $size: e }) => K(e)};height:${({ $size: e }) => K(e)};animation:1s infinite linear;animation-name:rotate;@keyframes rotate{from{transform:rotate(0);}to{transform:rotate(360deg);}}`;
2276
+ function Bs({ file: e, metadata: t, onClickMedia: n, children: o }) {
2277
+ const { aspectRatio: i, localFile: a } = t, [s] = _(() => a instanceof File ? URL.createObjectURL(a) : e.url), [l, c] = _(!1), d = {
2278
+ onClick: () => n == null ? void 0 : n(e),
2279
+ $ratio: i
2280
+ };
2281
+ return /* @__PURE__ */ r.createElement(Fs, null, /* @__PURE__ */ r.createElement(Us, { ...d }, !l && /* @__PURE__ */ r.createElement(Zn, { size: 26 }, /* @__PURE__ */ r.createElement(O, { type: "spinner", color: "textLowEmphasis", size: 26 })), /* @__PURE__ */ r.createElement(Hs, { $loaded: l, src: s, alt: "image-message", onLoad: () => c(!0) })), o);
2282
+ }
2283
+ const Fs = m.div`display:flex;flex-direction:column;align-items:flex-end;gap:${ke}px;`, Us = m.div`width:${Pe}px;border-radius:12px;overflow:hidden;cursor:pointer;height:auto;aspect-ratio:${(e) => e.$ratio};position:relative;display:flex;align-items:center;justify-content:center;${D.light`
2284
+ background-color: ${h.color.background100};
2285
+ `}
2286
+ ${D.dark`
2287
+ background-color: ${h.color.background400};
2288
+ `}
2289
+ `, Hs = m.img`position:absolute;width:100%;height:100%;inset-block-start:0;inset-inline-start:0;object-fit:cover;opacity:${(e) => e.$loaded ? 1 : 0};transition:opacity 0.5s ease;`;
2290
+ function Jt(e) {
2291
+ var n, o;
2292
+ const t = ye(() => yn.sanitize(Gn(e.message)), [e.message]);
2293
+ return /* @__PURE__ */ r.createElement(
2294
+ zs,
2295
+ {
2296
+ $maxWidth: e.maxBodyWidth ?? Pe,
2297
+ $color: (n = e.customStyle) == null ? void 0 : n.bubbleContentColor,
2298
+ $bgColor: (o = e.customStyle) == null ? void 0 : o.bubbleBackgroundColor
2299
+ },
2300
+ /* @__PURE__ */ r.createElement(Vs, { variant: "body3", dangerouslySetInnerHTML: { __html: t } })
2301
+ );
2302
+ }
2303
+ const zs = m.div`display:flex;flex-direction:column;border-radius:12px;overflow:hidden;max-width:${({ $maxWidth: e }) => e}px;${({ theme: e, $color: t, $bgColor: n }) => I`
2304
+ color: ${t || e.colors.messageOutgoing.text};
2305
+ background-color: ${n || e.colors.messageOutgoing.background};
2306
+ `}
2307
+ padding: 12px 0;
2308
+ transition: max-width 0.3s;
2309
+ overflow-wrap: break-word;
2310
+ `, Vs = m(w)`align-items:flex-start;line-height:140%;white-space:pre-wrap;padding:0 12px;`;
2311
+ function Ws(e) {
2312
+ const { stringSet: t } = R(), n = Wn(e) ? /* @__PURE__ */ r.createElement(Jt, { ...e }) : null;
2313
+ return e.messageType === "user" ? n : e.messageType === "file" ? e.file.type.startsWith("image") ? /* @__PURE__ */ r.createElement(Bs, { ...e }, n) : /* @__PURE__ */ r.createElement(Ns, { ...e }, n) : /* @__PURE__ */ r.createElement(Jt, { ...e, message: t.UNKNOWN__UNKNOWN_MESSAGE_TYPE });
2314
+ }
2315
+ function Gs({ sendingStatus: e }) {
2316
+ const t = bt();
2317
+ switch (e) {
2318
+ case "pending":
2319
+ return /* @__PURE__ */ r.createElement(js, { size: 16 }, /* @__PURE__ */ r.createElement(O, { type: "spinner", color: t.colors.messageOutgoing.background, size: 16 }));
2320
+ case "failed":
2321
+ return /* @__PURE__ */ r.createElement("div", { style: { marginBottom: 2 } }, /* @__PURE__ */ r.createElement(O, { type: "error", color: h.themedColor.error, size: 16 }));
2322
+ case "scheduled":
2323
+ case "canceled":
2324
+ return null;
2325
+ default:
2326
+ return /* @__PURE__ */ r.createElement("div", null, /* @__PURE__ */ r.createElement(O, { type: "chevron-down" }));
2327
+ }
2328
+ }
2329
+ const js = m(Zn)`margin-bottom:2px;width:16px;height:16px;`;
2330
+ function Zs({ createdAt: e }) {
2331
+ const { stringSet: t, format: n } = R();
2332
+ return e ? /* @__PURE__ */ r.createElement(w, { variant: "caption4", color: h.themedColor.textLowEmphasis }, n(e, t.DATE_FORMAT__MESSAGE_TIMESTAMP)) : null;
2333
+ }
2334
+ const It = we({
2335
+ template: Ks,
2336
+ components: {
2337
+ SendingStatus: Gs,
2338
+ SentTime: Zs,
2339
+ MessageBody: Ws
2340
+ }
2341
+ });
2342
+ function Ks(e) {
2343
+ const { components: t } = It.useContext(), n = e.sendingStatus === "succeeded", o = e.groupType === "bottom" || e.groupType === "single";
2344
+ return /* @__PURE__ */ r.createElement(Ys, { $marginBottom: _t(e.groupType) }, /* @__PURE__ */ r.createElement(qs, null, /* @__PURE__ */ r.createElement(t.MessageBody, { ...e })), o && /* @__PURE__ */ r.createElement(Js, { $extraEndPadding: 8 }, n ? /* @__PURE__ */ r.createElement(t.SentTime, { ...e }) : /* @__PURE__ */ r.createElement(t.SendingStatus, { ...e })));
2345
+ }
2346
+ const Ys = m.div`display:flex;flex:1;flex-direction:column;align-items:flex-end;margin-bottom:${({ $marginBottom: e }) => `${e}px`};
2347
+ `, Kn = m.div`display:flex;align-self:stretch;justify-content:flex-end;${({ $startPadding: e = re, $endPadding: t = re, $extraEndPadding: n = 0 }) => `padding-inline: ${e}px ${t + n}px;`};
2348
+ `, qs = m(Kn)``, Js = m(Kn)`margin-top:${Vn}px;`;
2349
+ function Xs(e) {
2350
+ return e.messageType !== "admin" ? null : /* @__PURE__ */ r.createElement(Qs, null, /* @__PURE__ */ r.createElement(w, { variant: "caption2", color: h.themedColor.textMidEmphasis }, ea(yn.sanitize(e.message))));
2351
+ }
2352
+ const Qs = m.div`text-align:center;text-wrap:pretty;a{text-decoration:none;color:inherit;}`, ea = (e) => {
2353
+ const t = /\[([^\]]+)\]\((https?:\/\/[^\s]+)\)/g, n = [];
2354
+ let o = 0;
2355
+ return e.replace(t, (i, a, s, l) => (n.push(e.slice(o, l)), n.push(
2356
+ /* @__PURE__ */ r.createElement("a", { key: s, href: s, target: "_blank", rel: Ct }, a)
2357
+ ), o = l + i.length, i)), n.push(e.slice(o)), n;
2358
+ }, ta = ({ submitted: e, defaultValue: t, value: n, onChange: o }) => {
2359
+ const { stringSet: i } = R();
2360
+ return N(() => {
2361
+ typeof n > "u" && typeof t == "boolean" && (o == null || o(t));
2362
+ }, [n, t]), /* @__PURE__ */ r.createElement(na, null, /* @__PURE__ */ r.createElement(w, { variant: "caption2", color: h.themedColor.textMidEmphasis }, i.CSAT_CRE_TITLE), /* @__PURE__ */ r.createElement("div", null, /* @__PURE__ */ r.createElement(
2363
+ Xt,
2364
+ {
2365
+ checked: n === !0,
2366
+ label: i.CSAT_CRE_SOLVED,
2367
+ disabled: e,
2368
+ onClick: () => o == null ? void 0 : o(!0)
2369
+ }
2370
+ ), /* @__PURE__ */ r.createElement(
2371
+ Xt,
2372
+ {
2373
+ checked: n === !1,
2374
+ label: i.CSAT_CRE_NOT_SOLVED,
2375
+ disabled: e,
2376
+ onClick: () => o == null ? void 0 : o(!1)
2377
+ }
2378
+ )));
2379
+ }, Xt = ({ onClick: e, checked: t, label: n, disabled: o }) => {
2380
+ const i = t ? h.color.primary.main : o ? h.themedColor.textDisabled : h.themedColor.textLowEmphasis, a = t ? h.themedColor.textHighEmphasis : o ? h.themedColor.textLowEmphasis : h.themedColor.textHighEmphasis;
2381
+ return /* @__PURE__ */ r.createElement(ra, { onClick: e, disabled: o }, /* @__PURE__ */ r.createElement(O, { size: 24, type: t ? "radio-on" : "radio-off", color: i }), /* @__PURE__ */ r.createElement(w, { variant: "caption2", color: a }, n));
2382
+ }, na = m.div`display:flex;flex-direction:column;gap:8px;`, ra = m.button`all:unset;display:flex;align-items:center;justify-content:flex-start;gap:2px;span{line-height:initial;}&:enabled{cursor:pointer;}`, oa = (e) => /* @__PURE__ */ r.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", id: "csat1", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M2.08301 20C2.08301 10.1049 10.1046 2.08334 19.9997 2.08334C29.8948 2.08334 37.9163 10.1049 37.9163 20C37.9163 29.8952 29.8948 37.9167 19.9997 37.9167C10.1046 37.9167 2.08301 29.8952 2.08301 20Z", fill: "#E0E0E0" }), /* @__PURE__ */ r.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M12.5824 29.3328C13.1344 29.7473 13.918 29.636 14.3326 29.084C15.6269 27.3607 17.6835 26.25 19.9997 26.25C22.316 26.25 24.3727 27.3607 25.6668 29.084C26.0815 29.636 26.865 29.7473 27.4172 29.3328C27.9692 28.9182 28.0805 28.1347 27.6658 27.5825C25.9198 25.2577 23.1357 23.75 19.9997 23.75C16.8638 23.75 14.0797 25.2577 12.3336 27.5825C11.919 28.1347 12.0304 28.9182 12.5824 29.3328Z", fill: "black", fillOpacity: 0.12 }), /* @__PURE__ */ r.createElement("path", { d: "M28.4449 13.7707C29.1324 13.8328 29.64 14.4406 29.578 15.1281C29.516 15.8153 28.909 16.3221 28.2219 16.2608C28.2219 16.2608 28.0282 16.2502 27.9267 16.2487C27.7224 16.2457 27.4382 16.2509 27.1224 16.2833C26.7864 16.3177 26.4644 16.3782 26.1799 16.4662L26.304 16.86C26.7792 18.3675 25.5094 19.5813 24.2057 19.5813C23.504 19.5813 22.8319 19.2617 22.4295 18.6857C22.0025 18.0745 21.9417 17.241 22.4075 16.5344C22.7505 16.0143 23.2444 15.3831 23.8959 14.8657C24.8355 14.1195 26.0435 13.8809 26.867 13.7963C27.3024 13.7517 28.0149 13.7319 28.4449 13.7707Z", fill: "black", fillOpacity: 0.12 }), /* @__PURE__ */ r.createElement("path", { d: "M11.5553 13.7707C10.8677 13.8328 10.3601 14.4406 10.4221 15.1281C10.4842 15.8153 11.0912 16.3221 11.7782 16.2608C11.7782 16.2608 11.972 16.2502 12.0734 16.2487C12.2778 16.2457 12.562 16.2509 12.8778 16.2833C13.2137 16.3177 13.5357 16.3782 13.8203 16.4662L13.6962 16.86C13.2209 18.3675 14.4907 19.5813 15.7944 19.5813C16.4962 19.5813 17.1683 19.2617 17.5707 18.6857C17.9975 18.0745 18.0585 17.241 17.5925 16.5344C17.2497 16.0143 16.7557 15.3831 16.1043 14.8657C15.1646 14.1195 13.9566 13.8809 13.1331 13.7963C12.6978 13.7517 11.9853 13.7319 11.5553 13.7707Z", fill: "black", fillOpacity: 0.12 })), ia = (e) => /* @__PURE__ */ r.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M2.08337 19.9999C2.08337 10.1048 10.1049 2.08325 20 2.08325C29.8952 2.08325 37.9167 10.1048 37.9167 19.9999C37.9167 29.8951 29.8952 37.9166 20 37.9166C10.1049 37.9166 2.08337 29.8951 2.08337 19.9999Z", fill: "url(#paint0_linear_159_173206)" }), /* @__PURE__ */ r.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M12.5828 29.3328C13.1348 29.7473 13.9184 29.636 14.3329 29.084C15.6272 27.3607 17.6839 26.25 20 26.25C22.3164 26.25 24.373 27.3607 25.6672 29.084C26.0819 29.636 26.8654 29.7473 27.4175 29.3328C27.9695 28.9182 28.0809 28.1347 27.6662 27.5825C25.9202 25.2577 23.136 23.75 20 23.75C16.8642 23.75 14.0801 25.2577 12.334 27.5825C11.9194 28.1347 12.0308 28.9182 12.5828 29.3328Z", fill: "#141B34" }), /* @__PURE__ */ r.createElement("path", { d: "M28.4454 13.7707C29.1329 13.8328 29.6405 14.4406 29.5785 15.1281C29.5165 15.8153 28.9095 16.3221 28.2224 16.2608C28.2224 16.2608 28.0287 16.2502 27.9272 16.2487C27.7229 16.2457 27.4387 16.2509 27.1229 16.2833C26.7869 16.3177 26.4649 16.3782 26.1804 16.4662L26.3045 16.86C26.7797 18.3675 25.5099 19.5813 24.2062 19.5813C23.5045 19.5813 22.8324 19.2617 22.43 18.6857C22.003 18.0745 21.9422 17.241 22.408 16.5344C22.751 16.0143 23.2449 15.3831 23.8964 14.8657C24.836 14.1195 26.044 13.8809 26.8675 13.7963C27.3029 13.7517 28.0154 13.7319 28.4454 13.7707Z", fill: "#141B34" }), /* @__PURE__ */ r.createElement("path", { d: "M11.5549 13.7707C10.8674 13.8328 10.3597 14.4406 10.4218 15.1281C10.4838 15.8153 11.0908 16.3221 11.7779 16.2608C11.7779 16.2608 11.9716 16.2502 12.073 16.2487C12.2774 16.2457 12.5616 16.2509 12.8774 16.2833C13.2134 16.3177 13.5353 16.3782 13.8199 16.4662L13.6958 16.86C13.2205 18.3675 14.4904 19.5813 15.794 19.5813C16.4958 19.5813 17.168 19.2617 17.5703 18.6857C17.9971 18.0745 18.0581 17.241 17.5921 16.5344C17.2493 16.0143 16.7553 15.3831 16.1039 14.8657C15.1643 14.1195 13.9562 13.8809 13.1327 13.7963C12.6974 13.7517 11.9849 13.7319 11.5549 13.7707Z", fill: "#141B34" }), /* @__PURE__ */ r.createElement("defs", null, /* @__PURE__ */ r.createElement("linearGradient", { id: "paint0_linear_159_173206", x1: 20, y1: 2.08325, x2: 20, y2: 37.9166, gradientUnits: "userSpaceOnUse" }, /* @__PURE__ */ r.createElement("stop", { stopColor: "#FF2D1D" }), /* @__PURE__ */ r.createElement("stop", { offset: 1, stopColor: "#FFA540" })))), sa = (e) => /* @__PURE__ */ r.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M19.9997 36.6667C29.2044 36.6667 36.6663 29.2048 36.6663 20C36.6663 10.7953 29.2044 3.33334 19.9997 3.33334C10.7949 3.33334 3.33301 10.7953 3.33301 20C3.33301 29.2048 10.7949 36.6667 19.9997 36.6667Z", fill: "#E0E0E0" }), /* @__PURE__ */ r.createElement("path", { d: "M15 28.333C16.3927 27.2867 18.124 26.6667 20 26.6667C21.876 26.6667 23.6073 27.2867 25 28.333", stroke: "black", strokeOpacity: 0.12, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" }), /* @__PURE__ */ r.createElement("path", { d: "M11.667 13.3511C11.667 13.3511 14.0161 13.139 15.3268 14.18M15.3268 14.18L14.8882 15.5711C14.7153 16.1199 15.1675 16.6667 15.7943 16.6667C16.4531 16.6667 16.8882 16.0723 16.549 15.5579C16.2483 15.102 15.8388 14.5866 15.3268 14.18ZM23.3337 13.3511C23.3337 13.3511 25.6827 13.139 26.9935 14.18M26.9935 14.18L26.555 15.5711C26.382 16.1199 26.8342 16.6667 27.461 16.6667C28.1198 16.6667 28.5548 16.0723 28.2157 15.5579C27.915 15.102 27.5055 14.5866 26.9935 14.18Z", stroke: "black", strokeOpacity: 0.12, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" })), aa = (e) => /* @__PURE__ */ r.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M2.083 20C2.083 10.105 10.105 2.083 20 2.083c9.895 0 17.917 8.021 17.917 17.917 0 9.895-8.022 17.917-17.917 17.917C10.105 37.917 2.083 29.895 2.083 20Z", fill: "#FFD46E" }), /* @__PURE__ */ r.createElement("path", { d: "M14.249 27.334C15.851 26.13 17.844 25.417 20 25.417c2.156 0 4.149.714 5.751 1.917.553.415.664 1.199.25 1.751-.415.552-1.199.664-1.751.25-1.183-.889-2.652-1.416-4.25-1.416s-3.067.527-4.25 1.416c-.553.414-1.336.302-1.751-.25-.415-.552-.303-1.336.249-1.751Z", fill: "#141B34" }), /* @__PURE__ */ r.createElement("path", { d: "M23.445 14.596c-.687.062-1.294-.445-1.356-1.132-.062-.687.445-1.295 1.132-1.357.082-.005.342-.02.482-.022.277-.004.662.002 1.097.047.823.085 2.031.323 2.97 1.07.652.518 1.146 1.15 1.489 1.67.466.706.405 1.54-.022 2.15-.402.576-1.074.896-1.775.896-1.304 0-2.573-1.214-2.098-2.722l.125-.394c-.285-.088-.607-.148-.942-.182-.316-.033-.6-.038-.804-.035-.101.002-.242.01-.294.013Z", fill: "#141B34" }), /* @__PURE__ */ r.createElement("path", { d: "M11.779 14.596c-.687.062-1.294-.445-1.356-1.132-.062-.687.445-1.295 1.132-1.357.082-.005.342-.02.482-.022.277-.004.662.002 1.097.047.823.085 2.031.323 2.97 1.07.652.518 1.146 1.15 1.489 1.67.466.706.405 1.54-.022 2.15-.402.576-1.074.896-1.775.896-1.304 0-2.573-1.214-2.098-2.722l.124-.394c-.284-.088-.606-.148-.941-.182-.316-.033-.6-.038-.804-.035-.101.002-.243.01-.294.013Z", fill: "#141B34" })), la = (e) => /* @__PURE__ */ r.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M19.9997 36.6667C29.2044 36.6667 36.6663 29.2048 36.6663 20C36.6663 10.7953 29.2044 3.33334 19.9997 3.33334C10.7949 3.33334 3.33301 10.7953 3.33301 20C3.33301 29.2048 10.7949 36.6667 19.9997 36.6667Z", fill: "#E0E0E0" }), /* @__PURE__ */ r.createElement("path", { d: "M13.348 15H13.333M26.6663 15H26.6513", stroke: "black", strokeOpacity: 0.12, strokeWidth: 3.33333, strokeLinecap: "round", strokeLinejoin: "round" }), /* @__PURE__ */ r.createElement("path", { d: "M15 26.6667H25", stroke: "black", strokeOpacity: 0.12, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" })), ca = (e) => /* @__PURE__ */ r.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M2.083 20C2.083 10.105 10.105 2.083 20 2.083c9.895 0 17.917 8.021 17.917 17.917 0 9.895-8.022 17.917-17.917 17.917C10.105 37.917 2.083 29.895 2.083 20Z", fill: "#FFD46E" }), /* @__PURE__ */ r.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M11.25 15c0-1.151.933-2.083 2.083-2.083h.015c1.151 0 2.084.933 2.084 2.083 0 1.151-.933 2.083-2.084 2.083h-.015c-1.15 0-2.083-.933-2.083-2.083ZM24.568 15c0-1.151.933-2.083 2.084-2.083h.015c1.151 0 2.083.933 2.083 2.083 0 1.151-.932 2.083-2.083 2.083h-.015c-1.151 0-2.084-.933-2.084-2.083Z", fill: "#141B34" }), /* @__PURE__ */ r.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M13.75 26.667c0-.691.56-1.25 1.25-1.25h10c.69 0 1.25.559 1.25 1.25 0 .691-.56 1.25-1.25 1.25h-10c-.69 0-1.25-.559-1.25-1.25Z", fill: "#141B34" })), da = (e) => /* @__PURE__ */ r.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M19.9997 36.6667C29.2044 36.6667 36.6663 29.2048 36.6663 20C36.6663 10.7953 29.2044 3.33334 19.9997 3.33334C10.7949 3.33334 3.33301 10.7953 3.33301 20C3.33301 29.2048 10.7949 36.6667 19.9997 36.6667Z", fill: "#E0E0E0" }), /* @__PURE__ */ r.createElement("path", { d: "M13.333 25C14.8532 27.024 17.2735 28.3333 19.9997 28.3333C22.7258 28.3333 25.1462 27.024 26.6663 25", stroke: "black", strokeOpacity: 0.12, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" }), /* @__PURE__ */ r.createElement("path", { d: "M13.348 15H13.333M26.6663 15H26.6513", stroke: "black", strokeOpacity: 0.12, strokeWidth: 3.33333, strokeLinecap: "round", strokeLinejoin: "round" })), ua = (e) => /* @__PURE__ */ r.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M2.083 20C2.083 10.105 10.105 2.083 20 2.083c9.895 0 17.917 8.021 17.917 17.917 0 9.895-8.022 17.917-17.917 17.917C10.105 37.917 2.083 29.895 2.083 20Z", fill: "#FFD46E" }), /* @__PURE__ */ r.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M12.583 24.001c.552-.414 1.335-.302 1.75.25 1.294 1.723 3.35 2.834 5.667 2.834s4.373-1.11 5.667-2.834c.415-.552 1.199-.664 1.751-.25.552.415.664 1.199.25 1.751C25.92 28.076 23.136 29.584 20 29.584s-5.92-1.508-7.666-3.832c-.415-.552-.303-1.336.249-1.751Z", fill: "#141B34" }), /* @__PURE__ */ r.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M11.25 15c0-1.151.933-2.083 2.083-2.083h.015c1.151 0 2.084.933 2.084 2.083 0 1.151-.933 2.083-2.084 2.083h-.015c-1.15 0-2.083-.933-2.083-2.083ZM24.568 15c0-1.151.933-2.083 2.084-2.083h.015c1.151 0 2.083.933 2.083 2.083 0 1.151-.932 2.083-2.083 2.083h-.015c-1.151 0-2.084-.933-2.084-2.083Z", fill: "#141B34" })), ma = (e) => /* @__PURE__ */ r.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M19.9997 36.6663C29.2044 36.6663 36.6663 29.2044 36.6663 19.9997C36.6663 10.7949 29.2044 3.33301 19.9997 3.33301C10.7949 3.33301 3.33301 10.7949 3.33301 19.9997C3.33301 29.2044 10.7949 36.6663 19.9997 36.6663Z", fill: "#E0E0E0" }), /* @__PURE__ */ r.createElement("path", { d: "M19.9997 30C23.16 30 25.8145 27.867 26.56 24.9832C26.9068 23.6413 26.4033 23.3333 25.0765 23.3333H14.9228C13.5959 23.3333 13.0925 23.6413 13.4393 24.9832C14.1848 27.867 16.8393 30 19.9997 30Z", stroke: "black", strokeOpacity: 0.12, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" }), /* @__PURE__ */ r.createElement("path", { d: "M11.667 15.8333C11.667 14.4526 12.7863 13.3333 14.167 13.3333C15.5477 13.3333 16.667 14.4526 16.667 15.8333M23.3337 15.8333C23.3337 14.4526 24.453 13.3333 25.8337 13.3333C27.2143 13.3333 28.3337 14.4526 28.3337 15.8333", stroke: "black", strokeOpacity: 0.12, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" })), ha = (e) => /* @__PURE__ */ r.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 40, height: 40, viewBox: "0 0 40 40", fill: "none", ...e }, /* @__PURE__ */ r.createElement("path", { d: "M2.083 20C2.083 10.105 10.105 2.083 20 2.083c9.895 0 17.917 8.021 17.917 17.917 0 9.895-8.022 17.917-17.917 17.917C10.105 37.917 2.083 29.895 2.083 20Z", fill: "#FFD46E" }), /* @__PURE__ */ r.createElement("g", { clipPath: "url(#clip0_159_173224)" }, /* @__PURE__ */ r.createElement("g", { clipPath: "url(#clip1_159_173224)" }, /* @__PURE__ */ r.createElement("path", { d: "M20 30.624c3.752 0 6.904-2.532 7.789-5.956.412-1.593-.185-1.959-1.76-1.959H13.973c-1.575 0-2.173.366-1.761 1.959.885 3.424 4.037 5.956 7.788 5.956Z", fill: "#141B34" })), /* @__PURE__ */ r.createElement("mask", { id: "mask0_159_173224", style: {
2383
+ maskType: "alpha"
2384
+ }, maskUnits: "userSpaceOnUse", x: 12, y: 22, width: 16, height: 9 }, /* @__PURE__ */ r.createElement("path", { d: "M20 30.624c3.752 0 6.904-2.532 7.789-5.956.412-1.593-.185-1.959-1.76-1.959H13.973c-1.575 0-2.173.366-1.761 1.959.885 3.424 4.037 5.956 7.788 5.956Z", fill: "#141B34" })), /* @__PURE__ */ r.createElement("g", { mask: "url(#mask0_159_173224)" }, /* @__PURE__ */ r.createElement("path", { d: "M20 32.998c3.278 0 5.936-1.594 5.936-3.561 0-1.968-2.658-3.562-5.936-3.562-3.278 0-5.936 1.594-5.936 3.562 0 1.967 2.658 3.561 5.936 3.561Z", fill: "#FF493B" }))), /* @__PURE__ */ r.createElement("path", { d: "M11.667 15.833c0-1.381 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5M23.333 15.833c0-1.381 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5", stroke: "#141B34", strokeWidth: 2.5, strokeLinecap: "round", strokeLinejoin: "round" }), /* @__PURE__ */ r.createElement("defs", null, /* @__PURE__ */ r.createElement("clipPath", { id: "clip0_159_173224" }, /* @__PURE__ */ r.createElement("rect", { width: 15.83, height: 7.915, fill: "white", transform: "translate(12.085 22.709)" })), /* @__PURE__ */ r.createElement("clipPath", { id: "clip1_159_173224" }, /* @__PURE__ */ r.createElement("rect", { width: 15.83, height: 7.915, fill: "white", transform: "translate(12.085 22.709)" })))), ga = [
2385
+ {
2386
+ value: 1,
2387
+ Icon: {
2388
+ Active: ia,
2389
+ Inactive: oa
2390
+ },
2391
+ isActive: (e) => e <= 1,
2392
+ getTooltip: (e) => e.CSAT5_RATING_SCORE_1
2393
+ },
2394
+ {
2395
+ value: 2,
2396
+ Icon: {
2397
+ Active: aa,
2398
+ Inactive: sa
2399
+ },
2400
+ isActive: (e) => e === 2,
2401
+ getTooltip: (e) => e.CSAT5_RATING_SCORE_2
2402
+ },
2403
+ {
2404
+ value: 3,
2405
+ Icon: {
2406
+ Active: ca,
2407
+ Inactive: la
2408
+ },
2409
+ isActive: (e) => e === 3,
2410
+ getTooltip: (e) => e.CSAT5_RATING_SCORE_3
2411
+ },
2412
+ {
2413
+ value: 4,
2414
+ Icon: {
2415
+ Active: ua,
2416
+ Inactive: da
2417
+ },
2418
+ isActive: (e) => e === 4,
2419
+ getTooltip: (e) => e.CSAT5_RATING_SCORE_4
2420
+ },
2421
+ {
2422
+ value: 5,
2423
+ Icon: {
2424
+ Active: ha,
2425
+ Inactive: ma
2426
+ },
2427
+ isActive: (e) => 5 <= e,
2428
+ getTooltip: (e) => e.CSAT5_RATING_SCORE_5
2429
+ }
2430
+ ], pa = () => ga, Yn = ({ label: e, children: t, position: n = "top", disabled: o }) => o ? t : /* @__PURE__ */ r.createElement(pt, null, t, /* @__PURE__ */ r.createElement(xa, { $position: n }, /* @__PURE__ */ r.createElement(Ea, { variant: "caption1" }, e), /* @__PURE__ */ r.createElement(fa, { $position: n }))), fa = ({ $position: e }) => /* @__PURE__ */ r.createElement(
2431
+ "svg",
2432
+ {
2433
+ style: { transform: e === "top" ? "rotate(0)" : "rotate(180deg)" },
2434
+ xmlns: "http://www.w3.org/2000/svg",
2435
+ width: "12",
2436
+ height: "6",
2437
+ viewBox: "0 0 12 6",
2438
+ fill: "none"
2439
+ },
2440
+ /* @__PURE__ */ r.createElement("path", { d: "M6 6L0 0h12L6 6Z", fill: h.themedColor.textHighEmphasis })
2441
+ ), ba = {
2442
+ top: I`flex-direction:column;top:0;transform:translate(-50%,-100%);`,
2443
+ bottom: I`flex-direction:column-reverse;bottom:0;transform:translate(-50%,100%);`
2444
+ }, pt = m.div`position:relative;`, xa = m.div`display:flex;align-items:center;position:absolute;left:50%;z-index:${fe.TOOLTIP};${({ $position: e }) => ba[e]}opacity:0;transition:opacity 0.2s ease-in-out;pointer-events:none;${pt}:hover &,${pt}:focus-within &{opacity:1;}`, Ea = m(w)`padding:6px 8px;background:${h.themedColor.textHighEmphasis};color:${h.themedColor.textHighEmphasisInverse};border-radius:4px;font-size:12px;white-space:nowrap;`, va = ({ submitted: e, value: t, onChange: n }) => {
2445
+ const { stringSet: o } = R(), i = pa(), a = typeof t == "number";
2446
+ return /* @__PURE__ */ r.createElement(Ca, null, /* @__PURE__ */ r.createElement(w, { variant: "caption2", color: h.themedColor.textMidEmphasis }, o.CSAT_RATING_TITLE), /* @__PURE__ */ r.createElement(ya, null, i.map((s) => /* @__PURE__ */ r.createElement(Yn, { disabled: e, key: s.value, label: s.getTooltip(o) }, /* @__PURE__ */ r.createElement(
2447
+ _a,
2448
+ {
2449
+ disabled: e,
2450
+ onClick: () => n(s.value),
2451
+ $inactive: a && !s.isActive(t)
2452
+ },
2453
+ a ? s.isActive(t) ? /* @__PURE__ */ r.createElement(s.Icon.Active, null) : /* @__PURE__ */ r.createElement(s.Icon.Inactive, null) : /* @__PURE__ */ r.createElement(s.Icon.Active, null)
2454
+ )))));
2455
+ }, Ca = m.div`display:flex;flex-direction:column;gap:8px;`, ya = m.div`display:flex;justify-content:space-between;width:100%;max-width:320px;`, _a = m.button`background-color:transparent;border:none;border-radius:4px;padding:0;display:flex;align-items:center;justify-content:center;box-sizing:border-box;&:enabled:hover{cursor:pointer;background-color:${h.color.background200};${D.dark`
2456
+ background-color: ${h.color.background500};
2457
+ `}
2458
+ }
2459
+
2460
+ ${({ $inactive: e, theme: t }) => e && t.selectedTheme === "dark" && Ta};
2461
+ `, Ta = I`[fill]{fill:white;fill-opacity:0.12;}[stroke]{stroke:white;stroke-opacity:0.12;}`, Sa = ({ submitted: e, value: t = "", onChange: n }) => {
2462
+ const { stringSet: o } = R();
2463
+ return e && !t ? null : /* @__PURE__ */ r.createElement(
2464
+ wa,
2465
+ {
2466
+ disabled: e,
2467
+ maxLength: 255,
2468
+ value: t,
2469
+ onChange: (i) => n(i.target.value),
2470
+ placeholder: o.CSAT_REASON_PLACEHOLDER
2471
+ }
2472
+ );
2473
+ }, wa = m.input`box-sizing:border-box;width:100%;border-radius:4px;padding:10px 16px;font-size:14px;font-weight:400;font-style:normal;border:unset;&:focus{outline:none;}color:${h.themedColor.textHighEmphasis};&::placeholder{color:${h.themedColor.textLowEmphasis};}background-color:${h.color.background50};${D.dark`
2474
+ background-color: ${h.themedColor.textDisabled};
2475
+ `}
2476
+
2477
+ &:disabled {
2478
+ cursor: not-allowed;
2479
+ color: ${h.themedColor.textLowEmphasis};
2480
+ background-color: ${h.color.background200};
2481
+ ${D.dark`
2482
+ color: ${h.color.ondark.textDisabled};
2483
+ background-color: ${h.themedColor.textDisabled};
2484
+ `}
2485
+ }
2486
+ `, ka = ({ submitted: e }) => {
2487
+ const { stringSet: t } = R();
2488
+ return e ? /* @__PURE__ */ r.createElement(w, { variant: "h2", color: h.themedColor.textHighEmphasis }, t.CSAT_TITLE_SUBMITTED) : /* @__PURE__ */ r.createElement(w, { variant: "h2", color: h.themedColor.textHighEmphasis }, t.CSAT_TITLE_UNSUBMITTED);
2489
+ };
2490
+ var ge = /* @__PURE__ */ ((e) => (e.AI_AGENT_CSAT_5 = "AI_AGENT_CSAT_5", e.AI_AGENT_CSAT_5_WITH_CRE = "AI_AGENT_CSAT_5_WITH_CRE", e))(ge || {});
2491
+ const Aa = (e) => yr((t, n) => ({ ...t, ...n }), e), Qt = ({
2492
+ type: e,
2493
+ renderSubmitButton: t,
2494
+ initialCsat: n,
2495
+ initialCsatReason: o,
2496
+ initialIsResolved: i
2497
+ }) => {
2498
+ const [a, s] = Aa({
2499
+ csatType: e,
2500
+ csat: n,
2501
+ csatReason: o,
2502
+ isResolved: i
2503
+ }), l = typeof n == "number" ? "submitted" : e === ge.AI_AGENT_CSAT_5 && typeof a.csat == "number" || e === ge.AI_AGENT_CSAT_5_WITH_CRE && typeof a.csat == "number" && typeof a.isResolved == "boolean" ? "submittable" : "unsubmittable", c = { state: l, submitted: l === "submitted" };
2504
+ return /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(Ia, null, /* @__PURE__ */ r.createElement(ka, { ...c }), e === ge.AI_AGENT_CSAT_5_WITH_CRE && /* @__PURE__ */ r.createElement(
2505
+ ta,
2506
+ {
2507
+ ...c,
2508
+ defaultValue: i,
2509
+ value: a.isResolved,
2510
+ onChange: (d) => s({ isResolved: d })
2511
+ }
2512
+ ), /* @__PURE__ */ r.createElement(va, { ...c, value: a.csat, onChange: (d) => s({ csat: d }) }), a.csat && /* @__PURE__ */ r.createElement(
2513
+ Sa,
2514
+ {
2515
+ ...c,
2516
+ value: a.csatReason,
2517
+ onChange: (d) => s({ csatReason: d })
2518
+ }
2519
+ )), l !== "submitted" && t({ state: l, params: a }));
2520
+ }, Ia = m.div`display:flex;flex-direction:column;gap:12px;`, $a = () => {
2521
+ const { stringSet: e } = R();
2522
+ return /* @__PURE__ */ r.createElement(w, { variant: "body2", color: h.themedColor.textMidEmphasis, style: { textAlign: "center" } }, e.CSAT_SUBMISSION_EXPIRED);
2523
+ }, Ma = (e) => {
2524
+ if (e.messageType !== "admin.csat")
2525
+ throw new Error("Invalid message type");
2526
+ const t = Br(), { stringSet: n } = R(), { extendedMessagePayload: o, csat: i, csatReason: a, csatExpireAt: s, isResolvedWhenDeterminedByUser: l, onSubmitCSAT: c } = e, { visibility: d, type: u } = (o == null ? void 0 : o.csat) ?? {};
2527
+ if (!d || !u || !ge[u]) return null;
2528
+ const p = u === ge.AI_AGENT_CSAT_5 || u === ge.AI_AGENT_CSAT_5_WITH_CRE ? Qt : () => null, g = (b) => {
2529
+ b.csat && !en(s) ? c({
2530
+ csatType: b.csatType,
2531
+ csat: b.csat,
2532
+ csatReason: b.csatReason,
2533
+ isResolved: b.isResolved
2534
+ }) : t();
2535
+ };
2536
+ return /* @__PURE__ */ r.createElement(Oa, null, !i && en(s) ? /* @__PURE__ */ r.createElement($a, null) : /* @__PURE__ */ r.createElement(
2537
+ p,
2538
+ {
2539
+ type: u,
2540
+ initialCsat: i,
2541
+ initialCsatReason: a,
2542
+ initialIsResolved: l,
2543
+ renderSubmitButton: ({ state: b, params: x }) => /* @__PURE__ */ r.createElement(La, { disabled: b !== "submittable", onClick: () => g(x) }, /* @__PURE__ */ r.createElement(w, { variant: "button" }, n.CSAT_SUBMIT_LABEL))
2544
+ }
2545
+ ));
2546
+ }, Oa = m.div`display:flex;flex-direction:column;background-color:${({ theme: e }) => e.colors.csat.background};border-radius:16px;gap:16px;padding:24px;`, La = m.button`all:unset;background-color:${({ theme: e }) => e.colors.base.primary};color:${({ theme: e }) => e.colors.base.primaryContrastContent};border-radius:6px;padding:10px 20px;display:flex;align-items:center;justify-content:center;cursor:pointer;&:hover{background-color:${h.color.primary.dark};}&:disabled{color:${h.color.ondark.textLowEmphasis};background-color:${h.themedColor.textDisabled};cursor:not-allowed;}`;
2547
+ function en(e) {
2548
+ return !!e && e < Date.now();
2549
+ }
2550
+ const $t = we({
2551
+ template: Ra,
2552
+ components: {
2553
+ AdminMessage: Xs,
2554
+ CSATMessage: Ma
2555
+ }
2556
+ });
2557
+ function Ra(e) {
2558
+ const { components: t } = $t.useContext(), n = At(() => e.messageType === "admin" ? /* @__PURE__ */ r.createElement(t.AdminMessage, { ...e }) : e.messageType === "admin.csat" ? /* @__PURE__ */ r.createElement(t.CSATMessage, { ...e }) : null);
2559
+ return /* @__PURE__ */ r.createElement(Na, { $marginBottom: _t(e.groupType) }, n);
2560
+ }
2561
+ const Na = m.div`padding-inline:${re}px;margin-bottom:${({ $marginBottom: e }) => e}px;`, tn = {
2562
+ file: "attach",
2563
+ snippet: "snippet",
2564
+ site: "website",
2565
+ sb_sprinklr: "sprinklr",
2566
+ sb_salesforce: "salesforce",
2567
+ sb_confluence: "confluence",
2568
+ sb_zendesk: "zendesk",
2569
+ sb_desk: "snippet"
2570
+ // TODO: request icon
2571
+ }, Da = ({
2572
+ actionbook: e,
2573
+ functionCalls: t,
2574
+ groundedness: n,
2575
+ agentMessageTemplates: o,
2576
+ onClickActionbook: i,
2577
+ onClickFunctionCall: a,
2578
+ onClickFunctionCallDetail: s,
2579
+ onClickGroundedness: l,
2580
+ onClickAgentMessageTemplate: c,
2581
+ bottomContent: d,
2582
+ renderCustomGroundednessIcon: u = (g) => g.default,
2583
+ style: p = {}
2584
+ }) => {
2585
+ const {
2586
+ // Note: This component is used with the dashboard, so cssVars should not be used.
2587
+ iconColor: g = "#000000",
2588
+ textColor: b = "#000000",
2589
+ highlightColor: x = On.DEFAULT_PRIMARY
2590
+ } = p;
2591
+ return /* @__PURE__ */ r.createElement(nn, null, e && /* @__PURE__ */ r.createElement(nn, null, /* @__PURE__ */ r.createElement(qe, null, /* @__PURE__ */ r.createElement(Ge, null, /* @__PURE__ */ r.createElement(O, { size: 16, type: "actionbook", color: g })), /* @__PURE__ */ r.createElement(
2592
+ We,
2593
+ {
2594
+ $clickable: !!i,
2595
+ $highlightColor: x,
2596
+ variant: "body2",
2597
+ color: b,
2598
+ onClick: () => i == null ? void 0 : i(e)
2599
+ },
2600
+ e.name
2601
+ ))), t == null ? void 0 : t.map((E) => /* @__PURE__ */ r.createElement(lt, { key: E.key }, /* @__PURE__ */ r.createElement(Ge, null, /* @__PURE__ */ r.createElement(O, { size: 16, type: "function", color: g })), /* @__PURE__ */ r.createElement(qe, null, /* @__PURE__ */ r.createElement(
2602
+ We,
2603
+ {
2604
+ $clickable: !!i,
2605
+ $highlightColor: x,
2606
+ variant: "body2",
2607
+ color: b,
2608
+ onClick: () => a == null ? void 0 : a(E)
2609
+ },
2610
+ E.name
2611
+ ), /* @__PURE__ */ r.createElement(Ba, { role: "button", onClick: () => s == null ? void 0 : s(E) }, /* @__PURE__ */ r.createElement(w, { variant: "body2", color: x }, "View details"), /* @__PURE__ */ r.createElement(O, { type: "chevron-right", size: 16, color: x }))))), n == null ? void 0 : n.map((E) => /* @__PURE__ */ r.createElement(lt, { key: E.id }, /* @__PURE__ */ r.createElement(Ge, null, u({
2612
+ default: /* @__PURE__ */ r.createElement(O, { size: 16, type: tn[E.source_type] ?? tn.snippet, color: g }),
2613
+ sourceType: E.source_type
2614
+ })), /* @__PURE__ */ r.createElement(
2615
+ We,
2616
+ {
2617
+ $clickable: !!l,
2618
+ $highlightColor: x,
2619
+ variant: "body2",
2620
+ color: b,
2621
+ onClick: () => l == null ? void 0 : l(E)
2622
+ },
2623
+ E.preview_title
2624
+ ))), o == null ? void 0 : o.map((E) => /* @__PURE__ */ r.createElement(lt, { key: E.key }, /* @__PURE__ */ r.createElement(Ge, null, /* @__PURE__ */ r.createElement(O, { size: 16, type: "template", color: g })), /* @__PURE__ */ r.createElement(
2625
+ We,
2626
+ {
2627
+ $clickable: !!c,
2628
+ $highlightColor: x,
2629
+ variant: "body2",
2630
+ color: b,
2631
+ onClick: () => c == null ? void 0 : c(E)
2632
+ },
2633
+ E.name
2634
+ ))), d);
2635
+ }, Pa = m(w)`font-weight:400;`, We = m(Pa)`${({ $clickable: e, $highlightColor: t }) => e && I`
2636
+ cursor: pointer;
2637
+ text-decoration: underline;
2638
+ &:hover {
2639
+ color: ${t};
2640
+ }
2641
+ `}
2642
+ `, Ge = m.div`display:flex;align-items:center;justify-content:center;flex-shrink:0;`, qe = m.div`display:flex;gap:8px;align-items:center;`, Ba = m(qe)`cursor:pointer;gap:4px;`, lt = m(qe)`flex-direction:row;align-items:center;`, nn = m.div`display:flex;gap:4px;flex-direction:column;align-items:flex-start;`, qn = Se(null);
2643
+ function Fa({ testerType: e, children: t }) {
2644
+ return /* @__PURE__ */ r.createElement(
2645
+ qn.Provider,
2646
+ {
2647
+ value: { testerType: e, isActionbookTester: e === "actionbook" }
2648
+ },
2649
+ e && /* @__PURE__ */ r.createElement(Ua, null),
2650
+ t
2651
+ );
2652
+ }
2653
+ const nt = () => {
2654
+ const e = te(qn);
2655
+ if (!e) throw new Error("_UNSAFE_INTERNAL_DashboardTesterProvider not found");
2656
+ return e;
2657
+ }, Ua = () => {
2658
+ const { isActionbookTester: e } = nt();
2659
+ return /* @__PURE__ */ r.createElement(Te.Template, { template: e ? Ha : void 0 }, /* @__PURE__ */ r.createElement(Te.MessageLogs, { component: za }));
2660
+ }, Ha = (e) => /* @__PURE__ */ r.createElement(jn, { ...e, testerMode: !0, maxBodyWidth: zn }), za = ({ extendedMessagePayload: e = {} }) => {
2661
+ const { handlers: t } = P(), { manual: n, groundedness: o, function_calls: i, agent_message_templates: a, is_thinking: s } = e;
2662
+ return s || !n && !(o != null && o.length) && !(i != null && i.length) && !(a != null && a.length) ? /* @__PURE__ */ r.createElement(r.Fragment, null) : /* @__PURE__ */ r.createElement(Va, null, /* @__PURE__ */ r.createElement(Wa, { width: 4 }), /* @__PURE__ */ r.createElement(
2663
+ Da,
2664
+ {
2665
+ actionbook: n,
2666
+ functionCalls: i,
2667
+ groundedness: o,
2668
+ agentMessageTemplates: a,
2669
+ onClickFunctionCallDetail: t == null ? void 0 : t.onFunctionCallDetailClick,
2670
+ style: {
2671
+ iconColor: h.themedColor.textHighEmphasis,
2672
+ textColor: h.themedColor.textHighEmphasis,
2673
+ barColor: h.themedColor.textDisabled
2674
+ },
2675
+ bottomContent: /* @__PURE__ */ r.createElement(Ga, { variant: "caption2", color: h.themedColor.textLowEmphasis }, "Only visible in the tester")
2676
+ }
2677
+ ));
2678
+ }, Va = m.div`display:flex;gap:16px;margin:16px ${re}px 0;align-self:stretch;`, Wa = m.div`width:${({ width: e }) => e}px;background-color:${h.themedColor.textDisabled};border-radius:100px;flex-shrink:0;`, Ga = m(w)`margin-top:5px;`, Mt = {
2679
+ isStreaming(e) {
2680
+ const t = Gt(e.data);
2681
+ return typeof t == "object" ? !!t.stream : !1;
2682
+ },
2683
+ isWelcomeMessage(e, t) {
2684
+ var n;
2685
+ if (((n = e.extendedMessagePayload) == null ? void 0 : n.bot_message_type) === "welcome")
2686
+ return !0;
2687
+ if ((e.isUserMessage() || e.isFileMessage()) && e.sender.userId === t) {
2688
+ const o = Gt(e.data);
2689
+ return !(o != null && o.respond_mesg_id) && !(o != null && o.stream);
2690
+ }
2691
+ return !1;
2692
+ }
2693
+ };
2694
+ function ja(e) {
2695
+ return "sendingStatus" in e ? e.sendingStatus === "succeeded" ? String(e.messageId) : e.reqId : String(e.messageId);
2696
+ }
2697
+ const Za = (e, t, n, o = !0) => {
2698
+ if (!o || !e.isUserMessage() && !e.isFileMessage())
2699
+ return "single";
2700
+ const i = () => {
2701
+ if (!t || !t.isUserMessage() && !t.isFileMessage()) return !1;
2702
+ const c = t.sender.userId === e.sender.userId, d = Ft(t.createdAt, e.createdAt);
2703
+ return c && d;
2704
+ }, a = () => {
2705
+ if (!n || !n.isUserMessage() && !n.isFileMessage()) return !1;
2706
+ const c = n.sender.userId === e.sender.userId, d = Ft(n.createdAt, e.createdAt);
2707
+ return c && d;
2708
+ }, s = i(), l = a();
2709
+ return s && l ? "middle" : s ? "bottom" : l ? "top" : "single";
2710
+ };
2711
+ function Ka(e, t) {
2712
+ return e.filter((n) => Mt.isWelcomeMessage(n, t));
2713
+ }
2714
+ function Jn(e, t) {
2715
+ return Ya(e) === t;
2716
+ }
2717
+ function Ya(e) {
2718
+ var t;
2719
+ if (e)
2720
+ return e.isUserMessage() || e.isFileMessage() || e.isMultipleFilesMessage() ? e.sender.userId : ((t = e == null ? void 0 : e.sender) == null ? void 0 : t.userId) ?? void 0;
2721
+ }
2722
+ function qa(e) {
2723
+ return e.isAdminMessage() ? e.message === "The channel's custom_type was updated." : !1;
2724
+ }
2725
+ const rn = (e) => !!e && "sender" in e, Xn = (e) => e.startsWith("image/"), Qn = (e) => e.startsWith("video/"), on = (e) => Xn(e) || Qn(e), je = {
2726
+ isAdmin: (e) => e.isAdminMessage(),
2727
+ isCSAT: (e) => {
2728
+ var t;
2729
+ return e.isAdminMessage() && !!((t = e.extendedMessagePayload) != null && t.csat);
2730
+ },
2731
+ isIncoming: (e, t) => rn(e) && e.sender.userId !== t,
2732
+ isOutgoing: (e, t) => rn(e) && (e.sender.userId === t || e.sendingStatus === zr.PENDING)
2733
+ }, er = ({ rootElementId: e, visible: t, onClose: n, children: o }) => {
2734
+ if (!t) return null;
2735
+ const { rootElement: i } = P(), a = pe(i), s = pe(i, !0);
2736
+ return Kr(
2737
+ /* @__PURE__ */ r.createElement(Ja, { onClick: n }, /* @__PURE__ */ r.createElement(Xa, { onClick: (l) => l.stopPropagation() }, o)),
2738
+ a.getElementById(e) ?? a.getElementById(ne.MODAL_ROOT) ?? s.body
2739
+ );
2740
+ }, Ja = m.div`position:fixed;top:0;left:0;width:100%;height:100%;background:${h.color.overlay.dark};display:flex;justify-content:center;align-items:center;z-index:${fe.MODAL};`, Xa = m.div`border-radius:4px;overflow:hidden;box-shadow:0 16px 24px 2px rgba(13,13,13,0.12),0 6px 30px 5px rgba(13,13,13,0.08),0 6px 10px -5px rgba(13,13,13,0.04);z-index:${fe.MODAL};`, Qa = m.div`flex-shrink:0;width:${({ $size: e }) => K(e)};height:${({ $size: e }) => K(e)};background-color:${({ theme: e }) => e.colors.base.primary};box-sizing:border-box;padding:6px;border-radius:50%;display:flex;justify-content:center;align-items:center;}`, el = m(wt)`path{fill:${({ theme: e }) => e.colors.base.primaryContrastContent};}`;
2741
+ function tr({ size: e }) {
2742
+ const { aiAgentInfo: t } = z();
2743
+ return t.profileUrl ? /* @__PURE__ */ r.createElement(kt, { size: e, src: t.profileUrl }) : /* @__PURE__ */ r.createElement(Qa, { $size: e }, /* @__PURE__ */ r.createElement(el, null));
2744
+ }
2745
+ const tl = m.div`width:100%;height:100%;position:fixed;top:0;left:0;outline:none;`, nl = m.div`height:64px;min-height:64px;box-sizing:border-box;display:flex;justify-content:space-between;border-bottom:1px solid ${h.themedColor.textDisabled};background-color:${h.themedColor.bg_50_600};@media screen and (max-width:768px){position:relative;}`, rl = m.div`box-sizing:border-box;display:flex;flex-direction:row;align-items:center;height:64px;padding:16px 20px;width:calc(100% - 128px);`, ol = m.div`margin-inline-end:8px;`, il = m.div`max-width:500px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:inline-block;@media screen and (max-width:768px){position:absolute;inset-inline-start:64px;top:10px;display:block;max-width:calc(100vw - 240px);}`, sl = m.div`display:inline-block;margin-inline-start:8px;padding-top:5px;@media screen and (max-width:768px){position:absolute;inset-inline-start:56px;top:24px;}`, al = m.div`display:flex;width:160px;justify-content:flex-end;`, ll = m.div`inset-inline-end:0;display:flex;flex-direction:row;`, ft = m.div`width:64px;padding:21px;box-sizing:border-box;cursor:${(e) => e.disabled ? "not-allowed" : "pointer"};`, cl = m(ft)`border-inline-start:1px solid ${h.themedColor.textDisabled};`, dl = m.div`width:100%;height:100%;display:flex;align-items:center;justify-content:center;`, ul = m.video`max-width:100%;max-height:100%;user-select:none;-webkit-user-drag:none;`, ml = m.img`max-width:90%;max-height:90%;user-select:none;-webkit-user-drag:none;`, hl = m.div`max-width:100%;max-height:100%;display:flex;justify-content:center;align-items:center;`, gl = ({ message: e, onClose: t, onDownloadClick: n }) => {
2746
+ const { sender: o, type: i, url: a, name: s = "", threadInfo: l } = e, { profileUrl: c, nickname: d, userId: u } = o, { userSession: p, aiAgentInfo: g } = z();
2747
+ return /* @__PURE__ */ r.createElement(
2748
+ fl,
2749
+ {
2750
+ profileUrl: c,
2751
+ nickname: d,
2752
+ type: i,
2753
+ url: a,
2754
+ name: s,
2755
+ onClose: t,
2756
+ isBotMessage: u === g.userId,
2757
+ isByMe: p.userId === u,
2758
+ disableDelete: l != null && l.replyCount ? l.replyCount > 0 : !1,
2759
+ onDownloadClick: n
2760
+ }
2761
+ );
2762
+ }, pl = ({ profileUrl: e, isBotMessage: t }) => !e && t ? /* @__PURE__ */ r.createElement(tr, { size: 32 }) : /* @__PURE__ */ r.createElement(kt, { size: 32, src: e }), fl = ({
2763
+ profileUrl: e,
2764
+ isBotMessage: t,
2765
+ nickname: n,
2766
+ name: o,
2767
+ type: i,
2768
+ url: a,
2769
+ isByMe: s,
2770
+ onClose: l,
2771
+ onDelete: c,
2772
+ disableDelete: d,
2773
+ onDownloadClick: u
2774
+ }) => {
2775
+ const { stringSet: p } = R();
2776
+ return /* @__PURE__ */ r.createElement(er, { onClose: l, visible: !0, rootElementId: ne.MODAL_ROOT }, /* @__PURE__ */ r.createElement(tl, null, /* @__PURE__ */ r.createElement(nl, null, /* @__PURE__ */ r.createElement(rl, null, /* @__PURE__ */ r.createElement(ol, null, /* @__PURE__ */ r.createElement(pl, { profileUrl: e, isBotMessage: t })), /* @__PURE__ */ r.createElement(il, null, /* @__PURE__ */ r.createElement(w, { variant: "h2", color: h.themedColor.textHighEmphasis }, o)), /* @__PURE__ */ r.createElement(sl, null, /* @__PURE__ */ r.createElement(w, { variant: "body1", color: h.color.ondark.textMidEmphasis }, n))), /* @__PURE__ */ r.createElement(al, null, on(i) && /* @__PURE__ */ r.createElement(ll, null, /* @__PURE__ */ r.createElement(ft, { as: "a", href: a, target: "_blank", rel: Ct, onClick: u }, /* @__PURE__ */ r.createElement(O, { type: "download", color: h.themedColor.textHighEmphasis, size: 24 })), c && s && /* @__PURE__ */ r.createElement(
2777
+ ft,
2778
+ {
2779
+ disabled: d,
2780
+ onClick: () => {
2781
+ d || c();
2782
+ }
2783
+ },
2784
+ /* @__PURE__ */ r.createElement(
2785
+ O,
2786
+ {
2787
+ type: "delete",
2788
+ color: d ? "gray" : h.themedColor.textHighEmphasis,
2789
+ size: 24
2790
+ }
2791
+ )
2792
+ )), /* @__PURE__ */ r.createElement(cl, { onClick: l }, /* @__PURE__ */ r.createElement(O, { type: "close", color: h.themedColor.textHighEmphasis, size: 24 })))), /* @__PURE__ */ r.createElement(dl, { onClick: (g) => g.currentTarget === g.target && l() }, Qn(i) && /* @__PURE__ */ r.createElement(ul, { controls: !0 }, /* @__PURE__ */ r.createElement("source", { src: a, type: i })), Xn(i) && /* @__PURE__ */ r.createElement(ml, { src: a, alt: o }), !on(i) && /* @__PURE__ */ r.createElement(hl, null, /* @__PURE__ */ r.createElement(w, { variant: "h1", color: h.themedColor.textHighEmphasis }, p.FILE_VIEWER__UNSUPPORT)))));
2793
+ }, nr = ({
2794
+ className: e,
2795
+ locale: t,
2796
+ date: n = Date.now(),
2797
+ formatString: o = "MMMM dd, yyyy",
2798
+ style: i
2799
+ }) => /* @__PURE__ */ r.createElement(bl, { style: i, className: e }, /* @__PURE__ */ r.createElement(w, { variant: "caption4", color: h.themedColor.textMidEmphasis }, En(n, o, { locale: t }))), bl = m.div`display:flex;justify-content:center;align-items:center;`, xl = Le(function(t, n) {
2800
+ const {
2801
+ messages: o,
2802
+ renderMessage: i,
2803
+ messageTopArea: a,
2804
+ messageBottomArea: s,
2805
+ overlayArea: l,
2806
+ onLoadPrev: c,
2807
+ onLoadNext: d,
2808
+ loadThreshold: u = 0.05,
2809
+ onScrollPosition: p = Oe,
2810
+ depsForResetScrollPositionToBottom: g,
2811
+ scrollPositionRef: b,
2812
+ scrollDistanceFromBottomRef: x,
2813
+ stackDirection: E = "top"
2814
+ } = t, f = n && "current" in n ? n : { current: null }, v = F(!1), y = F(void 0), $ = F(0), T = F(0), Y = F(0), L = b ?? T, be = x ?? Y;
2815
+ ae(() => {
2816
+ f.current && (f.current.scrollTop = f.current.scrollHeight);
2817
+ }, g), ae(() => {
2818
+ f.current && (y.current === "top" && (f.current.scrollTop = f.current.scrollHeight - L.current), y.current === "bottom" && (f.current.scrollTop = $.current), y.current = void 0);
2819
+ }, [f.current, o.length]);
2820
+ const xe = async () => {
2821
+ if (!f.current) return;
2822
+ const C = f.current;
2823
+ if (p(El(C)), L.current = C.scrollHeight - C.scrollTop, be.current = L.current - C.clientHeight, $.current = C.scrollTop, v.current) return;
2824
+ const B = C.clientHeight * Math.min(Math.max(0, u), 1);
2825
+ C.scrollTop <= B ? (v.current = !0, y.current = "top", await c(), v.current = !1) : C.scrollHeight - C.scrollTop - C.clientHeight <= B ? (v.current = !0, y.current = "bottom", await d(), v.current = !1) : y.current = void 0;
2826
+ };
2827
+ return /* @__PURE__ */ r.createElement(vl, { id: "infinite-list-container" }, /* @__PURE__ */ r.createElement(Cl, { id: "infinite-list-inner", ref: f, onScroll: xe }, E === "bottom" && /* @__PURE__ */ r.createElement("div", { style: { flexGrow: 1 } }), a, o.map((C, B) => i({ message: C, index: B })), s), /* @__PURE__ */ r.createElement(yl, { id: "infinite-list-overlay-container" }, /* @__PURE__ */ r.createElement(_l, { id: "infinite-list-overlay" }, l)));
2828
+ });
2829
+ function El(e) {
2830
+ return e.scrollTop <= 10 ? "top" : e.scrollHeight - (e.scrollTop + e.clientHeight) <= 10 ? "bottom" : "middle";
2831
+ }
2832
+ const vl = m.div`display:flex;position:relative;flex:1;overflow:hidden;`, Cl = m.div`display:flex;flex:1;flex-direction:column;overflow-y:auto;scrollbar-color:${h.themedColor.textLowEmphasis}transparent;&::-webkit-scrollbar-thumb:hover{background-color:transparent;}`, yl = m.div`position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:none;`, _l = m.div`pointer-events:auto;`, Tl = ({ className: e, onClick: t }) => /* @__PURE__ */ r.createElement(Sl, { className: e, onClick: t, tabIndex: 0 }, /* @__PURE__ */ r.createElement(O, { size: 24, type: "chevron-down", color: h.color.primary.main })), Sl = m.button`all:unset;cursor:pointer;display:flex;align-items:center;justify-content:center;width:40px;height:40px;border-radius:24px;box-shadow:0 2px 8px 0 rgba(0,0,0,0.08),0 4px 6px 0 rgba(0,0,0,0.12);${D.light`
2833
+ background-color: ${h.color.background50};
2834
+ &:hover {
2835
+ background-color: ${h.color.background100};
2836
+ }
2837
+ &:active {
2838
+ background-color: ${h.color.background200};
2839
+ }
2840
+ `}
2841
+ ${D.dark`
2842
+ background-color: ${h.color.background400};
2843
+ &:hover {
2844
+ background-color: ${h.color.background500};
2845
+ }
2846
+ &:active {
2847
+ background-color: ${h.color.background700};
2848
+ }
2849
+ `}
2850
+
2851
+ &:focus {
2852
+ outline: none;
2853
+ }
2854
+ `, rr = () => {
2855
+ const { chatSDK: e } = P(), { channelSource: t } = q(), [n, o] = _([]);
2856
+ return vn(e, {
2857
+ onTypingStatusUpdated(i) {
2858
+ var a;
2859
+ if (i.url === ((a = t.channel) == null ? void 0 : a.url)) {
2860
+ const s = i.getTypingUsers();
2861
+ o(s);
2862
+ }
2863
+ }
2864
+ }), n;
2865
+ }, wl = () => {
2866
+ const { agentPreviewConfigs: e = {}, aiAgentId: t } = P(), { aiAgentInfo: n } = z(), { stringSet: o, dateLocale: i } = R(), { messageSource: a } = q(), { Template: s } = Te.useContext(), l = e.welcomeMessages ?? [], c = a.messages, d = Ka(c, t), u = c[d.length + 1], p = d[0] ?? u;
2867
+ return {
2868
+ /**
2869
+ * Returns a list of messages filtered according to business requirements.
2870
+ */
2871
+ filteredMessages: c.filter((g) => qa(g) ? !1 : l.length > 0 ? !Mt.isWelcomeMessage(g, t) : !0),
2872
+ /**
2873
+ * Determines whether to display the DateSeparator in the data list by comparing it with the welcome messages from Bot Studio.
2874
+ */
2875
+ shouldShowOriginalDate: (g) => g > 0 || l.length === 0 ? !0 : u && !Lr(u.createdAt, (p == null ? void 0 : p.createdAt) ?? 0),
2876
+ /**
2877
+ * Renders the list of welcome messages from Bot Studio.
2878
+ */
2879
+ renderAgentPreviewWelcomeMessages: () => l.length === 0 ? null : /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(
2880
+ nr,
2881
+ {
2882
+ style: { margin: "16px 0" },
2883
+ date: p == null ? void 0 : p.createdAt,
2884
+ locale: i,
2885
+ formatString: o.DATE_FORMAT__MESSAGE_LIST__DATE_SEPARATOR
2886
+ }
2887
+ ), l.map((g, b) => {
2888
+ const x = b === l.length - 1, E = d.length !== c.length, f = l.length === 1 ? "single" : b === 0 ? "top" : x || E ? "bottom" : "middle";
2889
+ return /* @__PURE__ */ r.createElement(
2890
+ s,
2891
+ {
2892
+ messageType: "user",
2893
+ message: g.message,
2894
+ sender: n,
2895
+ groupType: f,
2896
+ createdAt: (p == null ? void 0 : p.createdAt) ?? Date.now(),
2897
+ extendedMessagePayload: { suggested_replies: g.suggestedReplies },
2898
+ suggestedRepliesDirection: e.suggestedRepliesDirection,
2899
+ suggestedRepliesVisible: x && !E,
2900
+ isBotMessage: !0,
2901
+ onClickSuggestedReply: async ({ reply: v }) => {
2902
+ a.sendUserMessage({ message: v });
2903
+ }
2904
+ }
2905
+ );
2906
+ }))
2907
+ };
2908
+ }, kl = (e) => m(e).withConfig({ shouldForwardProp: Yr });
2909
+ function Al(e) {
2910
+ var o;
2911
+ const t = "remove_powered_by", n = (o = e == null ? void 0 : e.appInfo) == null ? void 0 : o.applicationAttributes;
2912
+ return Array.isArray(n) && n.includes(t);
2913
+ }
2914
+ const Il = ({ style: e }) => {
2915
+ const { stringSet: t } = R(), { chatSDK: n } = P(), { isActionbookTester: o } = nt();
2916
+ return Al(n) || o ? null : /* @__PURE__ */ r.createElement($l, { variant: "caption2", style: e }, t.POWERED_BY + " ", /* @__PURE__ */ r.createElement(
2917
+ Ml,
2918
+ {
2919
+ variant: "caption2",
2920
+ as: "a",
2921
+ href: "https://sendbird.com?utm_medium=product&utm_source=aiagent&utm_campaign=fy26-glbl-ai-agent-poweredby",
2922
+ "aria-label": "Learn more about Sendbird",
2923
+ rel: Ct,
2924
+ target: "_blank"
2925
+ },
2926
+ "Sendbird"
2927
+ ));
2928
+ }, $l = m(w)`color:${h.themedColor.textLowEmphasis};text-align:center;`, Ml = kl(w)`
2929
+ color: ${h.themedColor.textLowEmphasis};
2930
+ cursor: pointer;
2931
+ text-decoration: none;
2932
+ `, Ol = () => {
2933
+ var c;
2934
+ const { stringSet: e } = R(), { activeChannel: t } = z(), { channelSource: n, goToActiveConversation: o, scrollSource: i } = q(), a = Fn(n.channel), l = t && ((c = n.channel) == null ? void 0 : c.url) === (t == null ? void 0 : t.url) && a;
2935
+ return ae(() => {
2936
+ l && i.scrollPubSub.publish({ type: "scrollToBottom", data: { animated: !0 } });
2937
+ }, [l]), l ? /* @__PURE__ */ r.createElement(Ll, null, /* @__PURE__ */ r.createElement(
2938
+ Rl,
2939
+ {
2940
+ variant: "button",
2941
+ role: "button",
2942
+ color: h.themedColor.textHighEmphasis,
2943
+ onClick: () => o()
2944
+ },
2945
+ e.START_NEW_CONVERSATION
2946
+ )) : null;
2947
+ }, Ll = m.div`display:flex;justify-content:center;margin:16px 0;`, Rl = m(w)`border-radius:6px;box-sizing:border-box;padding:10px 20px;border:1px solid ${h.themedColor.textDisabled};cursor:pointer;user-select:none;`, Nl = !0, Dl = () => {
2948
+ const { Template: e } = It.useContext(), { Template: t } = Te.useContext(), { Template: n } = $t.useContext(), [o, i] = _(null), { userSession: a, aiAgentInfo: s } = z(), { agentPreviewConfigs: l, chatSDK: c, state: d } = P(), { stringSet: u, dateLocale: p } = R(), { conversation: g, channelSource: b, messageSource: x, scrollSource: E } = q(), { isActionbookTester: f } = nt(), { filteredMessages: v, shouldShowOriginalDate: y, renderAgentPreviewWelcomeMessages: $ } = wl(), { storage: T } = In(), Y = rr(), L = At(() => {
2949
+ const C = Y[0];
2950
+ if (!C) return null;
2951
+ const B = C.userId === s.userId;
2952
+ return { user: B ? s : C, isBot: B };
2953
+ });
2954
+ N(() => {
2955
+ L && setTimeout(() => E.scrollPubSub.publish({ type: "scrollToBottom", data: { animated: !0 } }), 25);
2956
+ }, [!!L, E]);
2957
+ const be = (C, B = !1) => {
2958
+ var Ee;
2959
+ return B ? s : ((Ee = b.channel) == null ? void 0 : Ee.members.find((J) => J.userId === C.sender.userId)) ?? C.sender;
2960
+ }, xe = () => {
2961
+ if (!x.initialized)
2962
+ return /* @__PURE__ */ r.createElement(_e, { type: "loading" });
2963
+ if (x.messages.length === 0) {
2964
+ const C = $();
2965
+ return C ? /* @__PURE__ */ r.createElement("div", { style: { width: "100%" } }, C) : /* @__PURE__ */ r.createElement(_e, { type: "noMessages", label: u.PLACE_HOLDER__NO_MESSAGES });
2966
+ }
2967
+ return /* @__PURE__ */ r.createElement(
2968
+ xl,
2969
+ {
2970
+ ref: E.scrollRef,
2971
+ scrollPositionRef: E.scrollPositionRef,
2972
+ scrollDistanceFromBottomRef: E.scrollDistanceFromBottomRef,
2973
+ onScrollPosition: (C) => E.setIsScrollBottomReached(C === "bottom"),
2974
+ stackDirection: l == null ? void 0 : l.messageStackDirection,
2975
+ messages: v,
2976
+ onLoadPrev: x.loadPrevious,
2977
+ onLoadNext: x.loadNext,
2978
+ depsForResetScrollPositionToBottom: [x.initialized, x.messages.length !== 0],
2979
+ messageTopArea: /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(Il, { style: { marginTop: 16 } }), $()),
2980
+ messageBottomArea: /* @__PURE__ */ r.createElement(r.Fragment, null, L && /* @__PURE__ */ r.createElement(
2981
+ t,
2982
+ {
2983
+ isTyping: !0,
2984
+ isBotMessage: L.isBot,
2985
+ sender: L.user,
2986
+ messageType: "user",
2987
+ groupType: "single",
2988
+ message: ""
2989
+ }
2990
+ ), /* @__PURE__ */ r.createElement(Ol, null)),
2991
+ overlayArea: /* @__PURE__ */ r.createElement(r.Fragment, null, !E.isScrollBottomReached && /* @__PURE__ */ r.createElement(Bl, { onClick: () => E.scrollPubSub.publish({ type: "scrollToBottom" }) })),
2992
+ renderMessage: ({ message: C, index: B }) => {
2993
+ const Ee = ja(C), J = v[B - 1], Ae = v[B + 1], rt = v[v.length - 1], ot = C === rt, k = Za(C, J, Ae, Nl), A = !Vr((J == null ? void 0 : J.createdAt) ?? 0, C.createdAt) && y(B) && !f, M = () => {
2994
+ C.isFileMessage() && i(C);
2995
+ }, H = () => {
2996
+ C.isFileMessage() && Bn(C.url);
2997
+ }, ve = A ? /* @__PURE__ */ r.createElement(
2998
+ nr,
2999
+ {
3000
+ style: { margin: "16px 0" },
3001
+ date: C.createdAt,
3002
+ locale: p,
3003
+ formatString: u.DATE_FORMAT__MESSAGE_LIST__DATE_SEPARATOR
3004
+ }
3005
+ ) : null, oe = {
3006
+ maxBodyWidth: d.expanded ? zn : void 0,
3007
+ extendedMessagePayload: C.extendedMessagePayload,
3008
+ createdAt: C.createdAt,
3009
+ groupType: k,
3010
+ onClickMedia: M,
3011
+ onClickFile: H
3012
+ }, Z = (() => {
3013
+ var ie, Q;
3014
+ if (je.isAdmin(C))
3015
+ return je.isCSAT(C) ? g ? /* @__PURE__ */ r.createElement(
3016
+ n,
3017
+ {
3018
+ ...oe,
3019
+ ...g,
3020
+ isResolvedWhenDeterminedByUser: Fl(g),
3021
+ messageType: "admin.csat",
3022
+ onSubmitCSAT: ({ csat: G, csatType: ue, csatReason: V, isResolved: se }) => {
3023
+ var me;
3024
+ G && ((me = b.channel) == null || me.submitCSAT({ csat: G, csatType: ue, csatReason: V, isResolved: se }));
3025
+ }
3026
+ }
3027
+ ) : null : /* @__PURE__ */ r.createElement(n, { ...oe, messageType: "admin", message: C.message });
3028
+ if (je.isOutgoing(C, a.userId)) {
3029
+ const G = {
3030
+ ...oe,
3031
+ message: C.message,
3032
+ sender: be(C),
3033
+ sendingStatus: C.sendingStatus
3034
+ };
3035
+ if (C.isUserMessage())
3036
+ return /* @__PURE__ */ r.createElement(e, { messageType: "user", ...G });
3037
+ if (C.isFileMessage()) {
3038
+ const [ue, V] = ((ie = C.metaArrays.find((se) => se.key === Pn)) == null ? void 0 : ie.value) ?? [];
3039
+ return /* @__PURE__ */ r.createElement(
3040
+ e,
3041
+ {
3042
+ messageType: "file",
3043
+ file: C,
3044
+ metadata: {
3045
+ aspectRatio: ue && V ? `${ue}/${V}` : "1/1",
3046
+ localFile: (Q = C.messageParams) == null ? void 0 : Q.file
3047
+ },
3048
+ ...G
3049
+ }
3050
+ );
3051
+ }
3052
+ }
3053
+ if (je.isIncoming(C, a.userId)) {
3054
+ const G = C.sender.userId === s.userId, ue = {
3055
+ ...oe,
3056
+ sender: be(C, G),
3057
+ message: C.message,
3058
+ suggestedRepliesVisible: ot,
3059
+ suggestedRepliesDirection: l == null ? void 0 : l.suggestedRepliesDirection,
3060
+ isBotMessage: G,
3061
+ onClickSuggestedReply: async ({ reply: V }) => {
3062
+ x.sendUserMessage({ message: V });
3063
+ },
3064
+ onRequestMessageTemplate: async (V) => {
3065
+ const { template: se } = await c.aiAgent.getMessageTemplate(V);
3066
+ return T.setTemplate(V, se), se;
3067
+ },
3068
+ onGetCachedMessageTemplate: (V) => T.getTemplate(V),
3069
+ onHandleTemplateInternalAction: (V) => {
3070
+ if (V.type === "internal" && V.internalData) {
3071
+ const { method: se, payload: me } = V.internalData;
3072
+ se === "message.send" && (me != null && me.message) && x.sendUserMessage({ message: me.message });
3073
+ }
3074
+ }
3075
+ };
3076
+ if (C.isUserMessage())
3077
+ return /* @__PURE__ */ r.createElement(t, { messageType: "user", ...ue });
3078
+ if (C.isFileMessage())
3079
+ return /* @__PURE__ */ r.createElement(t, { messageType: "file", file: C, ...ue });
3080
+ }
3081
+ })();
3082
+ return /* @__PURE__ */ r.createElement("div", { key: Ee, id: `${X}-message-item` }, ve, Z);
3083
+ }
3084
+ }
3085
+ );
3086
+ };
3087
+ return /* @__PURE__ */ r.createElement(Pl, { id: `${X}-message-list` }, xe(), o && /* @__PURE__ */ r.createElement(gl, { onClose: () => i(null), message: o }));
3088
+ }, Pl = m.div`overflow-y:hidden;display:flex;flex:1;position:relative;`, Bl = m(Tl)`position:absolute;bottom:20px;inset-inline-end:20px;`;
3089
+ function Fl(e) {
3090
+ var t;
3091
+ if (((t = e == null ? void 0 : e.resolution) == null ? void 0 : t.determinedBy) === "user")
3092
+ return e.resolution.isResolved;
3093
+ }
3094
+ const Ul = () => {
3095
+ const { stringSet: e } = R(), { connectionError: t } = z(), { channelSource: n } = q(), o = t || n.error;
3096
+ if (o) {
3097
+ const i = t ? void 0 : { label: e.RETRY, onClick: () => n.refetch() };
3098
+ return /* @__PURE__ */ r.createElement(_e, { type: "error", label: o.message, action: i });
3099
+ }
3100
+ return n.channel ? /* @__PURE__ */ r.createElement(Dl, null) : /* @__PURE__ */ r.createElement(_e, { type: "loading" });
3101
+ }, or = () => {
3102
+ const { stringSet: e } = R(), { activeChannel: t } = z(), [n] = _(() => (t == null ? void 0 : t.status) === W.OPEN);
3103
+ return n ? e.RETURN_TO_CONVERSATION : e.START_NEW_CONVERSATION;
3104
+ }, Hl = () => {
3105
+ const { stringSet: e } = R(), { goToActiveConversation: t } = q(), n = or();
3106
+ return /* @__PURE__ */ r.createElement(zl, null, /* @__PURE__ */ r.createElement(w, { variant: "body1", color: h.themedColor.textMidEmphasis }, e.CONVERSATION_CLOSED_FOOTER_LABEL), /* @__PURE__ */ r.createElement(Vl, { onClick: t }, /* @__PURE__ */ r.createElement(w, { variant: "button", color: h.themedColor.textHighEmphasis }, n)));
3107
+ }, zl = m.div`display:flex;flex-direction:column;align-items:center;justify-content:center;padding:32px 0;gap:14px;${D.light`
3108
+ background-color: ${h.color.background100};
3109
+ `}
3110
+ ${D.dark`
3111
+ background-color: ${h.color.background500};
3112
+ `}
3113
+ `, Vl = m.button`all:unset;padding:10px 20px;border-radius:6px;border:1px solid ${h.themedColor.textDisabled};cursor:pointer;${D.light`
3114
+ background-color: ${h.color.background50};
3115
+ `}
3116
+ ${D.dark`
3117
+ background-color: ${h.color.background700};
3118
+ `}
3119
+ `, ir = Se(void 0), Wl = ({ children: e }) => {
3120
+ const { stringSet: t } = R(), { aiAgentInfo: n } = z(), { channelSource: o } = q(), [i, a] = _([]), [s, l] = _({
3121
+ visible: !1,
3122
+ title: "",
3123
+ buttonText: t.BUTTON__OK
3124
+ }), c = (n == null ? void 0 : n.replyToFile) || Hn(o.channel), d = (g) => {
3125
+ if (!c) return;
3126
+ const b = g.filter((x) => Rn.includes(x.type));
3127
+ if (b.length !== 0) {
3128
+ if (b.some((x) => x.size > di)) {
3129
+ l((x) => ({
3130
+ ...x,
3131
+ visible: !0,
3132
+ title: t.FILE_UPLOAD_NOTIFICATION__SIZE_LIMIT.replace("%d", "25")
3133
+ }));
3134
+ return;
3135
+ }
3136
+ if (b.length > 1 || b.length > 0 && i.length > 0) {
3137
+ l((x) => ({
3138
+ ...x,
3139
+ visible: !0,
3140
+ title: t.FILE_UPLOAD_NOTIFICATION__COUNT_LIMIT
3141
+ }));
3142
+ return;
3143
+ }
3144
+ a((x) => [
3145
+ ...x,
3146
+ ...b.map((E) => ({
3147
+ file: E,
3148
+ preview: { url: URL.createObjectURL(E), type: E.type, name: E.name }
3149
+ }))
3150
+ ]);
3151
+ }
3152
+ }, u = (g) => {
3153
+ a((b) => {
3154
+ var E;
3155
+ const x = (E = b[g]) == null ? void 0 : E.preview;
3156
+ return x && URL.revokeObjectURL(x.url), b.filter((f, v) => v !== g);
3157
+ });
3158
+ }, p = () => {
3159
+ a((g) => (g.forEach((b) => URL.revokeObjectURL(b.preview.url)), []));
3160
+ };
3161
+ return /* @__PURE__ */ r.createElement(
3162
+ ir.Provider,
3163
+ {
3164
+ value: {
3165
+ files: i,
3166
+ addFiles: d,
3167
+ removeFile: u,
3168
+ clearFiles: p,
3169
+ isFileUploadEnabled: c
3170
+ }
3171
+ },
3172
+ e,
3173
+ /* @__PURE__ */ r.createElement(Gl, { ...s, onClose: () => l((g) => ({ ...g, visible: !1, title: "" })) })
3174
+ );
3175
+ }, Ot = () => {
3176
+ const e = te(ir);
3177
+ if (!e)
3178
+ throw new Error("useFileUpload must be used within FileUploadProvider");
3179
+ return e;
3180
+ }, Gl = ({
3181
+ title: e,
3182
+ buttonText: t,
3183
+ visible: n,
3184
+ onClose: o
3185
+ }) => /* @__PURE__ */ r.createElement(er, { rootElementId: ne.WINDOW, visible: n, onClose: o }, /* @__PURE__ */ r.createElement(jl, null, /* @__PURE__ */ r.createElement(Kl, null, /* @__PURE__ */ r.createElement(w, { variant: "h1", color: h.themedColor.textHighEmphasis }, e)), /* @__PURE__ */ r.createElement(Zl, null, /* @__PURE__ */ r.createElement(Yl, { onClick: o }, /* @__PURE__ */ r.createElement(w, { variant: "button", color: h.themedColor.textHighEmphasisInverse }, t))))), jl = m.div`width:100%;height:auto;padding-block:18px 24px;padding-inline:24px;margin:0 auto;border-radius:4px;box-sizing:border-box;background-color:${({ theme: e }) => e.colors.base.modalContentBackground};`, Zl = m.div`display:flex;flex-direction:row;justify-content:flex-end;`, Kl = m.div`margin-bottom:16px;`, Yl = m.button`display:flex;justify-content:center;align-items:center;border-radius:4px;cursor:pointer;background-color:${h.themedColor.error};border:1px solid ${h.themedColor.error};padding:10px 16px;&:hover{background-color:${h.color.error.dark};border-color:${h.color.error.dark};}&:active{background-color:${h.color.error.extraDark};}`;
3186
+ function ql({ blurred: e, elementRef: t, document: n = window.document }) {
3187
+ const o = F(!1);
3188
+ e && t.current && n.activeElement === t.current && (o.current = !0), ae(() => {
3189
+ var i;
3190
+ !e && o.current && ((i = t.current) == null || i.focus(), o.current = !1);
3191
+ }, [e]);
3192
+ }
3193
+ const Jl = m.div`&::-webkit-scrollbar{display:none;}overflow-x:auto;display:flex;flex-direction:row;gap:10px;padding:8px 16px;background-color:transparent;`, Xl = m.div`display:flex;flex-shrink:0;position:relative;margin-block-start:8px;border-radius:12px;height:64px;img{border-radius:12px;object-fit:cover;width:64px;-webkit-user-drag:none;}`, Ql = m.div`display:flex;align-items:center;justify-content:center;position:absolute;inset-inline-end:-8px;inset-block-start:-8px;cursor:pointer;border-radius:50%;${D.light`
3194
+ background-color: ${h.color.background50};
3195
+ `}
3196
+ ${D.dark`
3197
+ background-color: ${h.color.background500};
3198
+ `}
3199
+ path {
3200
+ fill: ${h.themedColor.textMidEmphasis};
3201
+ }
3202
+
3203
+ &:hover {
3204
+ path {
3205
+ fill: ${h.themedColor.textHighEmphasis};
3206
+ }
3207
+ }
3208
+
3209
+ circle {
3210
+ stroke: ${h.themedColor.bg_50_600};
3211
+ }
3212
+ `, ec = () => {
3213
+ const e = De(), [t, n] = _(), { files: o, removeFile: i, isFileUploadEnabled: a } = Ot();
3214
+ return !a || o.length === 0 ? null : /* @__PURE__ */ r.createElement(Jl, null, o.map(({ preview: { type: s, name: l, url: c } }, d) => /* @__PURE__ */ r.createElement(Xl, { key: c, onMouseOver: () => n(d), onMouseLeave: () => n(void 0) }, (e || t === d) && /* @__PURE__ */ r.createElement(Ql, { title: "Remove file", onClick: () => i(d) }, /* @__PURE__ */ r.createElement(O, { type: "close-filled", color: h.themedColor.textMidEmphasis })), s.startsWith("image/") ? /* @__PURE__ */ r.createElement("img", { alt: "file-image", src: c }) : /* @__PURE__ */ r.createElement(St, { name: l, type: Tt(l, s) }))));
3215
+ }, tc = ({ channel: e, messages: t }) => {
3216
+ const { stringSet: n } = R(), { aiAgentInfo: o } = z(), i = nc(), a = rc({
3217
+ lastMessage: t[t.length - 1],
3218
+ aiAgentUserId: o.userId
3219
+ });
3220
+ return !e || !i || Fn(e) ? [!0, n.MESSAGE_INPUT__PLACE_HOLDER__DISABLED] : a ? [!0, n.MESSAGE_INPUT__PLACE_HOLDER__WAIT_AI_AGENT_RESPONSE] : [!1, n.MESSAGE_INPUT__PLACE_HOLDER];
3221
+ }, nc = () => {
3222
+ const e = fn(), { chatSDK: t } = P(), [n, o] = _(!0);
3223
+ return N(() => {
3224
+ const i = new Je({
3225
+ onDisconnected: () => o(!1),
3226
+ onConnected: () => o(!0),
3227
+ onReconnectSucceeded: () => o(!0)
3228
+ });
3229
+ return t.addConnectionHandler(e, i), () => {
3230
+ t.removeConnectionHandler(e);
3231
+ };
3232
+ }, [t]), n;
3233
+ }, rc = ({
3234
+ lastMessage: e,
3235
+ aiAgentUserId: t
3236
+ }) => {
3237
+ const [n, o] = _(!1), i = rr();
3238
+ return N(() => {
3239
+ if (!e) return;
3240
+ const a = i.some((l) => l.userId === t), s = Jn(e, t) && Mt.isStreaming(e);
3241
+ o(!!(s || a));
3242
+ }, [i, e, t]), n;
3243
+ }, sr = {
3244
+ textArea: I`min-height:40px;height:40px;font-size:16px;line-height:24px;`,
3245
+ attachIcon: I`margin-bottom:4px;`
3246
+ }, ar = m.button`all:unset;cursor:pointer;display:flex;align-items:center;justify-content:center;width:32px;height:32px;`, oc = m(ar)`flex-shrink:0;margin-inline-end:12px;margin-bottom:2px;&:disabled{cursor:not-allowed;}&:not(:disabled){&:hover{path{fill:${h.themedColor.textHighEmphasis};}}&:active{border-radius:4px;background-color:${h.themedColor.bg_200_400};}}${vt && sr.attachIcon};`, ic = m.input`display:none;`, sn = m.div`width:100%;position:relative;background-color:${h.themedColor.bg_100_500};border-radius:20px;`, an = m.div`display:flex;flex-direction:row;align-items:flex-end;position:relative;`, ln = m.textarea`all:unset;display:block;flex:1;min-width:0;padding-top:8px;padding-bottom:8px;padding-inline-start:16px;padding-inline-end:12px;box-sizing:border-box;font-size:14px;line-height:20px;color:${h.themedColor.textHighEmphasis};resize:none;width:100%;height:${Ln}px;overflow-wrap:break-word;white-space:pre-wrap;overflow-x:hidden;${vt && sr.textArea};&::placeholder{color:${h.themedColor.textLowEmphasis};}&:disabled{cursor:not-allowed;&::placeholder{color:${h.themedColor.textDisabled};}}`, cn = m.div`padding:12px 16px;position:relative;display:flex;align-items:center;`, dn = ({ disabled: e }) => {
3247
+ const t = F(null), { addFiles: n, clearFiles: o, files: i, isFileUploadEnabled: a } = Ot();
3248
+ return !a || i.length > 0 ? null : /* @__PURE__ */ r.createElement(
3249
+ oc,
3250
+ {
3251
+ disabled: e,
3252
+ onClick: () => {
3253
+ var s;
3254
+ o(), (s = t.current) == null || s.click();
3255
+ }
3256
+ },
3257
+ /* @__PURE__ */ r.createElement(
3258
+ O,
3259
+ {
3260
+ type: "attach",
3261
+ color: e ? h.themedColor.textDisabled : h.themedColor.textMidEmphasis,
3262
+ size: 16
3263
+ }
3264
+ ),
3265
+ /* @__PURE__ */ r.createElement(
3266
+ ic,
3267
+ {
3268
+ type: "file",
3269
+ ref: t,
3270
+ onChange: (s) => {
3271
+ const l = s.currentTarget.files;
3272
+ l && n(Array.from(l)), s.target.value = "";
3273
+ },
3274
+ accept: Rn.join(",")
3275
+ }
3276
+ )
3277
+ );
3278
+ }, sc = () => {
3279
+ const e = F(null), [t, n] = _(""), { rootElement: o } = P(), { channelSource: i, messageSource: a } = q(), [s, l] = tc({
3280
+ channel: i.channel,
3281
+ messages: a.messages
3282
+ }), { files: c, addFiles: d, clearFiles: u } = Ot();
3283
+ Ii({ onDropFiles: d }), ql({ blurred: s, elementRef: e, document: pe(o) });
3284
+ const p = t.trim().length > 0, g = c.length > 0, b = !s && (p || g), x = () => {
3285
+ e.current && (e.current.value = "", e.current.style.height = ""), u(), n("");
3286
+ }, E = async () => {
3287
+ const $ = t.trim(), T = { message: $ };
3288
+ if (!(!$ && !c.length)) {
3289
+ if (c.length > 0) {
3290
+ const Y = c[0].file, L = { ...T, file: Y };
3291
+ a.sendFileMessage(L), x();
3292
+ return;
3293
+ }
3294
+ a.sendUserMessage(T), x();
3295
+ }
3296
+ }, f = ($) => {
3297
+ const T = Array.from($.clipboardData.files);
3298
+ T.length > 0 && ($.preventDefault(), d(T));
3299
+ }, v = ($) => {
3300
+ $.key !== "Enter" || $.nativeEvent.isComposing || $.shiftKey || ($.preventDefault(), E());
3301
+ }, y = ($) => {
3302
+ if (e.current) {
3303
+ e.current.style.height = "";
3304
+ const T = Math.min(ci, e.current.scrollHeight);
3305
+ Ln < T && (e.current.style.height = `${T}px`);
3306
+ }
3307
+ n($.target.value);
3308
+ };
3309
+ return s ? /* @__PURE__ */ r.createElement(cn, null, /* @__PURE__ */ r.createElement(sn, null, /* @__PURE__ */ r.createElement(an, null, /* @__PURE__ */ r.createElement(ln, { disabled: !0, placeholder: l }), /* @__PURE__ */ r.createElement(dn, { disabled: !0 })))) : /* @__PURE__ */ r.createElement(cn, null, /* @__PURE__ */ r.createElement(sn, null, /* @__PURE__ */ r.createElement(ec, null), /* @__PURE__ */ r.createElement(an, null, /* @__PURE__ */ r.createElement(
3310
+ ln,
3311
+ {
3312
+ ref: e,
3313
+ role: "textbox",
3314
+ "aria-label": "Text Input",
3315
+ placeholder: l,
3316
+ maxLength: 5e3,
3317
+ onKeyDown: v,
3318
+ onChange: y,
3319
+ onPaste: f
3320
+ }
3321
+ ), /* @__PURE__ */ r.createElement(dn, null))), b && /* @__PURE__ */ r.createElement(ar, { onClick: () => E() }, /* @__PURE__ */ r.createElement(O, { type: "send", color: h.color.primary.main, size: 20 })));
3322
+ }, ac = m.div`padding:8px 16px;text-align:center;word-break:break-word;white-space:pre-wrap;line-height:1.43;letter-spacing:-0.2px;font-size:14px;font-weight:400;color:${h.themedColor.textLowEmphasis};&& a{font-weight:700;text-decoration:none;${D.light`
3323
+ color: ${h.color.information.light};
3324
+ `};
3325
+ ${D.dark`
3326
+ color: ${h.color.information.main};
3327
+ `};
3328
+ }
3329
+ `, lc = S(() => import("./CD9aZhSJ.js").then((e) => ({ default: e.MarkdownText }))), cc = () => {
3330
+ const { aiAgentInfo: e } = z(), { messageSource: t } = q(), { userSession: n } = z();
3331
+ return !e.specialNoticeEnabled || !e.specialNotice || !(t.initialized && !t.messages.some((i) => Jn(i, n.userId))) ? null : /* @__PURE__ */ r.createElement(ac, null, /* @__PURE__ */ r.createElement(lc, null, e.specialNotice));
3332
+ }, dc = () => /* @__PURE__ */ r.createElement(uc, null, /* @__PURE__ */ r.createElement(cc, null), /* @__PURE__ */ r.createElement(Wl, null, /* @__PURE__ */ r.createElement(sc, null))), uc = m.div`z-index:0;border:none;width:100%;`, mc = () => {
3333
+ var a, s, l;
3334
+ const { activeChannel: e } = z(), { channelSource: t } = q(), n = ((s = (a = t.channel) == null ? void 0 : a.conversation) == null ? void 0 : s.status) === W.CLOSED;
3335
+ return !(((l = t.channel) == null ? void 0 : l.url) === (e == null ? void 0 : e.url)) && n ? /* @__PURE__ */ r.createElement(Hl, null) : /* @__PURE__ */ r.createElement(dc, null);
3336
+ }, hc = () => {
3337
+ var y;
3338
+ const { state: e, logger: t, enableCloseConversationButton: n, enableExpandButton: o, dispatcher: i } = P(), { stringSet: a } = R(), { aiAgentInfo: s, activeChannel: l } = z(), { channelSource: c, onNavigateToConversationList: d } = q(), u = c.channel, g = De() ? 24 : 16, b = () => {
3339
+ e.setOpened(!1);
3340
+ }, x = async () => {
3341
+ try {
3342
+ const $ = await (u == null ? void 0 : u.markConversationAsHandoff());
3343
+ t.info("conversation.handleAgentHandoff: success", $);
3344
+ } catch ($) {
3345
+ t.error("conversation.handleAgentHandoff: error", $);
3346
+ }
3347
+ }, E = async () => {
3348
+ u && await i.send(io.CloseConversation({ channelUrl: u.url }));
3349
+ }, f = l && (u == null ? void 0 : u.url) === l.url, v = s.showHandoffButton && !!((y = u == null ? void 0 : u.conversation) != null && y.handoff) && f;
3350
+ return /* @__PURE__ */ r.createElement(xc, null, /* @__PURE__ */ r.createElement(Ec, null, d && /* @__PURE__ */ r.createElement(Be, { onClick: () => d() }, /* @__PURE__ */ r.createElement(O, { type: "menu", size: 24, color: h.themedColor.textHighEmphasis })), f && /* @__PURE__ */ r.createElement(tr, { size: 34 }), /* @__PURE__ */ r.createElement(Cc, { variant: "h2", color: h.themedColor.textHighEmphasis }, s.nickname || (u == null ? void 0 : u.name))), /* @__PURE__ */ r.createElement(vc, null, v && /* @__PURE__ */ r.createElement(
3351
+ bc,
3352
+ {
3353
+ tooltipLabel: a.HEADER_BUTTON__AGENT_HANDOFF,
3354
+ disabled: !Ai(u),
3355
+ size: g,
3356
+ onClick: x
3357
+ }
3358
+ ), n && /* @__PURE__ */ r.createElement(
3359
+ fc,
3360
+ {
3361
+ disabled: !Un(u),
3362
+ size: g,
3363
+ onClick: E
3364
+ }
3365
+ ), o && /* @__PURE__ */ r.createElement(gc, { size: g }), /* @__PURE__ */ r.createElement(pc, { size: g, onClick: b })));
3366
+ }, gc = ({ size: e, disabled: t }) => {
3367
+ const { state: n } = P();
3368
+ return /* @__PURE__ */ r.createElement(Be, { "aria-label": "expand", onClick: () => n.setExpanded(!n.expanded), disabled: t }, /* @__PURE__ */ r.createElement(O, { type: n.expanded ? "collapse" : "expand", size: e, color: h.themedColor.textHighEmphasis }));
3369
+ }, pc = ({ size: e, disabled: t, onClick: n }) => /* @__PURE__ */ r.createElement(Be, { "aria-label": "close messenger", onClick: n, disabled: t }, /* @__PURE__ */ r.createElement(O, { type: "close", size: e, color: h.themedColor.textHighEmphasis })), fc = ({ size: e, disabled: t, onClick: n }) => /* @__PURE__ */ r.createElement(Be, { "aria-label": "close conversation", onClick: n, disabled: t }, /* @__PURE__ */ r.createElement(
3370
+ O,
3371
+ {
3372
+ type: "refresh",
3373
+ size: e,
3374
+ color: t ? h.themedColor.textDisabled : h.themedColor.textHighEmphasis
3375
+ }
3376
+ )), bc = ({ size: e, onClick: t, disabled: n, tooltipLabel: o }) => /* @__PURE__ */ r.createElement(Yn, { label: o, position: "bottom", disabled: n }, /* @__PURE__ */ r.createElement(Be, { "aria-label": "agent", onClick: t, disabled: n }, /* @__PURE__ */ r.createElement(
3377
+ O,
3378
+ {
3379
+ type: "agent",
3380
+ size: e,
3381
+ color: n ? h.themedColor.textDisabled : h.themedColor.textHighEmphasis
3382
+ }
3383
+ ))), xc = m.div`height:56px;box-sizing:border-box;display:flex;align-items:center;padding:11px 12px;border-bottom:1px solid ${h.themedColor.textDisabled};background-color:${({ theme: e }) => e.colors.base.headerBackground};`, Ec = m.div`display:flex;flex:1;flex-direction:row;align-items:center;gap:6px;overflow:hidden;`, vc = m.div`display:flex;gap:10px;align-items:center;justify-content:center;`, Cc = m(w)`text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding:2px 0;`, Be = m.button`all:unset;padding:4px;cursor:pointer;display:flex;align-items:center;justify-content:center;&:disabled{cursor:not-allowed;}`, yc = () => {
3384
+ const { isActionbookTester: e } = nt();
3385
+ return e ? null : /* @__PURE__ */ r.createElement(hc, null);
3386
+ }, un = ({
3387
+ children: e,
3388
+ onNavigateToConversationList: t,
3389
+ closedChannelUrl: n,
3390
+ onClearClosedChannelUrl: o
3391
+ }) => {
3392
+ const { Template: i } = Lt.useContext();
3393
+ return /* @__PURE__ */ r.createElement(
3394
+ ki,
3395
+ {
3396
+ onNavigateToConversationList: t,
3397
+ closedChannelUrl: n,
3398
+ onClearClosedChannelUrl: o
3399
+ },
3400
+ /* @__PURE__ */ r.createElement(gt, null, /* @__PURE__ */ r.createElement(gt.Consumer, null, (a) => /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(Tc, { ...a }, /* @__PURE__ */ r.createElement(i, null)), e)))
3401
+ );
3402
+ }, Lt = we({
3403
+ template: _c,
3404
+ components: {
3405
+ Header: yc,
3406
+ Body: Ul,
3407
+ Footer: mc
3408
+ }
3409
+ });
3410
+ function _c() {
3411
+ const { components: e } = Lt.useContext();
3412
+ return /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(e.Header, null), /* @__PURE__ */ r.createElement(e.Body, null), /* @__PURE__ */ r.createElement(e.Footer, null));
3413
+ }
3414
+ const Tc = m.div`height:100%;width:100%;display:flex;flex-direction:column;flex:1;background-color:${({ theme: e }) => e.colors.base.background};`, {
3415
+ Provider: Sc,
3416
+ useContext: lr
3417
+ } = j("ConversationList");
3418
+ function wc({
3419
+ conversationListFilter: e,
3420
+ onOpenConversationView: t = Oe,
3421
+ children: n
3422
+ }) {
3423
+ return /* @__PURE__ */ r.createElement(po, { conversationListFilter: e }, (o) => /* @__PURE__ */ r.createElement(Sc, { value: { ...o, onOpenConversationView: t } }, n));
3424
+ }
3425
+ const cr = we({
3426
+ template: kc,
3427
+ // Note: 리스트 변경되면 디자인 변경 가능성이 있어서 일단 컴포넌트는 비워둠
3428
+ components: {}
3429
+ });
3430
+ function kc({
3431
+ title: e = "",
3432
+ lastMessageTimestamp: t = Date.now(),
3433
+ onClick: n
3434
+ }) {
3435
+ const { stringSet: o, format: i } = R();
3436
+ return /* @__PURE__ */ r.createElement(Ac, { role: "button", onClick: () => n == null ? void 0 : n() }, /* @__PURE__ */ r.createElement($c, null, /* @__PURE__ */ r.createElement(Mc, null, /* @__PURE__ */ r.createElement(w, { variant: "subtitle1", color: h.themedColor.textHighEmphasis }, i(t, o.DATE_FORMAT__CONVERSATION_LIST__LIST_ITEM_TITLE)), /* @__PURE__ */ r.createElement(w, { variant: "caption2", color: h.themedColor.textLowEmphasis }, i(t, o.DATE_FORMAT__CONVERSATION_LIST__LIST_ITEM_TITLE_CAPTION))), /* @__PURE__ */ r.createElement(w, { variant: "body3", color: h.themedColor.textMidEmphasis }, e || o.CONVERSATION_LIST__TOPICS_FALLBACK)), /* @__PURE__ */ r.createElement(O, { type: "chevron-right", size: 16, color: h.themedColor.textHighEmphasis }), /* @__PURE__ */ r.createElement(Ic, null));
3437
+ }
3438
+ const Ac = m.div`display:flex;flex-direction:row;align-items:center;position:relative;width:100%;padding:14px 16px;box-sizing:border-box;gap:4px;cursor:pointer;`, Ic = m.div`position:absolute;bottom:0;height:1px;width:calc(100% - 32px);background-color:${h.themedColor.textDisabled};`, $c = m.div`gap:4px;display:flex;flex-direction:column;flex:1;`, Mc = m.div`display:flex;justify-content:flex-start;align-items:center;gap:6px;`, Oc = ({ items: e, renderItem: t, onEndReached: n }) => {
3439
+ const o = (i) => {
3440
+ const a = i.target;
3441
+ a.scrollHeight - a.scrollTop === a.clientHeight && (n == null || n());
3442
+ };
3443
+ return /* @__PURE__ */ r.createElement(Lc, { onScroll: (i) => o(i) }, e.map((i, a) => t(i, a)));
3444
+ }, Lc = m.div`width:100%;height:100%;display:flex;flex-direction:column;flex:1;overflow:auto;`, Rc = () => {
3445
+ const { stringSet: e } = R(), { listSource: t, onOpenConversationView: n } = lr(), { Template: o } = cr.useContext();
3446
+ return t.initialized ? t.channels.length === 0 ? /* @__PURE__ */ r.createElement(_e, { type: "noChannels", label: e.CONVERSATION_LIST__NO_CONVERSATIONS }) : /* @__PURE__ */ r.createElement(
3447
+ Oc,
3448
+ {
3449
+ items: t.channels,
3450
+ renderItem: (i) => {
3451
+ var a, s, l;
3452
+ return /* @__PURE__ */ r.createElement(
3453
+ o,
3454
+ {
3455
+ key: i.url,
3456
+ channelUrl: i.url,
3457
+ title: (s = (a = i.conversation) == null ? void 0 : a.topics) == null ? void 0 : s.join(", "),
3458
+ lastMessageTimestamp: (l = i.lastMessage) == null ? void 0 : l.createdAt,
3459
+ onClick: () => n(i.url, W.CLOSED),
3460
+ channel: i
3461
+ }
3462
+ );
3463
+ },
3464
+ onEndReached: () => {
3465
+ t.loadMore();
3466
+ }
3467
+ }
3468
+ ) : /* @__PURE__ */ r.createElement(_e, { type: "loading" });
3469
+ }, Nc = () => {
3470
+ const { refreshActiveChannel: e } = z(), { onOpenConversationView: t } = lr(), n = or();
3471
+ return /* @__PURE__ */ r.createElement(
3472
+ Dc,
3473
+ {
3474
+ role: "button",
3475
+ onClick: async () => {
3476
+ const o = await e();
3477
+ t(o, W.OPEN);
3478
+ }
3479
+ },
3480
+ /* @__PURE__ */ r.createElement(Pc, { variant: "h1" }, n)
3481
+ );
3482
+ }, Dc = m.div`background-color:${({ theme: e }) => e.colors.base.primary};display:flex;align-items:center;justify-content:center;padding:16px;cursor:pointer;`, Pc = m(w)`color:${({ theme: e }) => e.colors.base.primaryContrastContent};overflow:hidden;text-overflow:ellipsis;white-space:nowrap;`, Bc = () => {
3483
+ const { stringSet: e } = R();
3484
+ return /* @__PURE__ */ r.createElement(Fc, null, /* @__PURE__ */ r.createElement(Uc, { variant: "h2", color: h.themedColor.textHighEmphasis }, e.CONVERSATION_LIST__HEADER_TITLE), /* @__PURE__ */ r.createElement(Hc, null));
3485
+ }, Fc = m.div`display:flex;flex-direction:column;align-items:flex-start;justify-content:center;width:100%;flex-shrink:0;height:56px;position:relative;background-color:${({ theme: e }) => e.colors.base.headerBackground};`, Uc = m(w)`padding:0 12px;width:100%;box-sizing:border-box;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;`, Hc = m.div`position:absolute;bottom:0;width:100%;height:1px;background-color:${h.themedColor.textDisabled};`, zc = ({ conversationListFilter: e, children: t, onOpenConversationView: n }) => {
3486
+ const { Template: o } = Rt.useContext();
3487
+ return /* @__PURE__ */ r.createElement(
3488
+ wc,
3489
+ {
3490
+ conversationListFilter: e,
3491
+ onOpenConversationView: n
3492
+ },
3493
+ /* @__PURE__ */ r.createElement(Wc, null, /* @__PURE__ */ r.createElement(o, null)),
3494
+ t
3495
+ );
3496
+ }, Rt = we({
3497
+ template: Vc,
3498
+ components: {
3499
+ Header: Bc,
3500
+ Body: Rc,
3501
+ Footer: Nc
3502
+ }
3503
+ });
3504
+ function Vc() {
3505
+ const { components: e } = Rt.useContext();
3506
+ return /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(e.Header, null), /* @__PURE__ */ r.createElement(e.Body, null), /* @__PURE__ */ r.createElement(e.Footer, null));
3507
+ }
3508
+ const Wc = m.div`height:100%;width:100%;display:flex;flex-direction:column;flex:1;background-color:${({ theme: e }) => e.colors.base.background};`, Gc = I`:where(#${ne.ENTRY}) :not(code *){font-family:'Roboto',sans-serif;box-sizing:border-box;}`, jc = [Gc, ei, ti], Zc = (e, ...t) => Mr(e, ...jc, ...t), Kc = Zc``, Yc = qr(
3509
+ Lt,
3510
+ Te,
3511
+ It,
3512
+ $t,
3513
+ Rt,
3514
+ cr
3515
+ );
3516
+ function qc({
3517
+ appearance: e,
3518
+ rootElement: t,
3519
+ logger: n,
3520
+ language: o,
3521
+ stringSet: i,
3522
+ children: a,
3523
+ messageTemplate: s,
3524
+ theme: l
3525
+ }) {
3526
+ return ai(Wo, t), /* @__PURE__ */ r.createElement(Or, { target: t }, /* @__PURE__ */ r.createElement(oi, { rootElement: t, logger: n, appearance: e, theme: l }, /* @__PURE__ */ r.createElement(Po, { internalVariables: s == null ? void 0 : s.__internalVariables }, /* @__PURE__ */ r.createElement(Qo, { stringSet: i, logger: n, language: o }, /* @__PURE__ */ r.createElement(Yc, null, a, /* @__PURE__ */ r.createElement(Kc, null))))));
3527
+ }
3528
+ const mn = {
3529
+ key_payment_plan_container: {
3530
+ color_variables: {},
3531
+ created_at: 1232,
3532
+ updated_at: 4563,
3533
+ key: "key_payment_plan_container",
3534
+ ui_template: {
3535
+ body: {
3536
+ items: [
3537
+ {
3538
+ carouselStyle: { maxChildWidth: 265, spacing: 10 },
3539
+ items: "{@templates}",
3540
+ type: "carouselView",
3541
+ viewStyle: { padding: { top: 0, bottom: 0, left: 50, right: 16 } }
3542
+ }
3543
+ ]
3544
+ },
3545
+ version: 2
3546
+ }
3547
+ },
3548
+ key_payment_plan: {
3549
+ color_variables: {},
3550
+ created_at: 123,
3551
+ updated_at: 456,
3552
+ key: "key_payment_plan",
3553
+ ui_template: {
3554
+ version: 1,
3555
+ body: {
3556
+ items: [
3557
+ {
3558
+ viewStyle: { radius: 16, backgroundColor: "#FFFFFF", borderWidth: "1", borderColor: "#E0E0E0" },
3559
+ width: { type: "fixed", value: "264" },
3560
+ height: { type: "fixed", value: "275" },
3561
+ type: "box",
3562
+ layout: "column",
3563
+ items: [
3564
+ {
3565
+ viewStyle: {
3566
+ padding: { left: 16, right: 16, top: 16, bottom: 16 },
3567
+ backgroundImageUrl: "https://storage-66w.pages.dev/carousel-bg.png"
3568
+ },
3569
+ action: { type: "web", data: "{action_url}" },
3570
+ type: "box",
3571
+ layout: "column",
3572
+ items: [
3573
+ {
3574
+ type: "text",
3575
+ text: "{header_plan}",
3576
+ textStyle: { size: 14, weight: "bold", color: "#FFFFFF" }
3577
+ },
3578
+ { type: "text", text: "{header_desc}", textStyle: { size: 12, color: "#FFFFFF" } }
3579
+ ]
3580
+ },
3581
+ {
3582
+ viewStyle: { padding: { left: 16, right: 16, top: 16, bottom: 16 } },
3583
+ action: { type: "web", data: "{action_url}" },
3584
+ type: "box",
3585
+ layout: "column",
3586
+ items: [
3587
+ { type: "text", text: "{price}", textStyle: { size: 20, weight: "bold" } },
3588
+ {
3589
+ viewStyle: { padding: { left: 0, right: 0, top: 16, bottom: 16 } },
3590
+ type: "box",
3591
+ layout: "column",
3592
+ items: [
3593
+ {
3594
+ viewStyle: { backgroundColor: "#E0E0E0" },
3595
+ width: { type: "flex", value: 0 },
3596
+ height: { type: "fixed", value: "1" },
3597
+ type: "box",
3598
+ layout: "column"
3599
+ }
3600
+ ]
3601
+ },
3602
+ {
3603
+ viewStyle: { margin: { bottom: 8, top: 0, left: 0, right: 0 } },
3604
+ type: "text",
3605
+ text: "{description}",
3606
+ textStyle: { size: 14, weight: "normal", color: "#7F7F7F" }
3607
+ }
3608
+ ]
3609
+ }
3610
+ ]
3611
+ }
3612
+ ]
3613
+ }
3614
+ }
3615
+ },
3616
+ key_content_preview: {
3617
+ color_variables: {},
3618
+ created_at: 1232,
3619
+ updated_at: 4563,
3620
+ key: "key_content_preview",
3621
+ ui_template: {
3622
+ version: 1,
3623
+ body: {
3624
+ items: [
3625
+ {
3626
+ viewStyle: {
3627
+ radius: 16,
3628
+ borderWidth: 1,
3629
+ borderColor: "#1F000000",
3630
+ backgroundColor: "#FFFFFF"
3631
+ },
3632
+ width: {
3633
+ type: "fixed",
3634
+ value: 264
3635
+ },
3636
+ action: { type: "web", data: "{action_url}" },
3637
+ type: "box",
3638
+ layout: "column",
3639
+ items: [
3640
+ {
3641
+ action: { type: "web", data: "{action_url}" },
3642
+ width: {
3643
+ type: "flex",
3644
+ value: 0
3645
+ },
3646
+ height: {
3647
+ type: "fixed",
3648
+ value: 200
3649
+ },
3650
+ type: "image",
3651
+ imageUrl: "{image}",
3652
+ imageStyle: {
3653
+ contentMode: "aspectFill"
3654
+ }
3655
+ },
3656
+ {
3657
+ action: { type: "web", data: "{action_url}" },
3658
+ viewStyle: {
3659
+ padding: {
3660
+ left: 16,
3661
+ right: 16,
3662
+ top: 16,
3663
+ bottom: 16
3664
+ }
3665
+ },
3666
+ type: "box",
3667
+ layout: "column",
3668
+ items: [
3669
+ {
3670
+ viewStyle: {
3671
+ margin: {
3672
+ bottom: 4,
3673
+ top: 0,
3674
+ left: 0,
3675
+ right: 0
3676
+ }
3677
+ },
3678
+ height: {
3679
+ type: "fixed",
3680
+ value: 16
3681
+ },
3682
+ type: "text",
3683
+ text: "{title}",
3684
+ maxTextLines: 1,
3685
+ textStyle: {
3686
+ size: 14,
3687
+ weight: "bold",
3688
+ color: "#000000"
3689
+ }
3690
+ },
3691
+ {
3692
+ height: {
3693
+ type: "fixed",
3694
+ value: 16
3695
+ },
3696
+ type: "text",
3697
+ text: "{release_date}",
3698
+ maxTextLines: 1,
3699
+ textStyle: {
3700
+ size: 14,
3701
+ weight: "normal",
3702
+ color: "#80000000"
3703
+ }
3704
+ }
3705
+ ]
3706
+ }
3707
+ ]
3708
+ }
3709
+ ]
3710
+ }
3711
+ }
3712
+ }
3713
+ }, dr = Le(function({
3714
+ rootElement: t = document.body,
3715
+ logLevel: n = bn.WARN,
3716
+ language: o = navigator.language,
3717
+ userSessionInfo: i,
3718
+ children: a,
3719
+ ...s
3720
+ }, l) {
3721
+ var c;
3722
+ return Ce.level !== n && (Ce.level = n), si("https://fonts.googleapis.com/css2?family=Roboto&display=swap", t), /* @__PURE__ */ r.createElement("div", { id: ne.ENTRY, style: { width: "fit-content", height: "fit-content" } }, /* @__PURE__ */ r.createElement(Ro, { logger: Ce, storage: Xc }, /* @__PURE__ */ r.createElement(
3723
+ qc,
3724
+ {
3725
+ logger: Ce,
3726
+ rootElement: t,
3727
+ appearance: (c = s.agentPreviewConfigs) == null ? void 0 : c.appearance,
3728
+ stringSet: s.stringSet,
3729
+ language: o,
3730
+ messageTemplate: s.messageTemplate,
3731
+ theme: s.theme
3732
+ },
3733
+ /* @__PURE__ */ r.createElement(
3734
+ no,
3735
+ {
3736
+ appId: s.appId,
3737
+ aiAgentId: s.aiAgentId,
3738
+ language: o,
3739
+ countryCode: s.countryCode,
3740
+ context: s.context,
3741
+ logger: Ce,
3742
+ dispatcher: Jc,
3743
+ chatParams: { customApiHost: s.customApiHost, customWebSocketHost: s.customWebSocketHost }
3744
+ },
3745
+ /* @__PURE__ */ r.createElement(hi, { rootElement: t, ...s }, /* @__PURE__ */ r.createElement(xi, { ref: l, userSessionInfo: i }, /* @__PURE__ */ r.createElement(Fa, { ...s._UNSAFE_INTERNAL_dashboardTester }, a, /* @__PURE__ */ r.createElement("div", { id: ne.MODAL_ROOT }))))
3746
+ )
3747
+ )));
3748
+ }), Ce = new Sn(bn.WARN), Jc = new _n(Ce), Nt = "@sba/message-template", hn = (e) => `${Nt}/templates/${e}`, gn = () => `${Nt}/token`, Xc = Oo({
3749
+ onSetTemplate: (e, t) => {
3750
+ mn[e] || ee.setItem(hn(e), t);
3751
+ },
3752
+ onGetTemplate: (e) => {
3753
+ const t = mn[e];
3754
+ return t ? JSON.stringify(t) : ee.getItem(hn(e));
3755
+ },
3756
+ onSetCachedToken(e) {
3757
+ ee.setItem(gn(), e);
3758
+ },
3759
+ onGetCachedToken() {
3760
+ return ee.getItem(gn());
3761
+ },
3762
+ onClear: () => {
3763
+ ee.getKeys(Nt).forEach(ee.deleteItem);
3764
+ }
3765
+ }), ur = ({ children: e, isOpened: t }) => {
3766
+ const { dir: n, rootElement: o } = P(), i = pe(o, !0);
3767
+ return N(() => {
3768
+ const a = "sb-agent-block-scroll";
3769
+ return t ? i.body.classList.add(a) : i.body.classList.remove(a), () => {
3770
+ i.body.classList.remove(a);
3771
+ };
3772
+ }, [i, t]), /* @__PURE__ */ r.createElement(Qc, { dir: n, $visible: t }, e);
3773
+ }, Qc = m.div`width:100%;height:100%;position:fixed;top:0;left:0;z-index:${fe.WINDOW};visibility:${({ $visible: e }) => e ? "visible" : "hidden"};`, ed = 48, td = 2 / 3;
3774
+ function nd({
3775
+ className: e,
3776
+ isOpened: t,
3777
+ onClick: n,
3778
+ type: o,
3779
+ imageUrl: i,
3780
+ dir: a,
3781
+ animated: s = !0,
3782
+ backgroundColor: l,
3783
+ size: c = ed
3784
+ }) {
3785
+ const d = ht(l), u = Math.round(c * td);
3786
+ return /* @__PURE__ */ r.createElement(
3787
+ id,
3788
+ {
3789
+ dir: a,
3790
+ id: ne.LAUNCHER,
3791
+ className: e,
3792
+ "aria-label": "Sendbird AIAgent Launcher",
3793
+ onClick: n,
3794
+ $animated: s,
3795
+ $backgroundColor: l,
3796
+ $size: c
3797
+ },
3798
+ /* @__PURE__ */ r.createElement(sd, { $isOpened: t, $animated: s, $fillColor: d, $iconSize: u }, /* @__PURE__ */ r.createElement(pn.Open, { url: i, isDefaultIcon: o === "default_icon" })),
3799
+ /* @__PURE__ */ r.createElement(ad, { $isOpened: t, $animated: s, $fillColor: d, $iconSize: u }, /* @__PURE__ */ r.createElement(pn.Close, { size: u }))
3800
+ );
3801
+ }
3802
+ const rd = I`&:hover{transition:transform 250ms cubic-bezier(0.33,0,0,1);transform:scale(1.1);}&:active{transform:scale(0.8);}`, od = I`img{width:100%;height:100%;object-fit:cover;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-webkit-user-drag:none;&[data-default-icon='true']{width:${({ $iconSize: e }) => e}px;height:${({ $iconSize: e }) => e}px;filter:${({ $fillColor: e }) => e === On.WHITE ? "grayscale(100%) brightness(2000%)" : "grayscale(100%) invert(100%) saturate(0%) brightness(0%) contrast(1000%)"};}}`, mr = I`svg{width:${({ $iconSize: e }) => e}px;height:${({ $iconSize: e }) => e}px;${({ $fillColor: e }) => I`
3803
+ path {
3804
+ fill: ${e};
3805
+ }
3806
+ [class*='fill'] {
3807
+ fill: ${e};
3808
+ }
3809
+ `}
3810
+ }
3811
+ `, id = m.button`position:relative;padding:0;width:${({ $size: e }) => e}px;height:${({ $size: e }) => e}px;background:${({ $backgroundColor: e }) => e};border-radius:50%;transition:all 0.3s cubic-bezier(0.31,-0.105,0.43,1.4);border:none;display:flex;justify-content:center;align-items:center;box-shadow:0 16px 24px 2px rgba(33,33,33,0.12),0 6px 30px 5px rgba(33,33,33,0.08),0 6px 10px -5px rgba(33,33,33,0.04);${({ $animated: e }) => e && rd}`, hr = m.span`position:absolute;width:100%;height:100%;border-radius:50%;overflow:hidden;transition:transform 0.16s linear,opacity 0.08s linear,scale 0.16s linear;user-select:none;display:flex;justify-content:center;align-items:center;`, sd = m(hr)`opacity:${({ $isOpened: e }) => e ? 0 : 1};transform:${({ $animated: e, $isOpened: t }) => e && (t ? "rotate(-90deg) scale(0)" : "rotate(0deg)")};${od}${mr}`, ad = m(hr)`scale:${({ $isOpened: e }) => e ? 1 : 0};transform:${({ $animated: e, $isOpened: t }) => e && (t ? "rotate(0deg)" : "rotate(-90deg)")};${mr}`, pn = {
3812
+ Open: (e) => e.url ? /* @__PURE__ */ r.createElement("img", { src: e.url, alt: "launcher-img", "data-default-icon": e.isDefaultIcon }) : /* @__PURE__ */ r.createElement(wt, null),
3813
+ Close: ({ size: e }) => /* @__PURE__ */ r.createElement(O, { size: e, type: "chevron-down" })
3814
+ };
3815
+ function gr({ className: e, size: t }) {
3816
+ const { colors: n } = bt(), { dir: o, state: i } = P(), { launcherInfo: a } = z();
3817
+ return cd(), /* @__PURE__ */ r.createElement(
3818
+ nd,
3819
+ {
3820
+ dir: o,
3821
+ className: e,
3822
+ isOpened: i.opened,
3823
+ onClick: () => i.setOpened(!i.opened),
3824
+ type: a.type,
3825
+ imageUrl: a.imageUrl,
3826
+ backgroundColor: n.base.primary,
3827
+ size: t
3828
+ }
3829
+ );
3830
+ }
3831
+ const ld = 1e3 * 60;
3832
+ function cd() {
3833
+ const { chatSDK: e, state: t, logger: n, enableAutoDisconnectInLauncher: o } = P(), i = F(null);
3834
+ N(() => {
3835
+ if (!o) return;
3836
+ function a() {
3837
+ i.current && (clearTimeout(i.current), i.current = null);
3838
+ }
3839
+ function s() {
3840
+ e.connectionState === Ir.CLOSED && (e.reconnect(), n.debug("useSDKInactivityTimeout: reconnected")), a(), n.debug("useSDKInactivityTimeout: clear disconnect schedule");
3841
+ }
3842
+ function l() {
3843
+ a(), i.current = setTimeout(async () => {
3844
+ await e.disconnectWebSocket(), n.debug("useSDKInactivityTimeout: disconnected");
3845
+ }, ld);
3846
+ }
3847
+ t.opened ? s() : (l(), n.debug("useSDKInactivityTimeout: schedule disconnect"));
3848
+ }, [o, e, t.opened]);
3849
+ }
3850
+ const pr = Se(null);
3851
+ function dd() {
3852
+ const e = te(pr);
3853
+ if (!e)
3854
+ throw new Error("useNavigator() must be used within <Navigator />");
3855
+ return e;
3856
+ }
3857
+ function fr({ children: e }) {
3858
+ const t = dd();
3859
+ return typeof e == "function" ? e(t) : /* @__PURE__ */ r.createElement(r.Fragment, null, e);
3860
+ }
3861
+ const ud = xn`0%{transform:translateY(40px);opacity:0;}100%{transform:translateY(0px);opacity:1;}`, md = xn`0%{transform:translateY(0px);opacity:1;}100%{transform:translateY(40px);opacity:0;}`, hd = I`animation-name:${ud};animation-duration:0.3s;animation-fill-mode:forwards;`, gd = I``, pd = I`animation-name:${md};animation-duration:0.3s;animation-fill-mode:forwards;`, fd = I`visibility:hidden;`, bd = m.div`position:absolute;top:0;left:0;width:100%;height:100%;${({ $transitionState: e }) => {
3862
+ switch (e) {
3863
+ case "entering":
3864
+ return hd;
3865
+ case "entered":
3866
+ return gd;
3867
+ case "exiting":
3868
+ return pd;
3869
+ case "exited":
3870
+ return fd;
3871
+ default:
3872
+ return "";
3873
+ }
3874
+ }}${({ $active: e }) => e ? I`
3875
+ z-index: 999;
3876
+ ` : I`z-index:1;pointer-events:none;`}
3877
+ `;
3878
+ function $e({ initialId: e, children: t }) {
3879
+ const n = U((f, v) => {
3880
+ c((y) => [...y, f]), u((y) => ({ ...y, [f]: !0 })), v != null && v.reset && x((y) => ({
3881
+ ...y,
3882
+ [f]: (y[f] || 0) + 1
3883
+ })), g((y) => ({
3884
+ ...y,
3885
+ [f]: "entering"
3886
+ })), setTimeout(() => {
3887
+ g((y) => ({
3888
+ ...y,
3889
+ [f]: "entered"
3890
+ }));
3891
+ }, 300);
3892
+ }, []), o = U(() => {
3893
+ c((f) => {
3894
+ if (f.length <= 1) return f;
3895
+ const v = f[f.length - 1];
3896
+ return g((y) => ({
3897
+ ...y,
3898
+ [v]: "exiting"
3899
+ })), setTimeout(() => {
3900
+ g((y) => ({
3901
+ ...y,
3902
+ [v]: "exited"
3903
+ })), c((y) => y.slice(0, -1));
3904
+ }, 300), f;
3905
+ });
3906
+ }, []), i = ye(() => ({
3907
+ navigation: {
3908
+ navigate: n,
3909
+ pop: o
3910
+ }
3911
+ }), [n, o]), a = ye(() => _r.toArray(t).filter(
3912
+ (f) => f.type === fr
3913
+ ), [t]), s = ye(() => {
3914
+ const f = {};
3915
+ return a.forEach((v) => {
3916
+ const { id: y, lazy: $, children: T } = v.props;
3917
+ f[y] = { lazy: $, element: typeof T == "function" ? T(i) : T };
3918
+ }), f;
3919
+ }, [a]), [l, c] = _([e]), [d, u] = _(() => {
3920
+ const f = {};
3921
+ return Object.entries(s).forEach(([v, { lazy: y }]) => {
3922
+ y === !1 && (f[v] = !0);
3923
+ }), f[e] = !0, f;
3924
+ }), [p, g] = _(() => {
3925
+ const f = {};
3926
+ return Object.keys(s).forEach((v) => {
3927
+ v === e ? f[v] = "entered" : f[v] = "exited";
3928
+ }), f;
3929
+ }), [b, x] = _({}), E = l[l.length - 1];
3930
+ return /* @__PURE__ */ r.createElement(pr.Provider, { value: i }, /* @__PURE__ */ r.createElement(xd, null, Object.keys(s).map((f) => {
3931
+ var T;
3932
+ if (!d[f]) return null;
3933
+ const v = p[f] || "exited", y = f === E, $ = `${f}-${b[f] || 0}`;
3934
+ return /* @__PURE__ */ r.createElement(bd, { key: $, $transitionState: v, $active: y }, (T = s[f]) == null ? void 0 : T.element);
3935
+ })));
3936
+ }
3937
+ const xd = m.div`position:relative;width:100%;height:100%;`;
3938
+ $e.Screen = fr;
3939
+ const he = {
3940
+ activeConv: "active-conv",
3941
+ closedConv: "closed-conv",
3942
+ convList: "conv-list"
3943
+ }, br = ({ setClosedChannelUrl: e, closedChannelUrl: t }) => /* @__PURE__ */ r.createElement($e, { initialId: he.activeConv }, /* @__PURE__ */ r.createElement($e.Screen, { id: he.activeConv }, ({ navigation: n }) => /* @__PURE__ */ r.createElement(un, { onNavigateToConversationList: () => n.navigate(he.convList, { reset: !0 }) })), /* @__PURE__ */ r.createElement($e.Screen, { id: he.closedConv }, ({ navigation: n }) => /* @__PURE__ */ r.createElement(
3944
+ un,
3945
+ {
3946
+ onNavigateToConversationList: () => n.pop(),
3947
+ closedChannelUrl: t,
3948
+ onClearClosedChannelUrl: () => e(void 0)
3949
+ }
3950
+ )), /* @__PURE__ */ r.createElement($e.Screen, { id: he.convList, lazy: !0 }, ({ navigation: n }) => /* @__PURE__ */ r.createElement(
3951
+ zc,
3952
+ {
3953
+ onOpenConversationView: (o, i) => {
3954
+ i === "closed" ? (e(o), n.navigate(he.closedConv, { reset: !0 })) : n.navigate(he.activeConv);
3955
+ }
3956
+ }
3957
+ )));
3958
+ function Ed({ isExpanded: e, isOpened: t, children: n, launcher: o }) {
3959
+ const { dir: i } = P();
3960
+ return /* @__PURE__ */ r.createElement(vd, null, /* @__PURE__ */ r.createElement(Cd, { dir: i, id: ne.WINDOW, $isExpanded: e, $isOpened: t }, n), o);
3961
+ }
3962
+ const vd = m.div`display:flex;flex-direction:column;gap:8px;align-items:flex-end;`, Cd = m.div`background:${({ theme: e }) => e.colors.base.background};display:flex;overscroll-behavior:none;-webkit-overflow-scrolling:auto;height:640px;min-height:80px;width:400px;max-width:80vw;max-height:80vh;box-shadow:0px 16px 24px 2px rgba(33,33,33,0.12),0px 6px 30px 5px rgba(33,33,33,0.08),0px 6px 10px -5px rgba(33,33,33,0.04);border-radius:16px;overflow:hidden;transition:width 200ms ease 0s,height 200ms ease 0s,max-height 200ms ease 0s,transform 150ms cubic-bezier(0,1.2,1,1) 0s,opacity 83ms ease-out 0s;transform:scale(0.15);opacity:0;transform-origin:right bottom;[dir='rtl'] &:not([dir='ltr']),&[dir='rtl']{transform-origin:left bottom;}${({ $isOpened: e }) => e && _d};${({ $isExpanded: e }) => e && yd};`, yd = I`width:743px;height:723px;`, _d = I`z-index:${fe.WINDOW};pointer-events:all;transform:scale(1);opacity:1;transition:width 200ms ease 0s,height 200ms ease 0s,max-height 200ms ease 0s,transform 300ms cubic-bezier(0,1.2,1,1) 0s,opacity 83ms ease-out 0s;`, Yd = Le(function({ children: e, ...t }, n) {
3963
+ const o = De(), [i, a] = _(), s = o ? ur : Ed;
3964
+ return /* @__PURE__ */ r.createElement(dr, { enableExpandButton: !o, ref: n, ...t }, /* @__PURE__ */ r.createElement(Dn, null, ({ state: l }) => /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(s, { isExpanded: l.expanded, isOpened: l.opened, launcher: /* @__PURE__ */ r.createElement(gr, null) }, /* @__PURE__ */ r.createElement(
3965
+ br,
3966
+ {
3967
+ closedChannelUrl: i,
3968
+ setClosedChannelUrl: a
3969
+ }
3970
+ )), e)));
3971
+ }), {
3972
+ Provider: Td,
3973
+ useContext: Dt
3974
+ } = j("FixedMessengerStyle");
3975
+ function xr(e, t, n, o = 0) {
3976
+ const { top: i, bottom: a, start: s, end: l } = n;
3977
+ let c = "", d = "";
3978
+ switch (e) {
3979
+ case "start":
3980
+ d = `inset-inline-start: ${K(s)}`;
3981
+ break;
3982
+ case "end":
3983
+ d = `inset-inline-end: ${K(l)}`;
3984
+ break;
3985
+ }
3986
+ switch (t) {
3987
+ case "top":
3988
+ c = `top: calc(${K(i)} + ${o}px)`;
3989
+ break;
3990
+ case "bottom":
3991
+ c = `bottom: calc(${K(a)} + ${o}px)`;
3992
+ break;
3993
+ }
3994
+ return I`${c};${d};`;
3995
+ }
3996
+ function Sd(e) {
3997
+ const { horizontal: t, vertical: n, margin: o, launcherSize: i } = Dt();
3998
+ return /* @__PURE__ */ r.createElement(wd, { ...e, size: i, $horizontal: t, $vertical: n, $margin: o });
3999
+ }
4000
+ const wd = m(gr)`position:fixed;z-index:${fe.LAUNCHER};${({ $horizontal: e, $vertical: t, $margin: n }) => xr(e, t, n)};`;
4001
+ function kd({ isExpanded: e, isOpened: t, children: n }) {
4002
+ const { dir: o } = P(), { horizontal: i, vertical: a, margin: s, launcherSize: l } = Dt();
4003
+ return /* @__PURE__ */ r.createElement(
4004
+ Ad,
4005
+ {
4006
+ dir: o,
4007
+ id: ne.WINDOW,
4008
+ $isExpanded: e,
4009
+ $isOpened: t,
4010
+ $horizontal: i,
4011
+ $vertical: a,
4012
+ $margin: s,
4013
+ $launcherSize: l
4014
+ },
4015
+ n
4016
+ );
4017
+ }
4018
+ const Ad = m.div`background:${({ theme: e }) => e.colors.base.background};display:flex;overscroll-behavior:none;-webkit-overflow-scrolling:auto;position:fixed;${({ $horizontal: e, $vertical: t, $margin: n, $launcherSize: o }) => xr(e, t, n, o + 12)};height:640px;min-height:80px;width:400px;max-width:80vw;max-height:80vh;box-shadow:0px 16px 24px 2px rgba(33,33,33,0.12),0px 6px 30px 5px rgba(33,33,33,0.08),0px 6px 10px -5px rgba(33,33,33,0.04);border-radius:16px;overflow:hidden;transition:width 200ms ease 0s,height 200ms ease 0s,max-height 200ms ease 0s,transform 150ms cubic-bezier(0,1.2,1,1) 0s,opacity 83ms ease-out 0s;transform:scale(0.15);opacity:0;transform-origin:${({ $horizontal: e, $vertical: t }) => `${e === "start" ? "left" : "right"} ${t}`};
4019
+ [dir='rtl'] &:not([dir='ltr']),
4020
+ &[dir='rtl'] {
4021
+ transform-origin: ${({ $horizontal: e, $vertical: t }) => `${e === "start" ? "right" : "left"} ${t}`};
4022
+ }
4023
+
4024
+ ${({ $isOpened: e }) => e && $d};
4025
+ ${({ $isExpanded: e }) => e && Id};
4026
+ `, Id = I`width:743px;height:723px;`, $d = I`z-index:${fe.WINDOW};pointer-events:all;transform:scale(1);opacity:1;transition:width 200ms ease 0s,height 200ms ease 0s,max-height 200ms ease 0s,transform 300ms cubic-bezier(0,1.2,1,1) 0s,opacity 83ms ease-out 0s;`, Er = { top: 24, bottom: 24, start: 24, end: 24 }, Md = Le(function({ children: e, ...t }, n) {
4027
+ const [o, i] = _(), [a, s] = _("end-bottom"), [l, c] = _(Er), [d, u] = _(48), p = De(), g = p ? ur : kd, { horizontal: b, vertical: x } = ye(() => {
4028
+ const [E, f] = a.split("-");
4029
+ return { horizontal: E === "start" ? "start" : "end", vertical: f === "top" ? "top" : "bottom" };
4030
+ }, [a]);
4031
+ return /* @__PURE__ */ r.createElement(dr, { enableExpandButton: !p, ref: n, ...t }, /* @__PURE__ */ r.createElement(Dn, null, ({ state: E }) => /* @__PURE__ */ r.createElement(
4032
+ Td,
4033
+ {
4034
+ value: { horizontal: b, vertical: x, margin: l, launcherSize: d, setPosition: s, setMargin: c, setLauncherSize: u }
4035
+ },
4036
+ /* @__PURE__ */ r.createElement(g, { isExpanded: E.expanded, isOpened: E.opened }, /* @__PURE__ */ r.createElement(
4037
+ br,
4038
+ {
4039
+ closedChannelUrl: o,
4040
+ setClosedChannelUrl: i
4041
+ }
4042
+ )),
4043
+ /* @__PURE__ */ r.createElement(Sd, null),
4044
+ e
4045
+ )));
4046
+ }), Od = (e) => {
4047
+ var i, a, s, l;
4048
+ const { setPosition: t, setMargin: n, setLauncherSize: o } = Dt();
4049
+ return ae(() => {
4050
+ e.position && t(e.position), e.margin && n({ ...Er, ...e.margin }), e.launcherSize && o(e.launcherSize);
4051
+ }, [
4052
+ e.position,
4053
+ (i = e.margin) == null ? void 0 : i.top,
4054
+ (a = e.margin) == null ? void 0 : a.bottom,
4055
+ (s = e.margin) == null ? void 0 : s.start,
4056
+ (l = e.margin) == null ? void 0 : l.end,
4057
+ e.launcherSize
4058
+ ]), null;
4059
+ }, qd = Object.assign(Md, {
4060
+ Style: Od
4061
+ });
4062
+ export {
4063
+ Ct as A,
4064
+ io as C,
4065
+ Yd as D,
4066
+ qd as F,
4067
+ O as I,
4068
+ Zn as L,
4069
+ Da as M,
4070
+ It as O,
4071
+ Kd as P,
4072
+ $t as S,
4073
+ w as a,
4074
+ dr as b,
4075
+ h as c,
4076
+ qc as d,
4077
+ z as e,
4078
+ R as f,
4079
+ nd as g,
4080
+ Te as h,
4081
+ ge as i,
4082
+ cr as j,
4083
+ un as k,
4084
+ Lt as l,
4085
+ Jc as m,
4086
+ zc as n,
4087
+ Rt as o,
4088
+ Tn as p,
4089
+ P as u
4090
+ };