@botonic/webchat-react 2.28.0 → 2.30.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/index.d.ts +6 -3
  3. package/index.js +61 -57
  4. package/lib/components/message/index.d.ts +1 -0
  5. package/lib/components/message/message/message.d.ts +2 -0
  6. package/lib/components/message/message/use-message.d.ts +2 -0
  7. package/lib/components/message/rating-message/icons/face-angry.d.ts +2 -0
  8. package/lib/components/message/rating-message/icons/face-frown.d.ts +2 -0
  9. package/lib/components/message/rating-message/icons/face-grin-beam.d.ts +2 -0
  10. package/lib/components/message/rating-message/icons/face-meh.d.ts +2 -0
  11. package/lib/components/message/rating-message/icons/face-smile.d.ts +2 -0
  12. package/lib/components/message/rating-message/icons/index.d.ts +7 -0
  13. package/lib/components/message/rating-message/icons/rating-icon-types.d.ts +5 -0
  14. package/lib/components/message/rating-message/icons/star.d.ts +2 -0
  15. package/lib/components/message/rating-message/index.d.ts +1 -0
  16. package/lib/components/message/rating-message/rating-message.d.ts +4 -0
  17. package/lib/components/message/rating-message/use-rating-message.d.ts +34 -0
  18. package/lib/components/message-machine-renderer/message-machine-renderer.d.ts +3 -2
  19. package/lib/components/preview-events/events/ai-agent/ai-agent.d.ts +3 -0
  20. package/lib/components/preview-events/events/ai-agent/executed-tools.d.ts +7 -0
  21. package/lib/components/preview-events/events/ai-agent/index.d.ts +1 -0
  22. package/lib/components/preview-events/events/ai-agent/parse-tools.d.ts +9 -0
  23. package/lib/components/preview-events/events/ai-agent-router/ai-agent-router.d.ts +3 -0
  24. package/lib/components/preview-events/events/ai-agent-router/index.d.ts +1 -0
  25. package/lib/components/preview-events/events/bot-action.d.ts +3 -0
  26. package/lib/components/preview-events/events/components/guardrail-item.d.ts +14 -0
  27. package/lib/components/preview-events/events/components/index.d.ts +2 -0
  28. package/lib/components/preview-events/events/components/sources-section.d.ts +11 -0
  29. package/lib/components/preview-events/events/conditional-channel.d.ts +3 -0
  30. package/lib/components/preview-events/events/conditional-country.d.ts +3 -0
  31. package/lib/components/preview-events/events/conditional-custom.d.ts +3 -0
  32. package/lib/components/preview-events/events/conditional-queue-status.d.ts +3 -0
  33. package/lib/components/preview-events/events/constants.d.ts +32 -0
  34. package/lib/components/preview-events/events/fallback.d.ts +3 -0
  35. package/lib/components/preview-events/events/handoff-success.d.ts +3 -0
  36. package/lib/components/preview-events/events/index.d.ts +15 -0
  37. package/lib/components/preview-events/events/keyword.d.ts +3 -0
  38. package/lib/components/preview-events/events/knowledge-base.d.ts +3 -0
  39. package/lib/components/preview-events/events/redirect-flow.d.ts +3 -0
  40. package/lib/components/preview-events/events/smart-intent.d.ts +3 -0
  41. package/lib/components/preview-events/events/types.d.ts +112 -0
  42. package/lib/components/preview-events/events/webview-action-triggered.d.ts +3 -0
  43. package/lib/components/preview-events/hooks/use-knowledge-base-info.d.ts +19 -0
  44. package/lib/components/preview-events/hooks/use-last-label-position.d.ts +9 -0
  45. package/lib/components/preview-events/icons/ai-router-icon.d.ts +1 -0
  46. package/lib/components/preview-events/icons/ai-specialist-icon.d.ts +1 -0
  47. package/lib/components/preview-events/icons/arrow-progress-icon.d.ts +1 -0
  48. package/lib/components/preview-events/icons/brain-icon.d.ts +1 -0
  49. package/lib/components/preview-events/icons/caret-down-icon.d.ts +1 -0
  50. package/lib/components/preview-events/icons/caret-up-icon.d.ts +1 -0
  51. package/lib/components/preview-events/icons/circle-check-icon.d.ts +1 -0
  52. package/lib/components/preview-events/icons/code-icon.d.ts +1 -0
  53. package/lib/components/preview-events/icons/file-pdf-icon.d.ts +1 -0
  54. package/lib/components/preview-events/icons/file-word-icon.d.ts +1 -0
  55. package/lib/components/preview-events/icons/hand-icon.d.ts +1 -0
  56. package/lib/components/preview-events/icons/head-set-icon.d.ts +1 -0
  57. package/lib/components/preview-events/icons/index.d.ts +19 -0
  58. package/lib/components/preview-events/icons/life-ring-icon.d.ts +1 -0
  59. package/lib/components/preview-events/icons/link-icon.d.ts +1 -0
  60. package/lib/components/preview-events/icons/quote-right-icon.d.ts +1 -0
  61. package/lib/components/preview-events/icons/screwdriver-wrench-icon.d.ts +1 -0
  62. package/lib/components/preview-events/icons/split-icon.d.ts +1 -0
  63. package/lib/components/preview-events/icons/wand-icon.d.ts +1 -0
  64. package/lib/components/preview-events/icons/window-restore-icon.d.ts +1 -0
  65. package/lib/components/preview-events/index.d.ts +3 -0
  66. package/lib/components/preview-events/preview-event-message/index.d.ts +1 -0
  67. package/lib/components/preview-events/preview-event-message/preview-event-message.d.ts +20 -0
  68. package/lib/components/preview-events/preview-event-message/use-preview-event-message.d.ts +17 -0
  69. package/lib/components/preview-events/preview-events-types.d.ts +12 -0
  70. package/lib/components/shared/index.d.ts +4 -2
  71. package/lib/components/shared/markdown-text/index.d.ts +2 -0
  72. package/lib/components/shared/markdown-text/markdown-text.d.ts +6 -0
  73. package/lib/components/shared/quick-reply/index.d.ts +2 -0
  74. package/lib/components/shared/{button-component/button-component.d.ts → quick-reply/quick-reply.d.ts} +4 -4
  75. package/lib/components/webchat-app/webchat-app.d.ts +1 -4
  76. package/lib/components/webchat-messages/use-webchat-messages.d.ts +6 -0
  77. package/lib/components/webchat-overlay/base/index.d.ts +0 -1
  78. package/lib/components/webchat-overlay/base/overlay/use-overlay.d.ts +0 -4
  79. package/lib/components/webchat-overlay/base/overlay-context.d.ts +0 -2
  80. package/lib/components/webchat-overlay/index.d.ts +1 -1
  81. package/lib/components/webchat-provider/webchat-context.d.ts +2 -0
  82. package/lib/hooks/use-update-custom-message-props.d.ts +1 -0
  83. package/lib/hooks/use-webchat-state.d.ts +6 -2
  84. package/lib/types/webchat-props.d.ts +19 -0
  85. package/package.json +8 -4
  86. package/styles.css +52 -1
  87. package/trigger.js +1 -1
  88. package/webchat-app-Cxzk8Q-q.js +5437 -0
  89. package/lib/components/shared/button-component/index.d.ts +0 -2
  90. package/lib/components/webchat-overlay/base/confirm-modal/confirm-modal.d.ts +0 -8
  91. package/lib/components/webchat-overlay/base/confirm-modal/index.d.ts +0 -2
  92. package/webchat-app-I5AArwfY.js +0 -4122
  93. /package/lib/components/shared/{button-component → quick-reply}/external-link-icon.d.ts +0 -0
@@ -1,4122 +0,0 @@
1
- import { jsx as n, jsxs as w, Fragment as Ie } from "react/jsx-runtime";
2
- import { Button as Ht, DropdownMenuItem as Ze, DropdownMenuItemCheckbox as Ft, PopoverTrigger as Ut, DropdownMenu as zt } from "@lilara/ui-web-react";
3
- import bt, { createContext as Re, useContext as xe, useState as N, useRef as y, useCallback as v, useMemo as _e, useEffect as T, forwardRef as O, useLayoutEffect as jt } from "react";
4
- import { cva as F, cx as I } from "class-variance-authority";
5
- import { WebchatController as qt, setupGlobalWebchatAPI as Gt, publicWebchatController as ot, isCloseWebviewMessage as Kt, isWebviewPostMessage as Xt, WEBVIEW_MESSAGE_TYPES as le, WebchatMessageFactory as Qe } from "@botonic/webchat-core";
6
- import { useDialog as Zt, FocusScope as Qt, useButton as vt, useFocusRing as Ye, mergeProps as wt, useObjectRef as Yt } from "react-aria";
7
- import { useSelector as L } from "@xstate/react";
8
- import { DEFAULT_WEBCHAT_CLIENT_SETTINGS as Jt, BotonicButtonType as en, MessageSentBy as me, MessageType as tn } from "@botonic/shared";
9
- const Ct = Re(null);
10
- function z() {
11
- const e = xe(Ct);
12
- if (!e)
13
- throw new Error("useWebchatContext must be used within a WebchatProvider");
14
- return e;
15
- }
16
- const yt = Re(
17
- null
18
- );
19
- function nn({
20
- children: e
21
- }) {
22
- const [t, a] = N(), o = y(t);
23
- o.current = t;
24
- const s = v((l) => {
25
- a(l);
26
- }, []), i = v((l) => {
27
- o.current === l && a(void 0);
28
- }, []), r = v(() => {
29
- o.current !== void 0 && a(void 0);
30
- }, []);
31
- return /* @__PURE__ */ n(
32
- yt.Provider,
33
- {
34
- value: { activeId: t, setActive: s, clearActive: i, pauseAll: r },
35
- children: e
36
- }
37
- );
38
- }
39
- function Le() {
40
- const e = xe(yt);
41
- if (!e)
42
- throw new Error(
43
- "useMediaPlayback must be used within a MediaPlaybackProvider"
44
- );
45
- return e;
46
- }
47
- function on(e, t, a = !1) {
48
- const o = e.custom?.[t];
49
- return typeof o == "boolean" ? o : a;
50
- }
51
- function an(e) {
52
- return {
53
- input: {
54
- isComposerVisible: e.user_input_enabled,
55
- isTextInputEnabled: e.user_input_enabled,
56
- areAttachmentsVisible: e.attachments_enabled,
57
- isEmojiPickerVisible: e.emoji_picker_enabled,
58
- isAudioRecordingVisible: on(
59
- e,
60
- "audio_recording_enabled"
61
- ),
62
- blockInputs: e.block_inputs
63
- }
64
- };
65
- }
66
- function sn(e) {
67
- const [t, a] = N(""), o = _e(() => {
68
- console.log("🏗️ Creating WebchatController with config:", e);
69
- const h = new qt(e);
70
- return h.initialize().catch((p) => {
71
- console.error("❌ Failed to initialize webchat:", p);
72
- }), h;
73
- }, [e.appId]), s = L(
74
- o.machine,
75
- (h) => {
76
- const p = h.context.messageActors;
77
- return p ? Array.from(p.values()) : [];
78
- }
79
- ), i = L(
80
- o.machine,
81
- (h) => h.context.isOpen || !1
82
- ), r = L(
83
- o.machine,
84
- (h) => h.matches("operational")
85
- ), l = L(
86
- o.machine,
87
- (h) => h.matches("connectionFailed")
88
- ), f = L(
89
- o.machine,
90
- (h) => h.context.connectionStatus || "disconnected"
91
- ), _ = L(
92
- o.machine,
93
- (h) => h.context.effectiveWebchatClientSettings ?? Jt
94
- ), m = _e(
95
- () => an(_),
96
- [_]
97
- ), d = L(
98
- o.machine,
99
- (h) => h.context.soundsEnabled ?? !0
100
- ), c = L(
101
- o.machine,
102
- (h) => h.context.overlayActor
103
- ), u = L(
104
- c,
105
- (h) => h.context.overlayState
106
- );
107
- return T(() => (Gt(o), () => {
108
- console.log("🧹 Cleaning up webchat controller"), o.destroy();
109
- }), [o]), {
110
- // Framework-agnostic controller - all webchat functionality
111
- controller: o,
112
- // React-specific UI state (minimal)
113
- inputValue: t,
114
- setInputValue: a,
115
- // XState machine state (direct from machine via useSelector)
116
- isOpen: i,
117
- isInitialized: r,
118
- initializationError: l,
119
- messageActors: s,
120
- connectionStatus: f,
121
- webchatClientSettings: _,
122
- webchatClientSettingsBehaviors: m,
123
- // Overlay state (webview or cover component)
124
- overlayState: u,
125
- // Sound notification state
126
- soundsEnabled: d,
127
- // Configuration
128
- avatarConfig: e.avatarConfig,
129
- enableResponsiveHeroHeader: e.enableResponsiveHeroHeader ?? !0,
130
- // Custom messages
131
- customMessages: e.customMessages
132
- };
133
- }
134
- const rn = O(({ children: e, ...t }, a) => {
135
- const o = sn(t);
136
- bt.useImperativeHandle(a, () => o.controller, [o.controller]);
137
- const s = {
138
- state: o,
139
- controller: o.controller
140
- // Direct access to controller
141
- };
142
- return /* @__PURE__ */ n(Ct.Provider, { value: s, children: /* @__PURE__ */ n(nn, { children: e }) });
143
- }), cn = {
144
- collapsedByDefaultWhenConversationHasMessages: !0,
145
- collapseOnUserEngagement: !0,
146
- expandHeroWhenReturningToScrollTop: !0
147
- };
148
- function ln(e) {
149
- return {
150
- ...cn,
151
- ...e
152
- };
153
- }
154
- function qe(e) {
155
- return e.context.messageActors?.size ?? 0;
156
- }
157
- function Me() {
158
- }
159
- const dn = {
160
- header: {
161
- variant: "collapsed",
162
- collapseProgress: 1,
163
- hasShadow: !1
164
- },
165
- messages: {
166
- hasUserInteracted: !1,
167
- onScrollDepthChange: Me,
168
- onMessagesScrollAtTopChange: Me,
169
- onUserInteraction: Me
170
- },
171
- onUserEngagement: Me
172
- };
173
- function un({
174
- controller: e,
175
- isOpen: t,
176
- layout: a,
177
- enableResponsiveHeroHeader: o = !0
178
- }) {
179
- const s = ln(a), i = qe(
180
- e.machine.getSnapshot()
181
- ), r = s.collapsedByDefaultWhenConversationHasMessages && i > 0, l = y(null), f = y(
182
- o ? r : !1
183
- ), _ = y(!1), [m, d] = N(
184
- () => o ? r : !1
185
- ), [c, u] = N(
186
- () => o ? r : !0
187
- ), [h, p] = N(!1), g = L(
188
- e.machine,
189
- (P) => qe(P),
190
- (P, A) => P === A
191
- );
192
- T(() => {
193
- if (!o) return;
194
- if (g === 0) {
195
- u(!1), d(!1), f.current = !1, _.current = !1, l.current = 0;
196
- return;
197
- }
198
- const P = l.current;
199
- l.current = g, s.collapsedByDefaultWhenConversationHasMessages && (P === null || P === 0) && (u(!0), d(!0), f.current = !0);
200
- }, [
201
- o,
202
- g,
203
- s.collapsedByDefaultWhenConversationHasMessages
204
- ]), T(() => {
205
- if (!o || !t || !s.collapsedByDefaultWhenConversationHasMessages) return;
206
- qe(e.machine.getSnapshot()) > 0 && (u(!0), d(!0), f.current = !0);
207
- }, [
208
- o,
209
- t,
210
- e,
211
- s.collapsedByDefaultWhenConversationHasMessages
212
- ]);
213
- const b = v(() => {
214
- o && (f.current = !0, d(!0), s.collapseOnUserEngagement && u(!0));
215
- }, [o, s.collapseOnUserEngagement]), C = v(
216
- (P) => {
217
- if (o && f.current) {
218
- if (!P) {
219
- _.current = !0, u(!0);
220
- return;
221
- }
222
- s.expandHeroWhenReturningToScrollTop && _.current && u(!1);
223
- }
224
- },
225
- [o, s.expandHeroWhenReturningToScrollTop]
226
- ), S = v(
227
- (P) => {
228
- o && p(P);
229
- },
230
- [o]
231
- ), M = c ? "collapsed" : "expanded";
232
- return o ? {
233
- header: {
234
- variant: M,
235
- collapseProgress: c ? 1 : 0,
236
- hasShadow: h
237
- },
238
- messages: {
239
- hasUserInteracted: m,
240
- onScrollDepthChange: S,
241
- onMessagesScrollAtTopChange: C,
242
- onUserInteraction: b
243
- },
244
- onUserEngagement: b
245
- } : dn;
246
- }
247
- const mn = "backdrop-module__base___2047X", _n = {
248
- base: mn
249
- };
250
- function hn({ isClosing: e = !1 }) {
251
- return /* @__PURE__ */ n(
252
- "div",
253
- {
254
- className: _n.base,
255
- "aria-hidden": !0,
256
- "data-closing": e || void 0
257
- }
258
- );
259
- }
260
- function fn() {
261
- return /* @__PURE__ */ n(
262
- "svg",
263
- {
264
- xmlns: "http://www.w3.org/2000/svg",
265
- viewBox: "0 0 448 512",
266
- fill: "currentColor",
267
- role: "img",
268
- "aria-hidden": !0,
269
- children: /* @__PURE__ */ n("path", { d: "M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z" })
270
- }
271
- );
272
- }
273
- function pn() {
274
- return /* @__PURE__ */ n(
275
- "svg",
276
- {
277
- xmlns: "http://www.w3.org/2000/svg",
278
- viewBox: "0 0 384 512",
279
- fill: "currentColor",
280
- role: "img",
281
- "aria-hidden": !0,
282
- children: /* @__PURE__ */ n("path", { d: "M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z" })
283
- }
284
- );
285
- }
286
- const gn = "dialog-module__base___K18e8", bn = "dialog-module__success___z5NAQ", vn = "dialog-module__error___Q46VR", wn = "dialog-module__loading___21312", Cn = "dialog-module__actions___xFizf", yn = "dialog-module__closing___qgRFX", Mn = "dialog-module__iconContainer___8lOJ3", Pn = "dialog-module__spinner___jL0bN", Nn = "dialog-module__textContent___t6Tqt", Sn = "dialog-module__title___jr3if", Tn = "dialog-module__subtitle___K1uUB", j = {
287
- base: gn,
288
- success: bn,
289
- error: vn,
290
- loading: wn,
291
- actions: Cn,
292
- closing: yn,
293
- iconContainer: Mn,
294
- spinner: Pn,
295
- textContent: Nn,
296
- title: Sn,
297
- subtitle: Tn
298
- }, An = F(j.base, {
299
- variants: {
300
- variant: {
301
- default: "",
302
- loading: j.loading,
303
- success: j.success,
304
- error: j.error
305
- },
306
- isClosing: { true: j.closing }
307
- },
308
- defaultVariants: { variant: "default" }
309
- });
310
- function En({
311
- variant: e,
312
- title: t,
313
- subtitle: a,
314
- actions: o,
315
- isClosing: s = !1,
316
- onExited: i
317
- }) {
318
- const r = o?.slice(0, 3);
319
- process.env.NODE_ENV !== "production" && o && o.length > 3 && console.warn(
320
- `[Dialog] actions array has ${o.length} items; only the first 3 are rendered.`
321
- );
322
- const l = r?.slice().sort((d, c) => {
323
- const u = (h) => (h ?? "solid") === "solid";
324
- return Number(u(d.appearance)) - Number(u(c.appearance));
325
- }), f = y(null), { dialogProps: _, titleProps: m } = Zt({ role: "dialog" }, f);
326
- return T(() => {
327
- f.current && f.current.focus();
328
- }, [e]), /* @__PURE__ */ n(Qt, { contain: !0, restoreFocus: !0, autoFocus: !0, children: /* @__PURE__ */ w(
329
- "div",
330
- {
331
- ..._,
332
- "aria-modal": !0,
333
- ref: f,
334
- className: An({ variant: e, isClosing: s }),
335
- onAnimationEnd: s ? i : void 0,
336
- children: [
337
- (e === "loading" || e === "success" || e === "error") && /* @__PURE__ */ w(
338
- "div",
339
- {
340
- className: j.iconContainer,
341
- "data-variant": e,
342
- "aria-hidden": !0,
343
- children: [
344
- e === "loading" && /* @__PURE__ */ n("div", { className: j.spinner }, "loading"),
345
- e === "success" && /* @__PURE__ */ n(fn, {}, "success"),
346
- e === "error" && /* @__PURE__ */ n(pn, {}, "error")
347
- ]
348
- }
349
- ),
350
- /* @__PURE__ */ w("div", { className: j.textContent, children: [
351
- /* @__PURE__ */ n("h2", { ...m, className: j.title, children: t }),
352
- a && /* @__PURE__ */ n("p", { className: j.subtitle, children: a })
353
- ] }),
354
- l && l.length > 0 && /* @__PURE__ */ n("div", { className: j.actions, "data-variant": e, children: l.map(({ label: d, ...c }, u) => /* @__PURE__ */ n(Ht, { ...c, children: d }, u)) })
355
- ]
356
- }
357
- ) });
358
- }
359
- const Mt = Re(null);
360
- function In() {
361
- const e = xe(Mt);
362
- if (!e)
363
- throw new Error("useDialog must be used within a DialogProvider");
364
- return e;
365
- }
366
- const Rn = {
367
- isOpen: !1,
368
- variant: "default",
369
- title: "",
370
- subtitle: void 0,
371
- actions: void 0
372
- };
373
- function xn({
374
- children: e,
375
- onOpen: t,
376
- controlsRef: a
377
- }) {
378
- const [o, s] = N(Rn), [i, r] = N(!1), l = y(t);
379
- l.current = t;
380
- const f = v(() => {
381
- s((p) => ({ ...p, isOpen: !1 })), r(!1);
382
- }, []), _ = y(f);
383
- _.current = f;
384
- const m = v((p) => {
385
- r(!1), l.current?.(), s({
386
- isOpen: !0,
387
- variant: p.variant ?? "default",
388
- title: p.title,
389
- subtitle: p.subtitle,
390
- actions: p.actions
391
- });
392
- }, []), d = v((p) => {
393
- s((g) => ({
394
- ...g,
395
- ...p.variant !== void 0 && { variant: p.variant },
396
- ...p.title !== void 0 && { title: p.title },
397
- subtitle: "subtitle" in p ? p.subtitle : g.subtitle,
398
- actions: "actions" in p ? p.actions : g.actions
399
- }));
400
- }, []), c = v(() => {
401
- if (typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
402
- _.current();
403
- return;
404
- }
405
- r(!0);
406
- }, []);
407
- a && (a.current = { open: m, update: d, close: c }), T(() => {
408
- if (process.env.NODE_ENV !== "production") {
409
- const p = document.querySelector(
410
- "[data-webchat-container], [data-webview-frame]"
411
- );
412
- p && (getComputedStyle(p).gridTemplateRows.includes("backdrop") || console.warn(
413
- `[DialogProvider] Parent grid does not declare "backdrop-start"/"backdrop-end" named lines. Backdrop and Dialog will not be positioned correctly. Add the named lines to the container's grid-template-rows and grid-template-columns.`
414
- ));
415
- }
416
- }, []);
417
- const u = o.isOpen || i, h = { open: m, update: d, close: c, dialogState: o };
418
- return /* @__PURE__ */ w(Mt.Provider, { value: h, children: [
419
- e,
420
- u && /* @__PURE__ */ n(hn, { isClosing: i }),
421
- u && /* @__PURE__ */ n(
422
- En,
423
- {
424
- variant: o.variant,
425
- title: o.title,
426
- subtitle: o.subtitle,
427
- actions: o.actions,
428
- isClosing: i,
429
- onExited: f
430
- }
431
- )
432
- ] });
433
- }
434
- function Ln({
435
- children: e
436
- }) {
437
- const { pauseAll: t } = Le(), a = y(t);
438
- a.current = t;
439
- const o = y(null), s = () => {
440
- a.current();
441
- };
442
- return T(() => (ot.setDialogController({
443
- open: (i) => o.current?.open(i),
444
- update: (i) => o.current?.update(i),
445
- close: () => o.current?.close()
446
- }), () => {
447
- ot.setDialogController(void 0);
448
- }), []), /* @__PURE__ */ n(xn, { onOpen: s, controlsRef: o, children: e });
449
- }
450
- const Bn = "button-component-module__buttonComponent___KMwSR", kn = "button-component-module__secondary___TTpBp", Dn = "button-component-module__primary___bD2jQ", On = "button-component-module__iconWrapper___70XMO", ge = {
451
- buttonComponent: Bn,
452
- secondary: kn,
453
- primary: Dn,
454
- iconWrapper: On
455
- };
456
- function Wn() {
457
- return /* @__PURE__ */ w(
458
- "svg",
459
- {
460
- viewBox: "0 0 16 16",
461
- fill: "none",
462
- xmlns: "http://www.w3.org/2000/svg",
463
- width: "14",
464
- height: "14",
465
- role: "img",
466
- "aria-hidden": !0,
467
- children: [
468
- /* @__PURE__ */ n(
469
- "path",
470
- {
471
- d: "M6.667 3.333H3.333A1.333 1.333 0 0 0 2 4.667v8A1.333 1.333 0 0 0 3.333 14h8A1.333 1.333 0 0 0 12.667 12.667V9.333",
472
- stroke: "currentColor",
473
- strokeWidth: "1.333",
474
- strokeLinecap: "round",
475
- strokeLinejoin: "round"
476
- }
477
- ),
478
- /* @__PURE__ */ n(
479
- "path",
480
- {
481
- d: "M9.333 2h4.667v4.667",
482
- stroke: "currentColor",
483
- strokeWidth: "1.333",
484
- strokeLinecap: "round",
485
- strokeLinejoin: "round"
486
- }
487
- ),
488
- /* @__PURE__ */ n(
489
- "path",
490
- {
491
- d: "M6.667 9.333 14 2",
492
- stroke: "currentColor",
493
- strokeWidth: "1.333",
494
- strokeLinecap: "round",
495
- strokeLinejoin: "round"
496
- }
497
- )
498
- ]
499
- }
500
- );
501
- }
502
- function Vn(e) {
503
- return "type" in e ? e.type === en.WebUrl || !!e.webview : !1;
504
- }
505
- const Ae = O(
506
- ({
507
- text: e,
508
- disabled: t = !1,
509
- onClick: a,
510
- button: o,
511
- className: s,
512
- variant: i = "secondary"
513
- }, r) => {
514
- const l = Vn(o);
515
- return /* @__PURE__ */ w(
516
- "button",
517
- {
518
- ref: r,
519
- disabled: t,
520
- onClick: (_) => {
521
- _.preventDefault(), _.stopPropagation(), a?.(o);
522
- },
523
- className: I(
524
- ge.buttonComponent,
525
- i === "primary" && ge.primary,
526
- i === "secondary" && ge.secondary,
527
- l && ge.withIcon,
528
- s
529
- ),
530
- type: "button",
531
- children: [
532
- l && /* @__PURE__ */ n("span", { className: ge.iconWrapper, children: /* @__PURE__ */ n(Wn, {}) }),
533
- e
534
- ]
535
- }
536
- );
537
- }
538
- ), $n = "confirm-modal-module__overlay___rRE3G", Hn = "confirm-modal-module__modal___AliW3", Fn = "confirm-modal-module__title___nOVLU", Un = "confirm-modal-module__message___NiTmg", zn = "confirm-modal-module__buttons___T9sSa", be = {
539
- overlay: $n,
540
- modal: Hn,
541
- title: Fn,
542
- message: Un,
543
- buttons: zn
544
- };
545
- function jn(e) {
546
- return e === !1 || e === void 0 ? null : e === !0 ? {
547
- message: "Are you sure you want to close?"
548
- } : typeof e == "string" ? {
549
- message: e
550
- } : e;
551
- }
552
- const qn = ({
553
- config: e,
554
- onConfirm: t,
555
- onCancel: a
556
- }) => {
557
- const o = y(null), s = y(null), i = jn(e);
558
- T(() => {
559
- o.current?.focus();
560
- }, []), T(() => {
561
- const m = (d) => {
562
- d.key === "Escape" && (d.stopPropagation(), a());
563
- };
564
- return window.addEventListener("keydown", m, !0), () => {
565
- window.removeEventListener("keydown", m, !0);
566
- };
567
- }, [a]);
568
- const r = v((m) => {
569
- if (m.key === "Tab") {
570
- const d = s.current?.querySelectorAll(
571
- "button:not([disabled])"
572
- );
573
- if (!d?.length) return;
574
- const c = d[0], u = d[d.length - 1];
575
- m.shiftKey ? document.activeElement === c && (m.preventDefault(), u.focus()) : document.activeElement === u && (m.preventDefault(), c.focus());
576
- }
577
- }, []);
578
- if (!i)
579
- return null;
580
- const l = i.title || "Close?", f = i.confirmText || "Close", _ = i.cancelText || "Cancel";
581
- return /* @__PURE__ */ n(
582
- "div",
583
- {
584
- className: be.overlay,
585
- role: "alertdialog",
586
- "aria-modal": "true",
587
- "aria-labelledby": "confirm-close-title",
588
- "aria-describedby": "confirm-close-message",
589
- onClick: a,
590
- children: /* @__PURE__ */ w(
591
- "div",
592
- {
593
- ref: s,
594
- className: be.modal,
595
- onClick: (m) => m.stopPropagation(),
596
- onKeyDown: r,
597
- children: [
598
- /* @__PURE__ */ n("h3", { id: "confirm-close-title", className: be.title, children: l }),
599
- /* @__PURE__ */ n("p", { id: "confirm-close-message", className: be.message, children: i.message }),
600
- /* @__PURE__ */ w("div", { className: be.buttons, children: [
601
- /* @__PURE__ */ n(
602
- Ae,
603
- {
604
- text: _,
605
- button: { text: "cancel", value: "cancel" },
606
- onClick: a,
607
- variant: "secondary"
608
- }
609
- ),
610
- /* @__PURE__ */ n(
611
- Ae,
612
- {
613
- ref: o,
614
- text: f,
615
- button: { text: "confirm", value: "confirm" },
616
- onClick: t,
617
- variant: "primary"
618
- }
619
- )
620
- ] })
621
- ]
622
- }
623
- )
624
- }
625
- );
626
- }, Pt = Re(null);
627
- function Be() {
628
- const e = xe(Pt);
629
- if (!e)
630
- throw new Error("useOverlayContext must be used within an Overlay");
631
- return e;
632
- }
633
- const Gn = "cover-frame-module__base___e38vU", Kn = "cover-frame-module__errorContainer___o19mQ", Xn = "cover-frame-module__errorText___ltF9m", Ke = {
634
- base: Gn,
635
- errorContainer: Kn,
636
- errorText: Xn
637
- }, at = F(Ke.base);
638
- function Zn({ className: e }) {
639
- const { overlayState: t, coverRegistry: a, setIsLoading: o } = Be();
640
- if (T(() => {
641
- t?.type === "cover" && o(!1);
642
- }, [t?.type, o]), !t || t.type !== "cover")
643
- return null;
644
- const s = t, i = a?.[s.componentId];
645
- return i ? /* @__PURE__ */ n("div", { className: at({ className: e }), "data-overlay-cover-frame": !0, children: /* @__PURE__ */ n(i, { ...s.props || {} }) }) : (console.warn(
646
- `[OverlayCoverFrame] Component "${s.componentId}" not found in registry. Available components: ${Object.keys(a || {}).join(", ") || "none"}`
647
- ), /* @__PURE__ */ n("div", { className: at({ className: e }), "data-overlay-cover-frame": !0, children: /* @__PURE__ */ n("div", { className: Ke.errorContainer, children: /* @__PURE__ */ w("p", { className: Ke.errorText, children: [
648
- 'Component "',
649
- s.componentId,
650
- '" not found'
651
- ] }) }) }));
652
- }
653
- const Qn = "webview-frame-module__base___u5SZG", Yn = "webview-frame-module__loadingContainer___eqQ-L", Jn = "webview-frame-module__spinner___5gsaP", eo = "webview-frame-module__iframe___XewWc", Te = {
654
- base: Qn,
655
- loadingContainer: Yn,
656
- spinner: Jn,
657
- iframe: eo
658
- }, to = F(Te.base);
659
- function no({ className: e }) {
660
- const { overlayState: t, sandboxPermissions: a, isLoading: o, setIsLoading: s } = Be(), i = v(() => {
661
- s(!1);
662
- }, [s]);
663
- if (!t || t.type !== "webview")
664
- return null;
665
- const r = t;
666
- return /* @__PURE__ */ w("div", { className: to({ className: e }), "data-overlay-webview-frame": !0, children: [
667
- o && /* @__PURE__ */ n("div", { className: Te.loadingContainer, children: /* @__PURE__ */ n("div", { className: Te.spinner, "aria-label": "Loading webview" }) }),
668
- /* @__PURE__ */ n(
669
- "iframe",
670
- {
671
- src: r.url,
672
- className: Te.iframe,
673
- sandbox: a,
674
- title: r.title || "Webview",
675
- onLoad: i,
676
- style: { opacity: o ? 0 : 1 }
677
- }
678
- )
679
- ] });
680
- }
681
- function oo({ className: e }) {
682
- const { overlayState: t } = Be();
683
- if (!t)
684
- return null;
685
- switch (t.type) {
686
- case "webview":
687
- return /* @__PURE__ */ n(no, { className: e });
688
- case "cover":
689
- return /* @__PURE__ */ n(Zn, { className: e });
690
- default:
691
- return null;
692
- }
693
- }
694
- const ao = "header-module__base___WYM0o", so = "header-module__minimal___6nq5w", ro = "header-module__titleContainer___56hi4", io = "header-module__icon___BCSbe", co = "header-module__title___0c-LL", lo = "header-module__closeButton___wOwC8", se = {
695
- base: ao,
696
- default: "header-module__default___z7D3c",
697
- minimal: so,
698
- titleContainer: ro,
699
- icon: io,
700
- title: co,
701
- closeButton: lo
702
- };
703
- function uo(e, t) {
704
- const a = t?.title || "Overlay", o = t?.icon, s = t?.allowClose !== !1;
705
- return {
706
- title: a,
707
- icon: o,
708
- showClose: s,
709
- variants: {
710
- variant: e.variant || "default"
711
- }
712
- };
713
- }
714
- const mo = F(se.base, {
715
- variants: {
716
- variant: {
717
- default: se.default,
718
- minimal: se.minimal
719
- }
720
- },
721
- defaultVariants: {
722
- variant: "default"
723
- }
724
- });
725
- function _o(e) {
726
- const { overlayState: t, attemptClose: a } = Be(), { showClose: o, title: s, icon: i, variants: r } = uo(
727
- e,
728
- t
729
- );
730
- return /* @__PURE__ */ w("header", { className: mo(r), "data-overlay-header": !0, children: [
731
- /* @__PURE__ */ w("div", { className: se.titleContainer, children: [
732
- i && /* @__PURE__ */ n("span", { className: se.icon, children: i }),
733
- /* @__PURE__ */ n("h4", { className: se.title, children: s })
734
- ] }),
735
- o && /* @__PURE__ */ n(
736
- "button",
737
- {
738
- type: "button",
739
- className: se.closeButton,
740
- onClick: a,
741
- "aria-label": "Close overlay",
742
- children: "×"
743
- }
744
- )
745
- ] });
746
- }
747
- const ho = "overlay-module__base___qm4j7", fo = "overlay-module__loading___8U4v9", st = {
748
- base: ho,
749
- loading: fo
750
- };
751
- function po(e, t) {
752
- const [a, o] = N(!0), [s, i] = N(!1), r = v(() => {
753
- e?.confirmClose ? i(!0) : t.onClose();
754
- }, [t, e?.confirmClose]), l = v(() => {
755
- i(!1), t.onClose();
756
- }, [t]), f = v(() => {
757
- i(!1);
758
- }, []);
759
- return T(() => {
760
- e?.isOpen && e?.type === "webview" && o(!0);
761
- }, [e?.isOpen, e?.type]), T(() => {
762
- e?.type === "webview" && o(!0);
763
- }, [e?.type === "webview" ? e.url : null]), T(() => {
764
- if (e?.type !== "webview")
765
- return;
766
- const _ = (m) => {
767
- if (Kt(m.data)) {
768
- r();
769
- return;
770
- }
771
- if (Xt(m.data)) {
772
- const d = m.data;
773
- switch (d.type) {
774
- case le.SET_TITLE:
775
- t.onSetTitle(d.title);
776
- break;
777
- case le.SET_ICON:
778
- t.onSetIcon(d.icon);
779
- break;
780
- case le.SET_ALLOW_CLOSE:
781
- t.onSetAllowClose(d.allow);
782
- break;
783
- case le.SET_CONFIRM_CLOSE:
784
- t.onSetConfirmClose(d.config);
785
- break;
786
- case le.SEND_PAYLOAD:
787
- t.onSendPayload(d.payload);
788
- break;
789
- case le.NAVIGATE:
790
- t.onNavigate(d.url);
791
- break;
792
- }
793
- }
794
- };
795
- return window.addEventListener("message", _), () => {
796
- window.removeEventListener("message", _);
797
- };
798
- }, [t, r, e?.type]), T(() => {
799
- if (s) return;
800
- const _ = (m) => {
801
- m.key === "Escape" && e?.isOpen && e?.allowClose !== !1 && r();
802
- };
803
- return window.addEventListener("keydown", _), () => {
804
- window.removeEventListener("keydown", _);
805
- };
806
- }, [
807
- r,
808
- s,
809
- e?.isOpen,
810
- e?.allowClose
811
- ]), {
812
- isLoading: a,
813
- setIsLoading: o,
814
- showConfirmModal: s,
815
- setShowConfirmModal: i,
816
- attemptClose: r,
817
- handleConfirmClose: l,
818
- handleCancelClose: f,
819
- variants: { isLoading: a }
820
- };
821
- }
822
- const go = "allow-scripts allow-forms allow-same-origin allow-popups", bo = F(st.base, {
823
- variants: {
824
- isLoading: {
825
- true: st.loading
826
- }
827
- }
828
- });
829
- function vo({
830
- overlayState: e,
831
- onClose: t,
832
- onSetTitle: a,
833
- onSetIcon: o,
834
- onSetAllowClose: s,
835
- onSetConfirmClose: i,
836
- onSendPayload: r,
837
- onNavigate: l,
838
- coverRegistry: f,
839
- children: _
840
- }) {
841
- const m = {
842
- onClose: t,
843
- onSetTitle: a,
844
- onSetIcon: o,
845
- onSetAllowClose: s,
846
- onSetConfirmClose: i,
847
- onSendPayload: r,
848
- onNavigate: l
849
- }, {
850
- isLoading: d,
851
- setIsLoading: c,
852
- showConfirmModal: u,
853
- setShowConfirmModal: h,
854
- attemptClose: p,
855
- handleConfirmClose: g,
856
- handleCancelClose: b,
857
- variants: C
858
- } = po(e, m);
859
- if (!e?.isOpen)
860
- return null;
861
- const S = {
862
- overlayState: e,
863
- ...m,
864
- sandboxPermissions: go,
865
- isLoading: d,
866
- setIsLoading: c,
867
- attemptClose: p,
868
- showConfirmModal: u,
869
- setShowConfirmModal: h,
870
- coverRegistry: f
871
- };
872
- return /* @__PURE__ */ n(Pt.Provider, { value: S, children: /* @__PURE__ */ w("div", { className: bo(C), "data-overlay": !0, children: [
873
- _ || /* @__PURE__ */ w(Ie, { children: [
874
- /* @__PURE__ */ n(_o, {}),
875
- /* @__PURE__ */ n(oo, {})
876
- ] }),
877
- u && e.confirmClose && /* @__PURE__ */ n(
878
- qn,
879
- {
880
- config: e.confirmClose,
881
- onConfirm: g,
882
- onCancel: b
883
- }
884
- )
885
- ] }) });
886
- }
887
- function wo(e, t, a) {
888
- const {
889
- layout: o = "default",
890
- size: s = "normal",
891
- position: i = "bottom-right",
892
- "aria-label": r = "Webchat interface",
893
- className: l,
894
- coverRegistry: f,
895
- // Exclude from DOM props
896
- ..._
897
- } = e, m = L(t.controller.machine, (b) => b.context.isOpen || !1), [d, c] = N(null), [u, h] = N(!1), p = y(!1), g = v(
898
- (b) => {
899
- b.target === b.currentTarget && d !== null && (d === "closing" && h(!1), c(null));
900
- },
901
- [d]
902
- );
903
- return T(() => {
904
- const b = p.current;
905
- p.current = m, b === !1 && m ? (h(!0), c("opening")) : b === !0 && !m && c("closing");
906
- }, [m]), {
907
- // Component visibility - stays true during close animation
908
- shouldRender: u,
909
- // Container element props
910
- containerProps: {
911
- ref: a,
912
- role: "dialog",
913
- "aria-label": r,
914
- "aria-live": "polite",
915
- "data-testid": "webchat-container",
916
- "data-layout": o,
917
- "data-size": s,
918
- tabIndex: -1,
919
- onAnimationEnd: g,
920
- ..._
921
- },
922
- // CSS class variants
923
- variants: {
924
- layout: o,
925
- size: s,
926
- position: i,
927
- isOpen: m,
928
- isOpening: d === "opening",
929
- isClosing: d === "closing",
930
- className: l
931
- }
932
- };
933
- }
934
- const Co = "webchat-container-module__base___-nEHI", ee = {
935
- base: Co,
936
- "is-open": "webchat-container-module__is-open___y7UjX",
937
- default: "webchat-container-module__default___Zl33C",
938
- "position-bottom-right": "webchat-container-module__position-bottom-right___NIW0p",
939
- "position-bottom-left": "webchat-container-module__position-bottom-left___gatKC",
940
- "position-top-right": "webchat-container-module__position-top-right___DKI8J",
941
- "position-top-left": "webchat-container-module__position-top-left___ehR4d",
942
- "is-opening": "webchat-container-module__is-opening___5Ot9W",
943
- "is-closing": "webchat-container-module__is-closing___o0hqs"
944
- }, yo = F(ee.base, {
945
- variants: {
946
- layout: {
947
- default: ee.default
948
- },
949
- position: {
950
- "bottom-right": ee["position-bottom-right"],
951
- "bottom-left": ee["position-bottom-left"],
952
- "top-right": ee["position-top-right"],
953
- "top-left": ee["position-top-left"]
954
- },
955
- isOpen: {
956
- true: ee["is-open"]
957
- },
958
- isOpening: {
959
- true: ee["is-opening"]
960
- },
961
- isClosing: {
962
- true: ee["is-closing"]
963
- }
964
- },
965
- defaultVariants: {
966
- layout: "default",
967
- position: "bottom-right"
968
- }
969
- });
970
- function Mo(e) {
971
- const { state: t, controller: a } = z(), o = y(null), { shouldRender: s, containerProps: i, variants: r } = wo(
972
- e,
973
- t,
974
- o
975
- ), {
976
- children: l,
977
- coverRegistry: f,
978
- layout: _,
979
- size: m,
980
- position: d,
981
- ...c
982
- } = e, u = v(
983
- () => a.overlay.close(),
984
- [a]
985
- ), h = v(
986
- (M) => a.overlay.setTitle(M),
987
- [a]
988
- ), p = v(
989
- (M) => a.overlay.setIcon(M),
990
- [a]
991
- ), g = v(
992
- (M) => a.overlay.setAllowClose(M),
993
- [a]
994
- ), b = v(
995
- (M) => a.overlay.setConfirmClose(M),
996
- [a]
997
- ), C = v(
998
- (M) => a.overlay.sendPayload(M),
999
- [a]
1000
- ), S = v(
1001
- (M) => a.overlay.navigate(M),
1002
- [a]
1003
- );
1004
- return s ? /* @__PURE__ */ w(
1005
- "div",
1006
- {
1007
- ...i,
1008
- ...c,
1009
- className: yo(r),
1010
- "data-testid": "webchat-container",
1011
- "data-webchat-container": !0,
1012
- children: [
1013
- /* @__PURE__ */ n(Ln, { children: l }),
1014
- /* @__PURE__ */ n(
1015
- vo,
1016
- {
1017
- overlayState: t.overlayState,
1018
- onClose: u,
1019
- onSetTitle: h,
1020
- onSetIcon: p,
1021
- onSetAllowClose: g,
1022
- onSetConfirmClose: b,
1023
- onSendPayload: C,
1024
- onNavigate: S,
1025
- coverRegistry: f
1026
- }
1027
- )
1028
- ]
1029
- }
1030
- ) : null;
1031
- }
1032
- function Po() {
1033
- return /* @__PURE__ */ w(
1034
- "svg",
1035
- {
1036
- xmlns: "http://www.w3.org/2000/svg",
1037
- viewBox: "0 0 10 10",
1038
- fill: "none",
1039
- stroke: "currentColor",
1040
- strokeWidth: "1.5",
1041
- strokeLinecap: "round",
1042
- role: "img",
1043
- "aria-hidden": !0,
1044
- width: "10",
1045
- height: "10",
1046
- children: [
1047
- /* @__PURE__ */ n("line", { x1: "1", y1: "1", x2: "9", y2: "9" }),
1048
- /* @__PURE__ */ n("line", { x1: "9", y1: "1", x2: "1", y2: "9" })
1049
- ]
1050
- }
1051
- );
1052
- }
1053
- function No() {
1054
- return /* @__PURE__ */ n(
1055
- "svg",
1056
- {
1057
- xmlns: "http://www.w3.org/2000/svg",
1058
- viewBox: "0 0 192 512",
1059
- fill: "currentColor",
1060
- role: "img",
1061
- "aria-hidden": !0,
1062
- width: "5",
1063
- height: "14",
1064
- children: /* @__PURE__ */ n("path", { d: "M96 184c39.8 0 72 32.2 72 72s-32.2 72-72 72-72-32.2-72-72 32.2-72 72-72zM24 80c0 39.8 32.2 72 72 72s72-32.2 72-72S135.8 8 96 8 24 40.2 24 80zm0 352c0 39.8 32.2 72 72 72s72-32.2 72-72-32.2-72-72-72-72 32.2-72 72z" })
1065
- }
1066
- );
1067
- }
1068
- function So(e) {
1069
- return Math.min(1, Math.max(0, e));
1070
- }
1071
- function To(e, t, a) {
1072
- const {
1073
- title: o = "Chat",
1074
- avatarSrc: s,
1075
- avatarAlt: i,
1076
- showStatus: r = !0,
1077
- showClose: l = !0,
1078
- onClose: f,
1079
- variant: _ = "collapsed",
1080
- collapseProgress: m,
1081
- hasShadow: d = !1,
1082
- enableResponsiveHeroHeader: c,
1083
- "aria-label": u,
1084
- className: h,
1085
- style: p,
1086
- ...g
1087
- } = e, b = s ?? t.avatarConfig?.bot?.src, C = t.avatarConfig?.bot?.svg, S = i ?? t.avatarConfig?.bot?.alt, M = L(
1088
- t.controller.machine,
1089
- (B) => B.context.connectionStatus || "disconnected"
1090
- ), P = v(() => {
1091
- f ? f() : t.controller.close();
1092
- }, [f, t.controller]), A = v((B) => {
1093
- switch (B) {
1094
- case "connected":
1095
- return "Online";
1096
- case "connecting":
1097
- return "Connecting...";
1098
- case "disconnected":
1099
- return "Offline";
1100
- case "unavailable":
1101
- return "Connection unstable";
1102
- case "error":
1103
- return "Connection error";
1104
- default:
1105
- return "Offline";
1106
- }
1107
- }, []), W = r ? A(M) : void 0, V = _ !== "expanded", $ = c ?? t.enableResponsiveHeroHeader ?? !0, q = So(
1108
- m ?? Number(V)
1109
- ), G = {
1110
- ...p,
1111
- "--webchat-header-collapse-progress": String(q)
1112
- };
1113
- return {
1114
- // Header element props
1115
- headerProps: {
1116
- ...g,
1117
- ref: a,
1118
- "aria-label": u || `${o} header`,
1119
- style: G,
1120
- "data-webchat-responsive-hero": $ ? "on" : "off"
1121
- },
1122
- // Header content
1123
- title: o,
1124
- avatarSrc: b,
1125
- avatarSvg: C,
1126
- avatarAlt: S,
1127
- showStatus: r,
1128
- statusText: W,
1129
- showClose: l,
1130
- onClose: P,
1131
- connectionStatus: M,
1132
- // CSS class variants
1133
- variants: {
1134
- variant: _,
1135
- hasShadow: d,
1136
- className: h
1137
- }
1138
- };
1139
- }
1140
- const Ao = "webchat-header-module__base___VbIWd", Eo = "webchat-header-module__profile___NsohW", Io = "webchat-header-module__avatar___klWPr", Ro = "webchat-header-module__collapsed___Xwj3m", xo = "webchat-header-module__expanded___9RKFH", x = {
1141
- base: Ao,
1142
- "header-content": "webchat-header-module__header-content___bPP9l",
1143
- profile: Eo,
1144
- avatar: Io,
1145
- "header-text": "webchat-header-module__header-text___64Yj9",
1146
- "header-title": "webchat-header-module__header-title___QHcHi",
1147
- "status-text": "webchat-header-module__status-text___fTZvQ",
1148
- "status-section": "webchat-header-module__status-section___TlGf-",
1149
- "header-actions": "webchat-header-module__header-actions___hVl-F",
1150
- "header-button": "webchat-header-module__header-button___8knmx",
1151
- "avatar-img": "webchat-header-module__avatar-img___5e2rl",
1152
- "avatar-svg": "webchat-header-module__avatar-svg___dKAm6",
1153
- "status-dot": "webchat-header-module__status-dot___rjbA2",
1154
- "has-shadow": "webchat-header-module__has-shadow___uQ7mG",
1155
- collapsed: Ro,
1156
- expanded: xo
1157
- }, Nt = O((e, t) => {
1158
- const a = Yt(t), { buttonProps: o } = vt(e, a), { focusProps: s, isFocusVisible: i } = Ye();
1159
- return /* @__PURE__ */ n(
1160
- "button",
1161
- {
1162
- ...wt(o, s),
1163
- ref: a,
1164
- className: x["header-button"],
1165
- "aria-label": e["aria-label"] ?? "Open menu",
1166
- "data-focus-visible": i || void 0,
1167
- children: /* @__PURE__ */ n(No, {})
1168
- }
1169
- );
1170
- });
1171
- function Lo(e) {
1172
- const t = y(null), { buttonProps: a } = vt(e, t), { focusProps: o, isFocusVisible: s } = Ye();
1173
- return /* @__PURE__ */ n(
1174
- "button",
1175
- {
1176
- ...wt(a, o),
1177
- ref: t,
1178
- className: x["header-button"],
1179
- "aria-label": e["aria-label"] ?? "Close chat",
1180
- "data-focus-visible": s || void 0,
1181
- children: /* @__PURE__ */ n(Po, {})
1182
- }
1183
- );
1184
- }
1185
- Nt.displayName = "MenuTriggerButton";
1186
- const Bo = F(x.base, {
1187
- variants: {
1188
- variant: {
1189
- default: x.collapsed,
1190
- collapsed: x.collapsed,
1191
- expanded: x.expanded
1192
- },
1193
- hasShadow: {
1194
- true: x["has-shadow"]
1195
- }
1196
- },
1197
- defaultVariants: {
1198
- variant: "collapsed"
1199
- }
1200
- });
1201
- function ko({
1202
- children: e,
1203
- ...t
1204
- }) {
1205
- const { state: a } = z(), o = y(null), {
1206
- headerProps: s,
1207
- title: i,
1208
- avatarSrc: r,
1209
- avatarSvg: l,
1210
- avatarAlt: f,
1211
- showStatus: _,
1212
- statusText: m,
1213
- showClose: d,
1214
- onClose: c,
1215
- connectionStatus: u,
1216
- variants: h
1217
- } = To(t, a, o);
1218
- return /* @__PURE__ */ n(
1219
- "header",
1220
- {
1221
- ...s,
1222
- className: Bo(h),
1223
- "data-webchat-header": !0,
1224
- children: /* @__PURE__ */ w("div", { className: x["header-content"], children: [
1225
- /* @__PURE__ */ w("div", { className: x.profile, children: [
1226
- /* @__PURE__ */ n("div", { className: x.avatar, "aria-hidden": "true", children: l ? /* @__PURE__ */ n(
1227
- "div",
1228
- {
1229
- className: x["avatar-svg"],
1230
- dangerouslySetInnerHTML: { __html: l },
1231
- role: "img",
1232
- "aria-label": f ?? i
1233
- }
1234
- ) : r ? /* @__PURE__ */ n(
1235
- "img",
1236
- {
1237
- src: r,
1238
- alt: f ?? i,
1239
- className: x["avatar-img"]
1240
- }
1241
- ) : null }),
1242
- /* @__PURE__ */ w("div", { className: x["header-text"], children: [
1243
- /* @__PURE__ */ n("h3", { className: x["header-title"], children: i }),
1244
- _ && /* @__PURE__ */ w("div", { className: x["status-section"], children: [
1245
- /* @__PURE__ */ n(
1246
- "div",
1247
- {
1248
- className: x["status-dot"],
1249
- "data-status": u,
1250
- "aria-hidden": "true"
1251
- }
1252
- ),
1253
- /* @__PURE__ */ n("span", { className: x["status-text"], children: m })
1254
- ] })
1255
- ] })
1256
- ] }),
1257
- /* @__PURE__ */ w("div", { className: x["header-actions"], children: [
1258
- e,
1259
- d && /* @__PURE__ */ n(Lo, { onPress: c })
1260
- ] })
1261
- ] })
1262
- }
1263
- );
1264
- }
1265
- const re = {
1266
- xmlns: "http://www.w3.org/2000/svg",
1267
- viewBox: "0 0 512 512",
1268
- fill: "currentColor",
1269
- role: "img",
1270
- "aria-hidden": !0
1271
- };
1272
- function Do() {
1273
- return /* @__PURE__ */ n("svg", { ...re, children: /* @__PURE__ */ n("path", { d: "M216 0h80c13.3 0 24 10.7 24 24v168h87.7c17.8 0 26.7 21.5 14.1 34.1L269.7 378.3c-7.5 7.5-19.8 7.5-27.3 0L90.1 226.1C77.5 213.5 86.3 192 104.2 192H192V24c0-13.3 10.7-24 24-24zm296 376v112c0 13.3-10.7 24-24 24H24c-13.3 0-24-10.7-24-24V376c0-13.3 10.7-24 24-24h146.7l49 49c20.1 20.1 52.5 20.1 72.6 0l49-49H488c13.3 0 24 10.7 24 24zm-124 88c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20zm-64 0c0-11-9-20-20-20s-20 9-20 20 9 20 20 20 20-9 20-20z" }) });
1274
- }
1275
- function Oo({
1276
- onClose: e,
1277
- children: t
1278
- }) {
1279
- const { controller: a } = z();
1280
- return /* @__PURE__ */ n(
1281
- Ze,
1282
- {
1283
- icon: /* @__PURE__ */ n(Do, {}),
1284
- onPress: () => {
1285
- a.downloadTranscript(), e?.();
1286
- },
1287
- children: t ?? "Download transcript"
1288
- }
1289
- );
1290
- }
1291
- function Wo() {
1292
- return /* @__PURE__ */ n("svg", { ...re, children: /* @__PURE__ */ n("path", { d: "M212.333 224.333H12c-6.627 0-12-5.373-12-12V12C0 5.373 5.373 0 12 0h48c6.627 0 12 5.373 12 12v78.112C117.773 39.279 184.26 7.47 258.175 8.007c136.906.994 246.448 111.623 246.157 248.532C504.041 393.258 393.12 504 256.333 504c-64.089 0-122.496-24.313-166.51-64.215-5.099-4.622-5.334-12.554-.467-17.42l33.967-33.967c4.474-4.474 11.662-4.717 16.401-.525C170.76 415.336 211.58 432 256.333 432c97.268 0 176-78.716 176-176 0-97.267-78.716-176-176-176-58.496 0-110.28 28.476-142.274 72.333h98.274c6.627 0 12 5.373 12 12v48c0 6.627-5.373 12-12 12z" }) });
1293
- }
1294
- function Vo({
1295
- onClose: e,
1296
- children: t
1297
- }) {
1298
- const { controller: a } = z();
1299
- return /* @__PURE__ */ n(
1300
- Ze,
1301
- {
1302
- icon: /* @__PURE__ */ n(Wo, {}),
1303
- onPress: () => {
1304
- a.resetConversation(), e?.();
1305
- },
1306
- children: t ?? "Reset conversation"
1307
- }
1308
- );
1309
- }
1310
- function $o() {
1311
- return /* @__PURE__ */ n("svg", { ...re, children: /* @__PURE__ */ n("path", { d: "M497 273L329 441c-15 15-41 4.5-41-17v-96H152c-13.3 0-24-10.7-24-24v-96c0-13.3 10.7-24 24-24h136V88c0-21.4 25.9-32 41-17l168 168c9.3 9.4 9.3 24.6 0 34zM192 436v-40c0-6.6-5.4-12-12-12H96c-17.7 0-32-14.3-32-32V160c0-17.7 14.3-32 32-32h84c6.6 0 12-5.4 12-12V76c0-6.6-5.4-12-12-12H96C42.1 64 0 106.1 0 160v192c0 53.9 42.1 96 96 96h84c6.6 0 12-5.4 12-12z" }) });
1312
- }
1313
- const Ho = "Reset session?", Fo = "You will end this conversation and lose your chat history.", Uo = "Cancel", zo = "Reset session";
1314
- function jo({
1315
- onClose: e
1316
- }) {
1317
- const { controller: t } = z(), { open: a, close: o } = In(), s = v(() => {
1318
- o();
1319
- }, [o]), i = v(() => {
1320
- t.resetSession(), o();
1321
- }, [o, t]);
1322
- return {
1323
- menuItemProps: {
1324
- onPress: v(() => {
1325
- a({
1326
- title: Ho,
1327
- subtitle: Fo,
1328
- actions: [
1329
- {
1330
- label: Uo,
1331
- intent: "secondary",
1332
- appearance: "outline",
1333
- onPress: s
1334
- },
1335
- {
1336
- label: zo,
1337
- intent: "danger",
1338
- onPress: i
1339
- }
1340
- ]
1341
- }), e?.();
1342
- }, [s, i, e, a])
1343
- }
1344
- };
1345
- }
1346
- function qo({
1347
- onClose: e,
1348
- children: t
1349
- }) {
1350
- const { menuItemProps: a } = jo({ onClose: e });
1351
- return /* @__PURE__ */ n(Ze, { icon: /* @__PURE__ */ n($o, {}), onPress: a.onPress, children: t ?? "Reset session" });
1352
- }
1353
- function Go() {
1354
- return /* @__PURE__ */ n(
1355
- "svg",
1356
- {
1357
- xmlns: "http://www.w3.org/2000/svg",
1358
- viewBox: "0 0 448 512",
1359
- fill: "currentColor",
1360
- role: "img",
1361
- "aria-hidden": !0,
1362
- children: /* @__PURE__ */ n("path", { d: "M224 512c35.32 0 63.97-28.65 63.97-64H160.03c0 35.35 28.65 64 63.97 64zm215.39-149.71c-19.32-20.76-55.47-51.99-55.47-154.29 0-77.7-54.48-139.9-127.94-155.16V32c0-17.67-14.32-32-31.98-32s-31.98 14.33-31.98 32v20.84C118.56 68.1 64.08 130.3 64.08 208c0 102.3-36.15 133.53-55.47 154.29-6 6.45-8.66 14.16-8.61 21.71.11 16.4 12.98 32 32.1 32h383.8c19.12 0 32-15.6 32.1-32 .05-7.55-2.61-15.27-8.61-21.71z" })
1363
- }
1364
- );
1365
- }
1366
- function Ko({
1367
- onClose: e,
1368
- children: t
1369
- }) {
1370
- const { state: a, controller: o } = z(), { soundsEnabled: s } = a;
1371
- return /* @__PURE__ */ n(
1372
- Ft,
1373
- {
1374
- icon: /* @__PURE__ */ n(Go, {}),
1375
- isSelected: s,
1376
- onChange: (i) => o.toggleSounds(i),
1377
- children: t ?? "Sounds"
1378
- }
1379
- );
1380
- }
1381
- function St() {
1382
- return /* @__PURE__ */ n("svg", { ...re, viewBox: "0 0 384 512", children: /* @__PURE__ */ n("path", { d: "M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z" }) });
1383
- }
1384
- function Tt() {
1385
- return /* @__PURE__ */ n(
1386
- "svg",
1387
- {
1388
- width: "16",
1389
- height: "16",
1390
- viewBox: "0 0 16 16",
1391
- fill: "none",
1392
- xmlns: "http://www.w3.org/2000/svg",
1393
- role: "img",
1394
- "aria-hidden": !0,
1395
- children: /* @__PURE__ */ n(
1396
- "path",
1397
- {
1398
- d: "M12 14.5C12.25 14.5 12.5 14.2812 12.5 14V5H10C9.4375 5 9 4.5625 9 4V1.5H4C3.71875 1.5 3.5 1.75 3.5 2V14C3.5 14.2812 3.71875 14.5 4 14.5H12ZM2 2C2 0.90625 2.875 0 4 0H9.15625C9.6875 0 10.1875 0.21875 10.5625 0.59375L13.4062 3.4375C13.7812 3.8125 14 4.3125 14 4.84375V14C14 15.125 13.0938 16 12 16H4C2.875 16 2 15.125 2 14V2Z",
1399
- fill: "currentColor"
1400
- }
1401
- )
1402
- }
1403
- );
1404
- }
1405
- function At() {
1406
- return /* @__PURE__ */ n(
1407
- "svg",
1408
- {
1409
- width: "16",
1410
- height: "16",
1411
- viewBox: "0 0 16 16",
1412
- fill: "none",
1413
- xmlns: "http://www.w3.org/2000/svg",
1414
- role: "img",
1415
- "aria-hidden": !0,
1416
- children: /* @__PURE__ */ n(
1417
- "path",
1418
- {
1419
- d: "M2 14.5H3.5V16H2C0.875 16 0 15.125 0 14V2C0 0.90625 0.875 0 2 0H7.15625C7.6875 0 8.1875 0.21875 8.5625 0.59375L11.4062 3.4375C11.7812 3.8125 12 4.3125 12 4.84375V9.5H10.5V5H8C7.4375 5 7 4.5625 7 4V1.5H2C1.71875 1.5 1.5 1.75 1.5 2V14C1.5 14.2812 1.71875 14.5 2 14.5ZM5.5 11H6.5C7.4375 11 8.25 11.8125 8.25 12.75C8.25 13.7188 7.4375 14.5 6.5 14.5H6V15.5C6 15.7812 5.75 16 5.5 16C5.21875 16 5 15.7812 5 15.5V14V11.5C5 11.25 5.21875 11 5.5 11ZM6.5 13.5C6.90625 13.5 7.25 13.1875 7.25 12.75C7.25 12.3438 6.90625 12 6.5 12H6V13.5H6.5ZM9.5 11H10.5C11.3125 11 12 11.6875 12 12.5V14.5C12 15.3438 11.3125 16 10.5 16H9.5C9.21875 16 9 15.7812 9 15.5V11.5C9 11.25 9.21875 11 9.5 11ZM10.5 15C10.75 15 11 14.7812 11 14.5V12.5C11 12.25 10.75 12 10.5 12H10V15H10.5ZM13 11.5C13 11.25 13.2188 11 13.5 11H15C15.25 11 15.5 11.25 15.5 11.5C15.5 11.7812 15.25 12 15 12H14V13H15C15.25 13 15.5 13.25 15.5 13.5C15.5 13.7812 15.25 14 15 14H14V15.5C14 15.7812 13.75 16 13.5 16C13.2188 16 13 15.7812 13 15.5V13.5V11.5Z",
1420
- fill: "currentColor"
1421
- }
1422
- )
1423
- }
1424
- );
1425
- }
1426
- const Xo = "attachment-preview-module__container___VIJkZ", Zo = "attachment-preview-module__thumbnailList___by6c8", Qo = "attachment-preview-module__thumbnailItem___GNFlf", Yo = "attachment-preview-module__thumbnail___Ckp9-", Jo = "attachment-preview-module__videoWrapper___lmpFI", ea = "attachment-preview-module__videoPlayBadge___ky5sB", ta = "attachment-preview-module__fileList___HO6cw", na = "attachment-preview-module__fileRow___F61bW", oa = "attachment-preview-module__fileIcon___azbPW", aa = "attachment-preview-module__fileName___Ye6Av", sa = "attachment-preview-module__removeBtn___TWvdF", H = {
1427
- container: Xo,
1428
- thumbnailList: Zo,
1429
- thumbnailItem: Qo,
1430
- thumbnail: Yo,
1431
- videoWrapper: Jo,
1432
- videoPlayBadge: ea,
1433
- fileList: ta,
1434
- fileRow: na,
1435
- fileIcon: oa,
1436
- fileName: aa,
1437
- removeBtn: sa
1438
- };
1439
- function ra(e) {
1440
- return e === "application/pdf" ? /* @__PURE__ */ n(At, {}) : /* @__PURE__ */ n(Tt, {});
1441
- }
1442
- function ia({ attachment: e, onRemove: t }) {
1443
- return /* @__PURE__ */ w("div", { role: "listitem", className: H.thumbnailItem, children: [
1444
- e.fileType === "video" ? /* @__PURE__ */ w("div", { className: H.videoWrapper, children: [
1445
- /* @__PURE__ */ n(
1446
- "video",
1447
- {
1448
- src: e.previewUrl,
1449
- className: H.thumbnail,
1450
- preload: "metadata",
1451
- muted: !0,
1452
- playsInline: !0,
1453
- "aria-label": e.file.name
1454
- }
1455
- ),
1456
- /* @__PURE__ */ n("span", { className: H.videoPlayBadge, "aria-hidden": !0, children: "▶" })
1457
- ] }) : /* @__PURE__ */ n(
1458
- "img",
1459
- {
1460
- src: e.previewUrl,
1461
- alt: e.file.name,
1462
- className: H.thumbnail
1463
- }
1464
- ),
1465
- /* @__PURE__ */ n(
1466
- "button",
1467
- {
1468
- type: "button",
1469
- className: H.removeBtn,
1470
- "aria-label": `Remove ${e.file.name}`,
1471
- onClick: () => t(e.id),
1472
- children: /* @__PURE__ */ n(St, {})
1473
- }
1474
- )
1475
- ] });
1476
- }
1477
- function ca({ attachment: e, onRemove: t }) {
1478
- return /* @__PURE__ */ w("div", { role: "listitem", className: H.fileRow, children: [
1479
- /* @__PURE__ */ n("span", { className: H.fileIcon, "aria-hidden": !0, children: ra(e.file.type) }),
1480
- /* @__PURE__ */ n("span", { className: H.fileName, children: e.file.name }),
1481
- /* @__PURE__ */ n(
1482
- "button",
1483
- {
1484
- type: "button",
1485
- className: H.removeBtn,
1486
- "aria-label": `Remove ${e.file.name}`,
1487
- onClick: () => t(e.id),
1488
- children: /* @__PURE__ */ n(St, {})
1489
- }
1490
- )
1491
- ] });
1492
- }
1493
- function la({
1494
- attachments: e,
1495
- onRemove: t
1496
- }) {
1497
- if (!e.length) return null;
1498
- const a = e.filter((s) => s.fileType !== "document"), o = e.filter((s) => s.fileType === "document");
1499
- return /* @__PURE__ */ w("div", { className: H.container, children: [
1500
- a.length > 0 && /* @__PURE__ */ n(
1501
- "div",
1502
- {
1503
- className: H.thumbnailList,
1504
- role: "list",
1505
- "aria-label": "Image and video attachments",
1506
- children: a.map((s) => /* @__PURE__ */ n(
1507
- ia,
1508
- {
1509
- attachment: s,
1510
- onRemove: t
1511
- },
1512
- s.id
1513
- ))
1514
- }
1515
- ),
1516
- o.length > 0 && /* @__PURE__ */ n(
1517
- "div",
1518
- {
1519
- className: H.fileList,
1520
- role: "list",
1521
- "aria-label": "File attachments",
1522
- children: o.map((s) => /* @__PURE__ */ n(
1523
- ca,
1524
- {
1525
- attachment: s,
1526
- onRemove: t
1527
- },
1528
- s.id
1529
- ))
1530
- }
1531
- )
1532
- ] });
1533
- }
1534
- const da = 25 * 1024 * 1024, ua = ["image/*", "video/*"], Et = [
1535
- ".pdf",
1536
- ".doc",
1537
- ".docx",
1538
- ".xls",
1539
- ".xlsx",
1540
- ".ppt",
1541
- ".pptx",
1542
- ".txt",
1543
- ".zip"
1544
- ], ma = new Set(
1545
- Et.map((e) => e.slice(1))
1546
- // strip leading '.'
1547
- ), _a = [
1548
- ...ua,
1549
- "application/pdf",
1550
- ...Et
1551
- ].join(",");
1552
- function ha(e) {
1553
- return e.type.startsWith("image/") ? "image" : e.type.startsWith("video/") ? "video" : "document";
1554
- }
1555
- function fa(e) {
1556
- if (e.type.startsWith("image/") || e.type.startsWith("video/"))
1557
- return !0;
1558
- const t = e.name.split(".").pop()?.toLowerCase() ?? "";
1559
- return !!ma.has(t);
1560
- }
1561
- function pa() {
1562
- const { controller: e } = z(), [t, a] = N([]), [o, s] = N(), i = y(null), r = y(/* @__PURE__ */ new Map());
1563
- T(() => {
1564
- const c = r.current;
1565
- return () => {
1566
- c.forEach((u) => URL.revokeObjectURL(u));
1567
- };
1568
- }, []);
1569
- const l = v(
1570
- (c) => {
1571
- const u = c.target.files?.[0];
1572
- if (!u) return;
1573
- if (c.target.value = "", !fa(u)) {
1574
- s("File type not supported.");
1575
- return;
1576
- }
1577
- if (u.size > da) {
1578
- s("File is too large. Maximum size is 25 MB.");
1579
- return;
1580
- }
1581
- s(void 0), r.current.forEach((g) => URL.revokeObjectURL(g)), r.current.clear();
1582
- const h = `${u.name}-${u.size}-${Date.now()}-${Math.random()}`, p = URL.createObjectURL(u);
1583
- r.current.set(h, p), a([{ id: h, file: u, previewUrl: p, fileType: ha(u) }]);
1584
- },
1585
- []
1586
- ), f = v((c) => {
1587
- const u = r.current.get(c);
1588
- u && (URL.revokeObjectURL(u), r.current.delete(c)), a((h) => h.filter((p) => p.id !== c));
1589
- }, []), _ = v(() => {
1590
- r.current.forEach((c) => URL.revokeObjectURL(c)), r.current.clear(), a([]);
1591
- }, []), m = v(() => {
1592
- i.current?.click();
1593
- }, []), d = v(() => {
1594
- if (t.length) {
1595
- for (const c of t) {
1596
- const u = Qe.createMedia({
1597
- file: c.file,
1598
- attachmentUrl: c.previewUrl,
1599
- metadata: { sent_by: me.User }
1600
- });
1601
- e.sendMessage(u, c.file);
1602
- }
1603
- r.current.clear(), a([]);
1604
- }
1605
- }, [t, e]);
1606
- return {
1607
- attachments: t,
1608
- hasAttachments: t.length > 0,
1609
- attachmentError: o,
1610
- fileInputRef: i,
1611
- handleFileInputChange: l,
1612
- handleRemoveAttachment: f,
1613
- clearAttachments: _,
1614
- handleOpenFilePicker: m,
1615
- sendAttachments: d,
1616
- attachmentListProps: {
1617
- attachments: t,
1618
- onRemove: f
1619
- }
1620
- };
1621
- }
1622
- const ga = "audio-waveform-module__waveform___xs7iO", It = {
1623
- waveform: ga
1624
- }, ba = 30, va = 1e3 / ba, wa = 24, rt = 2, it = 3;
1625
- function Ca({ analyserNode: e }) {
1626
- const t = y(null), a = y(void 0), o = y(0);
1627
- return T(() => {
1628
- const s = t.current;
1629
- if (!s) return;
1630
- const i = () => {
1631
- const c = window.devicePixelRatio ?? 1, u = Math.max(s.clientWidth, 60);
1632
- s.width = Math.round(u * c), s.height = wa * c;
1633
- };
1634
- i();
1635
- const r = new ResizeObserver(i);
1636
- r.observe(s);
1637
- const l = s.getContext("2d");
1638
- if (!l) return;
1639
- const f = e.frequencyBinCount, _ = new Uint8Array(f);
1640
- function m(c, u, h, p) {
1641
- const g = h / 2;
1642
- if (p <= h) {
1643
- l.beginPath(), l.arc(c + g, u + g, g, 0, Math.PI * 2), l.fill();
1644
- return;
1645
- }
1646
- l.beginPath(), l.moveTo(c + g, u), l.arcTo(c + h, u, c + h, u + g, g), l.lineTo(c + h, u + p - g), l.arcTo(c + h, u + p, c + g, u + p, g), l.lineTo(c + g, u + p), l.arcTo(c, u + p, c, u + p - g, g), l.lineTo(c, u + g), l.arcTo(c, u, c + g, u, g), l.closePath(), l.fill();
1647
- }
1648
- function d(c) {
1649
- if (c - o.current < va) {
1650
- a.current = requestAnimationFrame(d);
1651
- return;
1652
- }
1653
- o.current = c, e.getByteFrequencyData(_);
1654
- const u = window.devicePixelRatio ?? 1, h = s.width, p = s.height, g = rt * u, b = Math.max(
1655
- 1,
1656
- Math.floor(h / u / (rt + it))
1657
- ), C = it * u;
1658
- l.clearRect(0, 0, h, p), l.fillStyle = "currentColor";
1659
- const S = Math.floor(f * 0.5);
1660
- for (let M = 0; M < b; M++) {
1661
- const P = Math.floor(M / b * S), A = _[P], W = Math.max(g, A / 255 * p * 1.1), V = M * (g + C), $ = (p - W) / 2;
1662
- m(V, $, g, W);
1663
- }
1664
- a.current = requestAnimationFrame(d);
1665
- }
1666
- return a.current = requestAnimationFrame(d), () => {
1667
- a.current !== void 0 && cancelAnimationFrame(a.current), r.disconnect();
1668
- };
1669
- }, [e]), /* @__PURE__ */ n("canvas", { ref: t, className: It.waveform, "aria-hidden": !0 });
1670
- }
1671
- const ya = 24, ct = 2, lt = 3;
1672
- function Ma(e, t, a, o, s) {
1673
- const i = o / 2;
1674
- if (s <= o) {
1675
- e.beginPath(), e.arc(t + i, a + i, i, 0, Math.PI * 2), e.fill();
1676
- return;
1677
- }
1678
- e.beginPath(), e.moveTo(t + i, a), e.arcTo(t + o, a, t + o, a + i, i), e.lineTo(t + o, a + s - i), e.arcTo(t + o, a + s, t + i, a + s, i), e.lineTo(t + i, a + s), e.arcTo(t, a + s, t, a + s - i, i), e.lineTo(t, a + i), e.arcTo(t, a, t + i, a, i), e.closePath(), e.fill();
1679
- }
1680
- function Pa(e, t, a, o, s) {
1681
- const i = window.devicePixelRatio ?? 1;
1682
- e.clearRect(0, 0, t, a), e.fillStyle = "currentColor";
1683
- const r = ct * i, l = lt * i, f = Math.max(
1684
- 1,
1685
- Math.floor(t / i / (ct + lt))
1686
- ), _ = r, m = Math.round(s * f), d = new Float32Array(f);
1687
- for (let h = 0; h < f; h++)
1688
- if (o) {
1689
- const p = Math.floor(h / f * o.length), g = Math.max(
1690
- p + 1,
1691
- Math.floor((h + 1) / f * o.length)
1692
- );
1693
- let b = 0;
1694
- for (let C = p; C < g; C++) b += Math.abs(o[C]);
1695
- d[h] = b / (g - p);
1696
- } else
1697
- d[h] = 0.1 + 0.1 * Math.abs(Math.sin(h * 0.9)) + 0.07 * Math.abs(Math.sin(h * 1.7));
1698
- let c = 0;
1699
- for (let h = 0; h < f; h++)
1700
- d[h] > c && (c = d[h]);
1701
- const u = c > 0 ? a * 0.85 / c : 1;
1702
- for (let h = 0; h < f; h++) {
1703
- const p = Math.max(_, d[h] * u), g = h * (r + l), b = (a - p) / 2;
1704
- e.globalAlpha = h < m ? 1 : 0.35, Ma(e, g, b, r, p);
1705
- }
1706
- e.globalAlpha = 1;
1707
- }
1708
- function Pe(e, t, a) {
1709
- const o = window.devicePixelRatio ?? 1, s = Math.max(e.clientWidth, 60), i = Math.round(s * o), r = ya * o;
1710
- e.width !== i && (e.width = i), e.height !== r && (e.height = r);
1711
- const l = e.getContext("2d");
1712
- l && Pa(l, e.width, e.height, t, a);
1713
- }
1714
- function Na(e) {
1715
- return Math.min(1, Math.max(0, e));
1716
- }
1717
- function dt(e, t) {
1718
- const a = e.getBoundingClientRect();
1719
- return Na((t - a.left) / a.width);
1720
- }
1721
- function Rt({
1722
- audioBlob: e,
1723
- progress: t,
1724
- onSeek: a
1725
- }) {
1726
- const o = y(null), s = y(null), i = y(t), r = y(a);
1727
- i.current = t, r.current = a, T(() => {
1728
- const _ = o.current;
1729
- if (!_) return;
1730
- let m = !1;
1731
- s.current = null, Pe(_, null, i.current);
1732
- const d = new ResizeObserver(() => {
1733
- m || Pe(_, s.current, i.current);
1734
- });
1735
- d.observe(_);
1736
- const c = new AudioContext();
1737
- return e.arrayBuffer().then((u) => c.decodeAudioData(u)).then((u) => {
1738
- m || (s.current = u.getChannelData(0), Pe(_, s.current, i.current));
1739
- }).catch(() => {
1740
- }).finally(() => c.close()), () => {
1741
- m = !0, d.disconnect();
1742
- };
1743
- }, [e]), T(() => {
1744
- const _ = o.current;
1745
- _ && Pe(_, s.current, t);
1746
- }, [t]);
1747
- const l = v(
1748
- (_) => {
1749
- if (!r.current) return;
1750
- const m = o.current;
1751
- m && (_.preventDefault(), m.setPointerCapture(_.pointerId), r.current(dt(m, _.clientX)));
1752
- },
1753
- []
1754
- ), f = v(
1755
- (_) => {
1756
- if (!r.current || _.buttons === 0) return;
1757
- const m = o.current;
1758
- m && r.current(dt(m, _.clientX));
1759
- },
1760
- []
1761
- );
1762
- return /* @__PURE__ */ n(
1763
- "canvas",
1764
- {
1765
- ref: o,
1766
- className: It.waveform,
1767
- "data-seekable": !!a,
1768
- "aria-hidden": !0,
1769
- onPointerDown: a ? l : void 0,
1770
- onPointerMove: a ? f : void 0
1771
- }
1772
- );
1773
- }
1774
- function Sa() {
1775
- return /* @__PURE__ */ n(
1776
- "svg",
1777
- {
1778
- xmlns: "http://www.w3.org/2000/svg",
1779
- viewBox: "0 0 24 24",
1780
- fill: "none",
1781
- stroke: "currentColor",
1782
- strokeWidth: 2.5,
1783
- strokeLinecap: "round",
1784
- role: "img",
1785
- "aria-hidden": !0,
1786
- children: /* @__PURE__ */ n("path", { d: "M18 6L6 18M6 6l12 12" })
1787
- }
1788
- );
1789
- }
1790
- function xt() {
1791
- return /* @__PURE__ */ w(
1792
- "svg",
1793
- {
1794
- xmlns: "http://www.w3.org/2000/svg",
1795
- viewBox: "0 0 24 24",
1796
- fill: "currentColor",
1797
- role: "img",
1798
- "aria-hidden": !0,
1799
- children: [
1800
- /* @__PURE__ */ n("rect", { x: "6", y: "4", width: "4", height: "16", rx: "1" }),
1801
- /* @__PURE__ */ n("rect", { x: "14", y: "4", width: "4", height: "16", rx: "1" })
1802
- ]
1803
- }
1804
- );
1805
- }
1806
- function Je() {
1807
- return /* @__PURE__ */ n(
1808
- "svg",
1809
- {
1810
- xmlns: "http://www.w3.org/2000/svg",
1811
- viewBox: "0 0 24 24",
1812
- fill: "currentColor",
1813
- role: "img",
1814
- "aria-hidden": !0,
1815
- children: /* @__PURE__ */ n("polygon", { points: "5,3 19,12 5,21" })
1816
- }
1817
- );
1818
- }
1819
- const te = {
1820
- "recording-controls": "audio-input-module__recording-controls___Hj6Qf",
1821
- "recording-controls-enter": "audio-input-module__recording-controls-enter___0w-HZ",
1822
- "recording-controls-exit": "audio-input-module__recording-controls-exit___Bp3tQ",
1823
- "recording-side-btn": "audio-input-module__recording-side-btn___tKWQ6",
1824
- "recording-pill": "audio-input-module__recording-pill___mn3nx",
1825
- "recording-pill--recording": "audio-input-module__recording-pill--recording___piWoa",
1826
- "recording-pill--preview": "audio-input-module__recording-pill--preview___Tnk1m",
1827
- "recording-timer": "audio-input-module__recording-timer___kyV0m",
1828
- "preview-play-btn": "audio-input-module__preview-play-btn___WJatV"
1829
- };
1830
- function Ta({
1831
- showControls: e,
1832
- recordingControlsClassName: t,
1833
- frozenIsRecording: a,
1834
- frozenIsPreview: o,
1835
- analyserNode: s,
1836
- audioBlob: i,
1837
- audioProgress: r,
1838
- isPlaying: l,
1839
- isPreview: f,
1840
- handlePlayPause: _,
1841
- handleSeekPreview: m,
1842
- handleCancelRecording: d,
1843
- timerDisplay: c,
1844
- objectUrl: u,
1845
- audioRef: h,
1846
- handleAudioPlay: p,
1847
- handleAudioPause: g,
1848
- handleAudioEnded: b,
1849
- handleAudioLoadedMetadata: C,
1850
- handleAudioTimeUpdate: S
1851
- }) {
1852
- return /* @__PURE__ */ w(Ie, { children: [
1853
- e && /* @__PURE__ */ w(
1854
- "div",
1855
- {
1856
- className: I(
1857
- te["recording-controls"],
1858
- t
1859
- ),
1860
- children: [
1861
- /* @__PURE__ */ n(
1862
- "button",
1863
- {
1864
- type: "button",
1865
- className: te["recording-side-btn"],
1866
- "aria-label": f ? "Discard recording" : "Cancel recording",
1867
- onClick: d,
1868
- children: /* @__PURE__ */ n(Sa, {})
1869
- }
1870
- ),
1871
- /* @__PURE__ */ w(
1872
- "div",
1873
- {
1874
- className: I(
1875
- te["recording-pill"],
1876
- a ? te["recording-pill--recording"] : te["recording-pill--preview"]
1877
- ),
1878
- children: [
1879
- o && /* @__PURE__ */ n(
1880
- "button",
1881
- {
1882
- type: "button",
1883
- className: te["preview-play-btn"],
1884
- "aria-label": l ? "Pause" : "Play recording",
1885
- onClick: _,
1886
- children: l ? /* @__PURE__ */ n(xt, {}) : /* @__PURE__ */ n(Je, {})
1887
- }
1888
- ),
1889
- a && s ? /* @__PURE__ */ n(Ca, { analyserNode: s }) : o && i ? /* @__PURE__ */ n(
1890
- Rt,
1891
- {
1892
- audioBlob: i,
1893
- progress: r,
1894
- onSeek: m
1895
- }
1896
- ) : null,
1897
- /* @__PURE__ */ n("span", { className: te["recording-timer"], children: c })
1898
- ]
1899
- }
1900
- )
1901
- ]
1902
- }
1903
- ),
1904
- u && /* @__PURE__ */ n(
1905
- "audio",
1906
- {
1907
- ref: h,
1908
- src: u,
1909
- onPlay: p,
1910
- onPause: g,
1911
- onEnded: b,
1912
- onLoadedMetadata: C,
1913
- onTimeUpdate: S,
1914
- style: { display: "none" }
1915
- }
1916
- )
1917
- ] });
1918
- }
1919
- function Aa() {
1920
- return typeof window < "u" && typeof navigator.mediaDevices?.getUserMedia == "function" && typeof MediaRecorder < "u";
1921
- }
1922
- function Ea() {
1923
- const [e, t] = N("idle"), [a, o] = N(void 0), [s, i] = N(
1924
- void 0
1925
- ), [r, l] = N(!1), f = Aa(), _ = y(void 0), m = y(void 0), d = y(void 0), c = y([]), u = v(() => {
1926
- m.current?.getTracks().forEach((b) => b.stop()), m.current = void 0, d.current?.close(), d.current = void 0, i(void 0);
1927
- }, []), h = v(async () => {
1928
- if (!f || e !== "idle") return;
1929
- l(!1);
1930
- let b;
1931
- try {
1932
- b = await navigator.mediaDevices.getUserMedia({ audio: !0 });
1933
- } catch (A) {
1934
- A instanceof Error && A.name === "NotAllowedError" && l(!0);
1935
- return;
1936
- }
1937
- m.current = b;
1938
- const C = new AudioContext();
1939
- d.current = C;
1940
- const S = C.createMediaStreamSource(b), M = C.createAnalyser();
1941
- M.fftSize = 256, S.connect(M), i(M), c.current = [];
1942
- const P = new MediaRecorder(b);
1943
- _.current = P, P.ondataavailable = (A) => {
1944
- A.data.size > 0 && c.current.push(A.data);
1945
- }, P.start(), t("recording");
1946
- }, [f, e]), p = v(() => {
1947
- const b = _.current;
1948
- !b || e !== "recording" || (b.onstop = () => {
1949
- const C = new Blob(c.current, {
1950
- type: b.mimeType || "audio/webm"
1951
- });
1952
- o(C), t("preview");
1953
- }, b.stop(), u());
1954
- }, [e, u]), g = v(() => {
1955
- const b = _.current;
1956
- b && b.state !== "inactive" && (b.onstop = null, b.stop()), u(), c.current = [], o(void 0), t("idle");
1957
- }, [u]);
1958
- return T(() => () => {
1959
- const b = _.current;
1960
- b && b.state !== "inactive" && (b.onstop = null, b.stop()), u();
1961
- }, [u]), {
1962
- recorderState: e,
1963
- audioBlob: a,
1964
- analyserNode: s,
1965
- isSupported: f,
1966
- permissionError: r,
1967
- startRecording: h,
1968
- confirmRecording: p,
1969
- cancelRecording: g
1970
- };
1971
- }
1972
- function Ee(e) {
1973
- const t = String(Math.floor(e / 60)).padStart(2, "0"), a = String(Math.floor(e % 60)).padStart(2, "0");
1974
- return `${t}:${a}`;
1975
- }
1976
- const Ge = "audio-recording", de = "audio-preview", Ia = 120;
1977
- function Ra(e) {
1978
- return new Promise((t, a) => {
1979
- const o = new FileReader();
1980
- o.onloadend = () => t(o.result), o.onerror = a, o.readAsDataURL(e);
1981
- });
1982
- }
1983
- function xa(e) {
1984
- const [t, a] = N(e), [o, s] = N(!1), i = y();
1985
- return T(() => (e ? (clearTimeout(i.current), a(!0), s(!1)) : (s(!0), i.current = setTimeout(() => {
1986
- a(!1), s(!1);
1987
- }, Ia)), () => {
1988
- clearTimeout(i.current);
1989
- }), [e]), { showControls: t, isExiting: o };
1990
- }
1991
- function La(e, t) {
1992
- const { controller: a } = z(), { activeId: o, setActive: s, clearActive: i } = Le(), {
1993
- recorderState: r,
1994
- audioBlob: l,
1995
- analyserNode: f,
1996
- isSupported: _,
1997
- startRecording: m,
1998
- confirmRecording: d,
1999
- cancelRecording: c
2000
- } = Ea(), u = e.webchatClientSettingsBehaviors.input.isAudioRecordingVisible && _, [h, p] = N(0), g = y(
2001
- void 0
2002
- ), b = y(null), [C, S] = N(""), [M, P] = N(!1), [A, W] = N(0), [V, $] = N(0);
2003
- T(() => (r === "recording" ? (p(0), g.current = setInterval(() => {
2004
- p((R) => R + 1);
2005
- }, 1e3)) : (clearInterval(g.current), r === "idle" && (p(0), W(0), $(0), P(!1))), () => clearInterval(g.current)), [r]), T(() => {
2006
- if (!l) {
2007
- S("");
2008
- return;
2009
- }
2010
- const R = URL.createObjectURL(l);
2011
- return S(R), () => URL.revokeObjectURL(R);
2012
- }, [l]);
2013
- const q = Ee(r === "recording" ? h : M ? V : A), G = A > 0 ? V / A : 0;
2014
- T(() => {
2015
- o !== de && M && b.current?.pause();
2016
- }, [o, M]);
2017
- const B = v(() => {
2018
- P(!0), s(de);
2019
- }, [s]), K = v(() => {
2020
- P(!1), i(de);
2021
- }, [i]), ne = v(() => {
2022
- P(!1), i(de);
2023
- }, [i]), J = v(
2024
- (R) => {
2025
- W(Math.round(R.currentTarget.duration));
2026
- },
2027
- []
2028
- ), Ce = v(
2029
- (R) => {
2030
- $(Math.round(R.currentTarget.currentTime));
2031
- },
2032
- []
2033
- ), ke = v(() => {
2034
- const R = b.current;
2035
- R && (M ? R.pause() : R.play().catch(() => P(!1)));
2036
- }, [M]), De = v(() => {
2037
- u && (s(Ge), m());
2038
- }, [u, s, m]), Oe = v(() => {
2039
- i(Ge), d();
2040
- }, [i, d]), We = v(() => {
2041
- i(Ge), i(de), c();
2042
- }, [i, c]), ce = v(
2043
- (R) => {
2044
- !b.current || A === 0 || (b.current.currentTime = R * A, $(Math.round(b.current.currentTime)));
2045
- },
2046
- [A]
2047
- ), Ve = v(() => {
2048
- b.current?.pause(), i(de), l && Ra(l).then((R) => {
2049
- const je = Qe.createAudio({
2050
- attachmentContent: R,
2051
- metadata: { sent_by: me.User }
2052
- });
2053
- a.sendMessage(je);
2054
- }).catch(() => {
2055
- }).finally(() => {
2056
- c();
2057
- });
2058
- }, [l, a, c, i]), he = r !== "idle", { showControls: $e, isExiting: fe } = xa(he), pe = y(r);
2059
- he && (pe.current = r);
2060
- const He = pe.current === "recording", ae = pe.current === "preview", X = r === "preview", Fe = r === "recording", Ue = he, ze = fe ? te["recording-controls-exit"] : te["recording-controls-enter"];
2061
- return {
2062
- audioRecordingAvailable: u,
2063
- hideBaseContent: Ue,
2064
- isPreview: X,
2065
- isRecording: Fe,
2066
- handleMicrophoneClick: De,
2067
- handleConfirmRecording: Oe,
2068
- handleSendRecording: Ve,
2069
- overlayProps: {
2070
- showControls: $e,
2071
- recordingControlsClassName: ze,
2072
- frozenIsRecording: He,
2073
- frozenIsPreview: ae,
2074
- analyserNode: f,
2075
- audioBlob: l,
2076
- audioProgress: G,
2077
- isPlaying: M,
2078
- isPreview: X,
2079
- handlePlayPause: ke,
2080
- handleSeekPreview: ce,
2081
- handleCancelRecording: We,
2082
- timerDisplay: q,
2083
- objectUrl: C,
2084
- audioRef: b,
2085
- handleAudioPlay: B,
2086
- handleAudioPause: K,
2087
- handleAudioEnded: ne,
2088
- handleAudioLoadedMetadata: J,
2089
- handleAudioTimeUpdate: Ce
2090
- }
2091
- };
2092
- }
2093
- function Ba() {
2094
- return /* @__PURE__ */ n("svg", { ...re, viewBox: "0 0 448 512", children: /* @__PURE__ */ n("path", { d: "M364.2 83.8c-24.4-24.4-64-24.4-88.4 0l-184 184c-42.1 42.1-42.1 110.3 0 152.4s110.3 42.1 152.4 0l152-152c10.9-10.9 28.7-10.9 39.6 0s10.9 28.7 0 39.6l-152 152c-64 64-167.6 64-231.6 0s-64-167.6 0-231.6l184-184c46.3-46.3 121.3-46.3 167.6 0s46.3 121.3 0 167.6l-176 176c-28.6 28.6-75 28.6-103.6 0s-28.6-75 0-103.6l144-144c10.9-10.9 28.7-10.9 39.6 0s10.9 28.7 0 39.6l-144 144c-6.7 6.7-6.7 17.7 0 24.4s17.7 6.7 24.4 0l176-176c24.4-24.4 24.4-64 0-88.4z" }) });
2095
- }
2096
- function ka() {
2097
- return /* @__PURE__ */ n(
2098
- "svg",
2099
- {
2100
- xmlns: "http://www.w3.org/2000/svg",
2101
- viewBox: "0 0 24 24",
2102
- fill: "none",
2103
- stroke: "currentColor",
2104
- strokeWidth: 2.5,
2105
- strokeLinecap: "round",
2106
- strokeLinejoin: "round",
2107
- role: "img",
2108
- "aria-hidden": !0,
2109
- children: /* @__PURE__ */ n("path", { d: "M20 6L9 17l-5-5" })
2110
- }
2111
- );
2112
- }
2113
- function Da() {
2114
- return /* @__PURE__ */ n("svg", { ...re, children: /* @__PURE__ */ n("path", { d: "M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm177.6 62.1C192.8 334.5 218.8 352 256 352s63.2-17.5 78.4-33.9c9-9.7 24.2-10.4 33.9-1.4s10.4 24.2 1.4 33.9c-22 23.8-60 49.4-113.6 49.4s-91.7-25.5-113.6-49.4c-9-9.7-8.4-24.9 1.4-33.9s24.9-8.4 33.9 1.4zM144.4 208a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zm192-32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z" }) });
2115
- }
2116
- function Oa() {
2117
- return /* @__PURE__ */ n(
2118
- "svg",
2119
- {
2120
- xmlns: "http://www.w3.org/2000/svg",
2121
- viewBox: "0 0 24 24",
2122
- fill: "none",
2123
- stroke: "currentColor",
2124
- strokeWidth: 2,
2125
- strokeLinecap: "round",
2126
- strokeLinejoin: "round",
2127
- role: "img",
2128
- "aria-hidden": !0,
2129
- children: /* @__PURE__ */ n("path", { d: "M12 18.75a6 6 0 0 0 6-6v-1.5m-6 7.5a6 6 0 0 1-6-6v-1.5m6 7.5v3.75m-3.75 0h7.5M12 15.75a3 3 0 0 1-3-3V4.5a3 3 0 1 1 6 0v8.25a3 3 0 0 1-3 3Z" })
2130
- }
2131
- );
2132
- }
2133
- function ut() {
2134
- return /* @__PURE__ */ n("svg", { ...re, children: /* @__PURE__ */ n("path", { d: "M57.6 35.8C23.1 20.6-11.3 57.4 6.1 90.9l63 121.2c4.4 8.4 12.6 14.1 22 15.3L266 249.3c3.4 .4 6 3.3 6 6.7s-2.6 6.3-6 6.7L91.1 284.6c-9.4 1.2-17.6 6.9-22 15.3L6.1 421.1c-17.4 33.5 17 70.2 51.6 55.1L492.9 285.3c25.5-11.2 25.5-47.4 0-58.6L57.6 35.8z" }) });
2135
- }
2136
- const Wa = "webchat-input-module__base___TZXU7", Va = "webchat-input-module__branding___ReLzJ", E = {
2137
- default: "webchat-input-module__default___tHS5e",
2138
- base: Wa,
2139
- "input-form": "webchat-input-module__input-form___GnKc7",
2140
- "input-row": "webchat-input-module__input-row___uqTs6",
2141
- branding: Va,
2142
- "input-form--active": "webchat-input-module__input-form--active___ZioHn",
2143
- "input-field": "webchat-input-module__input-field___c4r26",
2144
- "primary-action-base": "webchat-input-module__primary-action-base___UfC2U",
2145
- "primary-action-send": "webchat-input-module__primary-action-send___3ZCtv",
2146
- "primary-action-mic": "webchat-input-module__primary-action-mic___cB0BZ",
2147
- "icon-slot": "webchat-input-module__icon-slot___VBqqX",
2148
- "icon-face": "webchat-input-module__icon-face___9gNV-",
2149
- "icon-send": "webchat-input-module__icon-send___iTZQ1",
2150
- "action-button": "webchat-input-module__action-button___QnDXK",
2151
- "icon-mic": "webchat-input-module__icon-mic___m8zbn",
2152
- "input-container": "webchat-input-module__input-container___N2B7J",
2153
- "attachment-error": "webchat-input-module__attachment-error___JuZwS",
2154
- "primary-action-confirm": "webchat-input-module__primary-action-confirm___-iVtj",
2155
- "icon-confirm": "webchat-input-module__icon-confirm___0cjMa",
2156
- "action-bar": "webchat-input-module__action-bar___gEuJH",
2157
- "content-hidden": "webchat-input-module__content-hidden___9pFoD"
2158
- };
2159
- function $a(e, t) {
2160
- const a = e.trim();
2161
- return a ? t.some((o) => {
2162
- if (o.message && a === o.message)
2163
- return !0;
2164
- if (!o.regex) return !1;
2165
- try {
2166
- return new RegExp(o.regex).test(a);
2167
- } catch {
2168
- return !1;
2169
- }
2170
- }) : !1;
2171
- }
2172
- function Ha(e, t, a) {
2173
- const { controller: o } = z(), {
2174
- placeholder: s = "Message...",
2175
- disabled: i,
2176
- variant: r = "default",
2177
- showBranding: l = !0,
2178
- "aria-label": f,
2179
- className: _,
2180
- onEmojiClick: m,
2181
- onAttachmentClick: d,
2182
- onMicrophoneClick: c,
2183
- onUserMessageSent: u,
2184
- ...h
2185
- } = e, [p, g] = N(""), b = y(""), C = t.webchatClientSettingsBehaviors.input, S = C.isTextInputEnabled && !i, M = $a(
2186
- p,
2187
- C.blockInputs
2188
- ), P = p.trim().length > 0, {
2189
- hasAttachments: A,
2190
- attachmentError: W,
2191
- fileInputRef: V,
2192
- handleFileInputChange: $,
2193
- handleOpenFilePicker: q,
2194
- sendAttachments: G,
2195
- attachmentListProps: B
2196
- } = pa(), {
2197
- audioRecordingAvailable: K,
2198
- hideBaseContent: ne,
2199
- isPreview: J,
2200
- isRecording: Ce,
2201
- handleMicrophoneClick: ke,
2202
- handleConfirmRecording: De,
2203
- handleSendRecording: Oe,
2204
- overlayProps: We
2205
- } = La(t), ce = v(() => {
2206
- if (!S || M) return;
2207
- const Z = b.current.trim();
2208
- if (Z) {
2209
- const ye = Qe.createText({
2210
- text: Z,
2211
- metadata: {
2212
- sent_by: me.User
2213
- }
2214
- });
2215
- u?.(), o.sendMessage(ye), b.current = "", g("");
2216
- }
2217
- }, [o, S, M, u]), Ve = v(
2218
- (Z) => {
2219
- Z.preventDefault(), A && G(), ce();
2220
- },
2221
- [A, G, ce]
2222
- ), he = v(
2223
- (Z) => {
2224
- const ye = Z.target.value;
2225
- b.current = ye, g(ye);
2226
- },
2227
- []
2228
- ), $e = v(
2229
- (Z) => {
2230
- Z.key === "Enter" && !Z.shiftKey && (Z.preventDefault(), ce());
2231
- },
2232
- [ce]
2233
- ), fe = P || A, pe = K ? !!i || !S || P && M : !!i || !S || !fe || P && M, He = K ? fe ? "submit" : "button" : "submit", ae = !Ce && !J && K && !fe, X = Ce, Fe = !ae && !X, Ue = ae ? E["primary-action-mic"] : X ? E["primary-action-confirm"] : E["primary-action-send"], ze = X || J ? "button" : He, nt = X ? !1 : pe, R = X ? De : J ? Oe : ae ? ke : void 0, je = ae ? "Record voice message" : X ? "Confirm recording" : "Send message", $t = v(() => {
2234
- q(), d?.();
2235
- }, [q, d]);
2236
- return {
2237
- // Input wrapper props
2238
- inputProps: {
2239
- ...h,
2240
- ref: a,
2241
- "aria-label": f || s,
2242
- "data-webchat-input": ""
2243
- },
2244
- // Form state and handlers
2245
- inputValue: p,
2246
- hasText: P,
2247
- handleSubmit: Ve,
2248
- onEmojiClick: m,
2249
- onAttachmentClick: $t,
2250
- // Attachment preview
2251
- hasAttachments: A,
2252
- attachmentError: W,
2253
- fileInputRef: V,
2254
- handleFileInputChange: $,
2255
- attachmentListProps: B,
2256
- // Input field props
2257
- fieldProps: {
2258
- value: p,
2259
- onChange: he,
2260
- onKeyDown: $e,
2261
- placeholder: s,
2262
- disabled: !S,
2263
- rows: 1
2264
- // minimum rows; CSS field-sizing: content allows growth up to --webchat-input-max-rows
2265
- },
2266
- // CSS class variants
2267
- variants: {
2268
- variant: r,
2269
- className: _
2270
- },
2271
- isInputEnabled: S,
2272
- isInputDisabled: i,
2273
- inputBehavior: C,
2274
- showBranding: l,
2275
- // Audio overlay (passed to AudioInput)
2276
- overlayProps: We,
2277
- hideBaseContent: ne,
2278
- audioRecordingAvailable: K,
2279
- // Primary action button
2280
- primaryBgClass: Ue,
2281
- primaryType: ze,
2282
- isPrimaryDisabled: nt,
2283
- primaryHandler: R,
2284
- primaryLabel: je,
2285
- // Action bar
2286
- showMic: ae,
2287
- showConfirm: X,
2288
- showSend: Fe
2289
- };
2290
- }
2291
- const Fa = F(E.base, {
2292
- variants: {
2293
- variant: {
2294
- default: E.default
2295
- }
2296
- },
2297
- defaultVariants: {
2298
- variant: "default"
2299
- }
2300
- });
2301
- function Ua(e) {
2302
- const { state: t } = z(), a = y(null), {
2303
- inputProps: o,
2304
- handleSubmit: s,
2305
- fieldProps: i,
2306
- variants: r,
2307
- showBranding: l,
2308
- onEmojiClick: f,
2309
- onAttachmentClick: _,
2310
- isInputDisabled: m,
2311
- inputBehavior: d,
2312
- overlayProps: c,
2313
- hideBaseContent: u,
2314
- audioRecordingAvailable: h,
2315
- primaryBgClass: p,
2316
- primaryType: g,
2317
- isPrimaryDisabled: b,
2318
- primaryHandler: C,
2319
- primaryLabel: S,
2320
- showMic: M,
2321
- showConfirm: P,
2322
- showSend: A,
2323
- hasAttachments: W,
2324
- attachmentError: V,
2325
- fileInputRef: $,
2326
- handleFileInputChange: q,
2327
- attachmentListProps: G
2328
- } = Ha(e, t, a), { icons: B } = e;
2329
- if (!d.isComposerVisible)
2330
- return null;
2331
- const K = l ? /* @__PURE__ */ n("p", { className: E.branding, children: "Powered by Hubtype" }) : void 0;
2332
- return /* @__PURE__ */ w(
2333
- "div",
2334
- {
2335
- ...o,
2336
- className: Fa(r),
2337
- "data-webchat-input": !0,
2338
- "data-attachments-enabled": String(d.areAttachmentsVisible),
2339
- "data-emoji-picker-enabled": String(d.isEmojiPickerVisible),
2340
- children: [
2341
- /* @__PURE__ */ n("div", { className: E["input-container"], children: /* @__PURE__ */ w(
2342
- "form",
2343
- {
2344
- onSubmit: s,
2345
- className: I(
2346
- E["input-form"],
2347
- u && E["input-form--active"]
2348
- ),
2349
- children: [
2350
- W && /* @__PURE__ */ n(la, { ...G }),
2351
- V && /* @__PURE__ */ n("p", { className: E["attachment-error"], role: "alert", children: V }),
2352
- /* @__PURE__ */ w("div", { className: E["input-row"], children: [
2353
- h && /* @__PURE__ */ n(Ta, { ...c }),
2354
- /* @__PURE__ */ n(
2355
- "textarea",
2356
- {
2357
- ...i,
2358
- className: I(
2359
- E["input-field"],
2360
- u && E["content-hidden"]
2361
- ),
2362
- inert: u ? "" : void 0
2363
- }
2364
- ),
2365
- /* @__PURE__ */ w(
2366
- "div",
2367
- {
2368
- className: I(
2369
- E["action-bar"],
2370
- u && E["content-hidden"]
2371
- ),
2372
- role: "group",
2373
- "aria-label": "Message actions",
2374
- inert: u ? "" : void 0,
2375
- children: [
2376
- d.isEmojiPickerVisible && /* @__PURE__ */ n(
2377
- "button",
2378
- {
2379
- type: "button",
2380
- className: E["action-button"],
2381
- "aria-label": "Emoji",
2382
- disabled: m,
2383
- onClick: f,
2384
- children: B?.emoji ?? /* @__PURE__ */ n(Da, {})
2385
- }
2386
- ),
2387
- d.areAttachmentsVisible && /* @__PURE__ */ n(
2388
- "button",
2389
- {
2390
- type: "button",
2391
- className: E["action-button"],
2392
- "aria-label": "Attach file",
2393
- disabled: m,
2394
- onClick: _,
2395
- children: B?.attachment ?? /* @__PURE__ */ n(Ba, {})
2396
- }
2397
- )
2398
- ]
2399
- }
2400
- ),
2401
- /* @__PURE__ */ n(
2402
- "button",
2403
- {
2404
- type: g,
2405
- className: I(E["primary-action-base"], p),
2406
- disabled: b,
2407
- "aria-label": S,
2408
- onClick: C,
2409
- children: /* @__PURE__ */ n("span", { className: E["icon-slot"], children: h ? /* @__PURE__ */ w(Ie, { children: [
2410
- /* @__PURE__ */ n(
2411
- "span",
2412
- {
2413
- "aria-hidden": !0,
2414
- className: I(E["icon-face"], E["icon-mic"]),
2415
- "data-visible": M ? "true" : "false",
2416
- children: B?.microphone ?? /* @__PURE__ */ n(Oa, {})
2417
- }
2418
- ),
2419
- /* @__PURE__ */ n(
2420
- "span",
2421
- {
2422
- "aria-hidden": !0,
2423
- className: I(
2424
- E["icon-face"],
2425
- E["icon-confirm"]
2426
- ),
2427
- "data-visible": P ? "true" : "false",
2428
- children: /* @__PURE__ */ n(ka, {})
2429
- }
2430
- ),
2431
- /* @__PURE__ */ n(
2432
- "span",
2433
- {
2434
- "aria-hidden": !0,
2435
- className: I(E["icon-face"], E["icon-send"]),
2436
- "data-visible": A ? "true" : "false",
2437
- children: B?.send ?? /* @__PURE__ */ n(ut, {})
2438
- }
2439
- )
2440
- ] }) : /* @__PURE__ */ n(
2441
- "span",
2442
- {
2443
- "aria-hidden": !0,
2444
- className: I(E["icon-face"], E["icon-send"]),
2445
- "data-visible": "true",
2446
- children: B?.send ?? /* @__PURE__ */ n(ut, {})
2447
- }
2448
- ) })
2449
- }
2450
- )
2451
- ] }),
2452
- /* @__PURE__ */ n(
2453
- "input",
2454
- {
2455
- ref: $,
2456
- type: "file",
2457
- accept: _a,
2458
- onChange: q,
2459
- style: { display: "none" },
2460
- "aria-hidden": !0,
2461
- tabIndex: -1
2462
- }
2463
- )
2464
- ]
2465
- }
2466
- ) }),
2467
- K
2468
- ]
2469
- }
2470
- );
2471
- }
2472
- function Xe(e) {
2473
- if (!e) return;
2474
- const t = e.replace(/-/g, "");
2475
- if (t.length < 16 || parseInt(t[12], 16) !== 7) return;
2476
- const o = parseInt(t.slice(0, 12), 16);
2477
- if (!(!Number.isFinite(o) || o <= 0))
2478
- return new Date(o);
2479
- }
2480
- const za = "message-bubble-module__base___WzTAP", ja = "message-bubble-module__bot___PcXmL", qa = "message-bubble-module__agent___WGfzX", Ga = "message-bubble-module__user___lFMMm", Ka = "message-bubble-module__system___e8-FD", Xa = "message-bubble-module__sending___P9nK-", Za = "message-bubble-module__error___mine7", Q = {
2481
- base: za,
2482
- bot: ja,
2483
- agent: qa,
2484
- user: Ga,
2485
- "flat-top-corner": "message-bubble-module__flat-top-corner___CLxP2",
2486
- "flat-bottom-corner": "message-bubble-module__flat-bottom-corner___DrB7C",
2487
- system: Ka,
2488
- sending: Xa,
2489
- error: Za
2490
- }, Qa = F(Q.base, {
2491
- variants: {
2492
- variant: {
2493
- user: Q.user,
2494
- bot: Q.bot,
2495
- system: Q.system,
2496
- agent: Q.agent
2497
- },
2498
- status: {
2499
- sending: Q.sending,
2500
- sent: Q.sent,
2501
- error: Q.error
2502
- },
2503
- flatTopCorner: {
2504
- true: Q["flat-top-corner"]
2505
- },
2506
- flatBottomCorner: {
2507
- true: Q["flat-bottom-corner"]
2508
- }
2509
- },
2510
- defaultVariants: { variant: "bot", status: "sent" }
2511
- }), et = O(
2512
- ({
2513
- variant: e = "bot",
2514
- status: t = "sent",
2515
- flatTopCorner: a,
2516
- flatBottomCorner: o,
2517
- children: s,
2518
- className: i
2519
- }, r) => /* @__PURE__ */ n(
2520
- "div",
2521
- {
2522
- ref: r,
2523
- className: Qa({
2524
- variant: e,
2525
- status: t,
2526
- flatTopCorner: a,
2527
- flatBottomCorner: o,
2528
- className: i
2529
- }),
2530
- "data-webchat-message-bubble": !0,
2531
- children: s
2532
- }
2533
- )
2534
- ), Ya = "typing-message-module__typingDot___cCobM", Ja = "typing-message-module__typingDots___LwFeC", Ne = {
2535
- typingDot: Ya,
2536
- typingDots: Ja
2537
- }, es = ({
2538
- isVisible: e = !1,
2539
- className: t
2540
- }) => e ? /* @__PURE__ */ n(et, { variant: "bot", className: t, children: /* @__PURE__ */ w("div", { "data-testid": "typing-indicator", className: Ne.typingDots, children: [
2541
- /* @__PURE__ */ n("span", { className: Ne.typingDot }),
2542
- /* @__PURE__ */ n("span", { className: Ne.typingDot }),
2543
- /* @__PURE__ */ n("span", { className: Ne.typingDot })
2544
- ] }) }) : null, ts = "message-avatar-module__container___-EX1c", ns = "message-avatar-module__base___RPKhe", os = "message-avatar-module__circle___M68eH", as = "message-avatar-module__square___PjaDi", ss = "message-avatar-module__image___rxwYA", rs = "message-avatar-module__svg___eMikf", is = "message-avatar-module__fallback___2Xa-W", cs = "message-avatar-module__name___L20Ht", ls = "message-avatar-module__small___gBALc", ds = "message-avatar-module__medium___WSeE1", us = "message-avatar-module__large___a-hNp", ms = "message-avatar-module__bot___2Bh0Y", _s = "message-avatar-module__agent___MemVD", D = {
2545
- container: ts,
2546
- base: ns,
2547
- circle: os,
2548
- square: as,
2549
- image: ss,
2550
- svg: rs,
2551
- fallback: is,
2552
- name: cs,
2553
- small: ls,
2554
- medium: ds,
2555
- large: us,
2556
- bot: ms,
2557
- agent: _s
2558
- }, hs = F(D.base, {
2559
- variants: {
2560
- variant: {
2561
- user: D.user,
2562
- bot: D.bot,
2563
- system: D.system,
2564
- agent: D.agent
2565
- },
2566
- size: {
2567
- small: D.small,
2568
- medium: D.medium,
2569
- large: D.large
2570
- },
2571
- shape: {
2572
- circle: D.circle,
2573
- square: D.square
2574
- }
2575
- },
2576
- defaultVariants: { variant: "bot", size: "medium", shape: "circle" }
2577
- }), tt = O(
2578
- ({
2579
- variant: e = "bot",
2580
- size: t = "medium",
2581
- shape: a = "circle",
2582
- src: o,
2583
- alt: s,
2584
- svg: i,
2585
- showName: r = !1,
2586
- name: l,
2587
- fallback: f,
2588
- className: _
2589
- }, m) => /* @__PURE__ */ w(
2590
- "div",
2591
- {
2592
- ref: m,
2593
- className: D.container,
2594
- "data-webchat-message-avatar": !0,
2595
- children: [
2596
- /* @__PURE__ */ n(
2597
- "div",
2598
- {
2599
- className: hs({
2600
- variant: e,
2601
- size: t,
2602
- shape: a,
2603
- className: _
2604
- }),
2605
- children: i ? /* @__PURE__ */ n(
2606
- "div",
2607
- {
2608
- className: D.svg,
2609
- dangerouslySetInnerHTML: { __html: i },
2610
- role: "img",
2611
- "aria-label": s || `${e} avatar`
2612
- }
2613
- ) : o ? /* @__PURE__ */ n(
2614
- "img",
2615
- {
2616
- src: o,
2617
- alt: s || `${e} avatar`,
2618
- className: D.image
2619
- }
2620
- ) : /* @__PURE__ */ n("div", { className: D.fallback, children: f || (e === "bot" ? "🤖" : e === "agent" ? "👨‍💼" : "👤") })
2621
- }
2622
- ),
2623
- r && l && /* @__PURE__ */ n("div", { className: D.name, children: l })
2624
- ]
2625
- }
2626
- )
2627
- ), fs = "message-info-module__base___yO0Cd", ps = "message-info-module__senderName___fP58-", gs = "message-info-module__timestamp___xwDsF", bs = "message-info-module__status___jPwtz", vs = "message-info-module__top___NK5CY", ws = "message-info-module__bottom___NE4Rs", Cs = "message-info-module__bot___xlQbg", ys = "message-info-module__agent___ckeYQ", Ms = "message-info-module__user___bgEi-", Ps = "message-info-module__system___MF1CS", Y = {
2628
- base: fs,
2629
- senderName: ps,
2630
- timestamp: gs,
2631
- status: bs,
2632
- top: vs,
2633
- bottom: ws,
2634
- bot: Cs,
2635
- agent: ys,
2636
- user: Ms,
2637
- system: Ps
2638
- }, Ns = F(Y.base, {
2639
- variants: {
2640
- variant: {
2641
- user: Y.user,
2642
- bot: Y.bot,
2643
- system: Y.system,
2644
- agent: Y.agent
2645
- },
2646
- position: {
2647
- top: Y.top,
2648
- bottom: Y.bottom
2649
- }
2650
- },
2651
- defaultVariants: { variant: "bot", position: "bottom" }
2652
- }), Ss = (e) => {
2653
- if (e)
2654
- return typeof e == "string" ? e : e.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
2655
- }, Lt = O(
2656
- ({
2657
- variant: e = "bot",
2658
- position: t = "bottom",
2659
- showTimestamp: a = !0,
2660
- timestamp: o,
2661
- showStatus: s = !1,
2662
- status: i,
2663
- avatarProps: r,
2664
- senderName: l,
2665
- className: f,
2666
- children: _
2667
- }, m) => {
2668
- const d = (h) => {
2669
- switch (h) {
2670
- case "sending":
2671
- return "Sending...";
2672
- case "sent":
2673
- return "Sent";
2674
- case "error":
2675
- return "Failed to send";
2676
- default:
2677
- return "";
2678
- }
2679
- }, c = Ss(o);
2680
- return a && c || s || _ || r || l ? /* @__PURE__ */ w(
2681
- "div",
2682
- {
2683
- ref: m,
2684
- className: Ns({
2685
- variant: e,
2686
- position: t,
2687
- className: f
2688
- }),
2689
- "data-webchat-message-info": !0,
2690
- children: [
2691
- r && /* @__PURE__ */ n(tt, { ...r }),
2692
- l && /* @__PURE__ */ n("span", { className: Y.senderName, children: l }),
2693
- a && c && /* @__PURE__ */ n("span", { className: Y.timestamp, children: c }),
2694
- s && i && /* @__PURE__ */ n("span", { className: Y.status, "data-status": i, children: d(i) }),
2695
- _
2696
- ]
2697
- }
2698
- ) : null;
2699
- }
2700
- ), Ts = "message-module__base___Ki7QB", As = "message-module__bot___vw-E6", Es = "message-module__agent___2wXra", Is = "message-module__user___BSpcY", Rs = "message-module__system___-jvsr", U = {
2701
- base: Ts,
2702
- "hide-footer": "message-module__hide-footer___hIyVr",
2703
- bot: As,
2704
- "is-full-width": "message-module__is-full-width___TbepW",
2705
- "has-actions": "message-module__has-actions___oKqN8",
2706
- "is-continuation": "message-module__is-continuation___0ir98",
2707
- agent: Es,
2708
- user: Is,
2709
- system: Rs
2710
- }, xs = F(U.base, {
2711
- variants: {
2712
- variant: {
2713
- user: U.user,
2714
- bot: U.bot,
2715
- system: U.system,
2716
- agent: U.agent
2717
- },
2718
- status: {
2719
- sending: U.sending,
2720
- sent: U.sent,
2721
- error: U.error
2722
- },
2723
- hideFooter: {
2724
- true: U["hide-footer"]
2725
- },
2726
- isContinuation: {
2727
- true: U["is-continuation"]
2728
- },
2729
- hasActions: {
2730
- true: U["has-actions"]
2731
- },
2732
- isFullWidth: {
2733
- true: U["is-full-width"]
2734
- }
2735
- },
2736
- defaultVariants: { variant: "bot", status: "sent" }
2737
- });
2738
- function Bt(e) {
2739
- const {
2740
- variant: t = "bot",
2741
- status: a = "sent",
2742
- showTimestamp: o = !0,
2743
- showStatus: s = !1,
2744
- timestamp: i,
2745
- avatarConfig: r,
2746
- senderName: l,
2747
- className: f,
2748
- hideFooter: _,
2749
- isContinuation: m,
2750
- hasActions: d,
2751
- isFullWidth: c,
2752
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2753
- children: u,
2754
- // Consume unknown props without forwarding them to child components
2755
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2756
- ...h
2757
- } = e;
2758
- return _e(() => {
2759
- const p = xs({
2760
- variant: t,
2761
- status: a,
2762
- className: f,
2763
- hideFooter: _,
2764
- isContinuation: m,
2765
- hasActions: d,
2766
- isFullWidth: c
2767
- }), g = {
2768
- variant: t,
2769
- showTimestamp: o,
2770
- showStatus: s,
2771
- timestamp: i,
2772
- status: a,
2773
- senderName: l
2774
- }, b = {
2775
- variant: t,
2776
- status: a,
2777
- flatTopCorner: m,
2778
- flatBottomCorner: _
2779
- };
2780
- if (!r)
2781
- return {
2782
- messageClasses: p,
2783
- bubbleProps: b,
2784
- infoProps: g,
2785
- standaloneAvatarProps: null
2786
- };
2787
- const { placement: C, avatarProps: S } = r;
2788
- switch (C) {
2789
- case "bubble":
2790
- case "info":
2791
- return {
2792
- messageClasses: p,
2793
- bubbleProps: b,
2794
- infoProps: { ...g, avatarProps: S },
2795
- standaloneAvatarProps: null
2796
- };
2797
- case "standalone":
2798
- return {
2799
- messageClasses: p,
2800
- bubbleProps: b,
2801
- infoProps: g,
2802
- standaloneAvatarProps: S
2803
- };
2804
- default:
2805
- return {
2806
- messageClasses: p,
2807
- bubbleProps: b,
2808
- infoProps: g,
2809
- standaloneAvatarProps: null
2810
- };
2811
- }
2812
- }, [
2813
- t,
2814
- a,
2815
- o,
2816
- s,
2817
- i,
2818
- r,
2819
- l,
2820
- f,
2821
- _,
2822
- m,
2823
- d,
2824
- c
2825
- ]);
2826
- }
2827
- const ie = O(
2828
- ({ botInteractionId: e, ...t }, a) => {
2829
- const { messageClasses: o, bubbleProps: s, infoProps: i, standaloneAvatarProps: r } = Bt(t);
2830
- return /* @__PURE__ */ w(
2831
- "div",
2832
- {
2833
- ref: a,
2834
- className: o,
2835
- "data-testid": `webchat-message-${t.variant || "bot"}`,
2836
- "data-interaction-id": e,
2837
- children: [
2838
- r && /* @__PURE__ */ n(tt, { ...r }),
2839
- /* @__PURE__ */ n(et, { ...s, children: t.children }),
2840
- !t.hideFooter && /* @__PURE__ */ n(Lt, { ...i })
2841
- ]
2842
- }
2843
- );
2844
- }
2845
- ), Ls = "audio-message-module__audioMessageBase___Xye8T", Bs = "audio-message-module__audioControls___bPgRS", ks = "audio-message-module__playButton___zFi0C", Ds = "audio-message-module__waveformPlaceholder___I9e-v", Os = "audio-message-module__timer___6vQtQ", ve = {
2846
- audioMessageBase: Ls,
2847
- audioControls: Bs,
2848
- playButton: ks,
2849
- waveformPlaceholder: Ds,
2850
- timer: Os
2851
- };
2852
- function Ws({
2853
- src: e,
2854
- messageId: t,
2855
- onAudioLoad: a,
2856
- onPlay: o,
2857
- onPause: s,
2858
- onEnded: i
2859
- }) {
2860
- const r = y(null), [l, f] = N(!1), [_, m] = N(), [d, c] = N(0), [u, h] = N(), p = y(!1), { activeId: g, setActive: b, clearActive: C } = Le(), { isFocusVisible: S, focusProps: M } = Ye();
2861
- T(() => {
2862
- t && g !== t && l && r.current?.pause();
2863
- }, [g, t, l]), T(() => {
2864
- if (p.current) return;
2865
- let ne = !1;
2866
- return fetch(e).then((J) => J.blob()).then((J) => {
2867
- ne || (p.current = !0, h(J));
2868
- }).catch(() => {
2869
- }), () => {
2870
- ne = !0;
2871
- };
2872
- }, [e]);
2873
- const P = v(() => {
2874
- r.current && (m(r.current.duration), a?.());
2875
- }, [a]), A = v(() => {
2876
- r.current && c(r.current.currentTime);
2877
- }, []), W = v(() => {
2878
- f(!0), t && b(t), o?.();
2879
- }, [t, o, b]), V = v(() => {
2880
- f(!1), t && C(t), s?.();
2881
- }, [t, s, C]), $ = v(() => {
2882
- f(!1), c(0), t && C(t), i?.();
2883
- }, [t, i, C]), q = v(() => {
2884
- r.current && (l ? r.current.pause() : r.current.play());
2885
- }, [l]), G = v(
2886
- (ne) => {
2887
- !r.current || _ === void 0 || (r.current.currentTime = ne * _, c(r.current.currentTime));
2888
- },
2889
- [_]
2890
- ), B = _ ? d / _ : 0, K = l ? Ee(d) : _ !== void 0 ? Ee(_) : "--:--";
2891
- return {
2892
- audioRef: r,
2893
- audioBlob: u,
2894
- isPlaying: l,
2895
- audioProgress: B,
2896
- timerLabel: K,
2897
- handlePlayPause: q,
2898
- handleSeek: G,
2899
- audioProps: {
2900
- onLoadedMetadata: P,
2901
- onTimeUpdate: A,
2902
- onPlay: W,
2903
- onPause: V,
2904
- onEnded: $
2905
- },
2906
- playButtonProps: {
2907
- ...M,
2908
- "data-focus-visible": S
2909
- }
2910
- };
2911
- }
2912
- const kt = O(
2913
- ({
2914
- src: e,
2915
- messageId: t,
2916
- alt: a = "Audio message",
2917
- onAudioLoad: o,
2918
- onPlay: s,
2919
- onPause: i,
2920
- onEnded: r,
2921
- className: l,
2922
- ...f
2923
- }, _) => {
2924
- const {
2925
- audioRef: m,
2926
- audioBlob: d,
2927
- isPlaying: c,
2928
- audioProgress: u,
2929
- timerLabel: h,
2930
- handlePlayPause: p,
2931
- handleSeek: g,
2932
- audioProps: b,
2933
- playButtonProps: C
2934
- } = Ws({
2935
- src: e,
2936
- messageId: t,
2937
- onAudioLoad: o,
2938
- onPlay: s,
2939
- onPause: i,
2940
- onEnded: r
2941
- });
2942
- return /* @__PURE__ */ w(
2943
- ie,
2944
- {
2945
- ref: _,
2946
- className: I(ve.audioMessageBase, l),
2947
- ...f,
2948
- children: [
2949
- /* @__PURE__ */ n(
2950
- "audio",
2951
- {
2952
- ref: m,
2953
- src: e,
2954
- "aria-label": a,
2955
- ...b,
2956
- preload: "metadata"
2957
- }
2958
- ),
2959
- /* @__PURE__ */ w("div", { className: ve.audioControls, children: [
2960
- /* @__PURE__ */ n(
2961
- "button",
2962
- {
2963
- type: "button",
2964
- className: ve.playButton,
2965
- onClick: p,
2966
- "aria-label": c ? "Pause audio" : "Play audio",
2967
- ...C,
2968
- children: c ? /* @__PURE__ */ n(xt, {}) : /* @__PURE__ */ n(Je, {})
2969
- }
2970
- ),
2971
- d ? /* @__PURE__ */ n(
2972
- Rt,
2973
- {
2974
- audioBlob: d,
2975
- progress: u,
2976
- onSeek: g
2977
- }
2978
- ) : /* @__PURE__ */ n("div", { className: ve.waveformPlaceholder, "aria-hidden": !0 }),
2979
- /* @__PURE__ */ n("span", { className: ve.timer, children: h })
2980
- ] })
2981
- ]
2982
- }
2983
- );
2984
- }
2985
- );
2986
- kt.displayName = "AudioMessage";
2987
- const Vs = "button-message-module__actions___3CAVo", $s = "button-message-module__floatingButton___OK9AF", mt = {
2988
- actions: Vs,
2989
- floatingButton: $s
2990
- }, Hs = O(
2991
- ({ text: e, buttons: t, buttonsPerRow: a = 1, className: o, hideFooter: s, ...i }, r) => {
2992
- const l = Math.min(a, t.length), { messageClasses: f, bubbleProps: _, infoProps: m, standaloneAvatarProps: d } = Bt({ ...i, children: null, hasActions: !0, hideFooter: s });
2993
- return /* @__PURE__ */ w(
2994
- "div",
2995
- {
2996
- ref: r,
2997
- className: I(f, o),
2998
- "data-testid": `webchat-message-${i.variant || "bot"}`,
2999
- children: [
3000
- d && /* @__PURE__ */ n(tt, { ...d }),
3001
- /* @__PURE__ */ n(et, { ..._, children: e }),
3002
- /* @__PURE__ */ n(
3003
- "div",
3004
- {
3005
- className: mt.actions,
3006
- "data-webchat-message-actions": !0,
3007
- style: { gridTemplateColumns: `repeat(${l}, 1fr)` },
3008
- children: t.map((c, u) => /* @__PURE__ */ n(
3009
- Ae,
3010
- {
3011
- text: c.text,
3012
- disabled: c.disabled,
3013
- button: c.type ? {
3014
- type: c.type,
3015
- title: c.text,
3016
- payload: c.value,
3017
- webview: c.webview
3018
- } : { text: c.text, value: c.value },
3019
- onClick: () => c.onClick?.(c.value),
3020
- variant: "secondary",
3021
- className: mt.floatingButton
3022
- },
3023
- u
3024
- ))
3025
- }
3026
- ),
3027
- !s && /* @__PURE__ */ n(Lt, { ...m })
3028
- ]
3029
- }
3030
- );
3031
- }
3032
- ), Fs = "carousel-message-module__carouselMessageBase___yV-Nd", Us = "carousel-message-module__buttonContainer___lPydV", zs = "carousel-message-module__carouselWrapper___OaVVz", js = "carousel-message-module__carouselSlider___qtpjn", qs = "carousel-message-module__carouselCard___5GhQQ", Gs = "carousel-message-module__imageContainer___-NYcV", Ks = "carousel-message-module__elementImage___TEjVf", Xs = "carousel-message-module__elementContent___fQqqZ", Zs = "carousel-message-module__elementTitle___sUPzb", Qs = "carousel-message-module__elementSubtitle___7yW9w", Ys = "carousel-message-module__arrowLayer___-lMZC", Js = "carousel-message-module__arrowButton___EkObr", er = "carousel-message-module__prevArrow___YcQdm", tr = "carousel-message-module__nextArrow___ndT0K", k = {
3033
- carouselMessageBase: Fs,
3034
- buttonContainer: Us,
3035
- carouselWrapper: zs,
3036
- carouselSlider: js,
3037
- carouselCard: qs,
3038
- imageContainer: Gs,
3039
- elementImage: Ks,
3040
- elementContent: Xs,
3041
- elementTitle: Zs,
3042
- elementSubtitle: Qs,
3043
- arrowLayer: Ys,
3044
- arrowButton: Js,
3045
- prevArrow: er,
3046
- nextArrow: tr
3047
- };
3048
- function nr() {
3049
- return /* @__PURE__ */ n(
3050
- "svg",
3051
- {
3052
- viewBox: "0 0 16 16",
3053
- fill: "currentColor",
3054
- width: "16",
3055
- height: "16",
3056
- role: "img",
3057
- "aria-hidden": !0,
3058
- children: /* @__PURE__ */ n("path", { d: "M10.354 3.646a.5.5 0 0 1 0 .708L6.707 8l3.647 3.646a.5.5 0 0 1-.708.708l-4-4a.5.5 0 0 1 0-.708l4-4a.5.5 0 0 1 .708 0z" })
3059
- }
3060
- );
3061
- }
3062
- function or() {
3063
- return /* @__PURE__ */ n(
3064
- "svg",
3065
- {
3066
- viewBox: "0 0 16 16",
3067
- fill: "currentColor",
3068
- width: "16",
3069
- height: "16",
3070
- role: "img",
3071
- "aria-hidden": !0,
3072
- children: /* @__PURE__ */ n("path", { d: "M5.646 3.646a.5.5 0 0 0 0 .708L9.293 8 5.646 11.646a.5.5 0 0 0 .708.708l4-4a.5.5 0 0 0 0-.708l-4-4a.5.5 0 0 0-.708 0z" })
3073
- }
3074
- );
3075
- }
3076
- const _t = 12;
3077
- function ar({
3078
- elements: e,
3079
- onButtonClick: t,
3080
- onElementImageLoad: a
3081
- }) {
3082
- const o = y(null), [s, i] = N(!1), [r, l] = N(e.length > 1), f = v(() => o.current?.firstElementChild?.offsetWidth ?? 200, []), _ = v(() => {
3083
- const g = o.current;
3084
- if (!g) return;
3085
- const b = 2;
3086
- i(g.scrollLeft > b), l(g.scrollLeft < g.scrollWidth - g.clientWidth - b);
3087
- }, []), m = v(() => {
3088
- const g = o.current;
3089
- if (!g) return;
3090
- const b = f();
3091
- g.scrollTo({
3092
- left: g.scrollLeft - (b + _t),
3093
- behavior: "smooth"
3094
- });
3095
- }, [f]), d = v(() => {
3096
- const g = o.current;
3097
- if (!g) return;
3098
- const b = f();
3099
- g.scrollTo({
3100
- left: g.scrollLeft + (b + _t),
3101
- behavior: "smooth"
3102
- });
3103
- }, [f]), c = v(
3104
- (g) => {
3105
- g.key === "ArrowLeft" ? (g.preventDefault(), m()) : g.key === "ArrowRight" && (g.preventDefault(), d());
3106
- },
3107
- [m, d]
3108
- ), u = v(
3109
- (g) => {
3110
- "type" in g && t?.(g);
3111
- },
3112
- [t]
3113
- ), h = v(
3114
- (g) => ({
3115
- onLoad: () => a?.(g),
3116
- onError: () => a?.(g)
3117
- }),
3118
- [a]
3119
- ), p = v(
3120
- (g) => ({
3121
- role: "listitem",
3122
- "aria-label": `Card ${g + 1} of ${e.length}`
3123
- }),
3124
- [e.length]
3125
- );
3126
- return {
3127
- containerProps: {
3128
- role: "region",
3129
- "aria-label": "Carousel",
3130
- onKeyDown: c,
3131
- tabIndex: 0
3132
- },
3133
- sliderProps: {
3134
- ref: o,
3135
- role: "list",
3136
- onScroll: _
3137
- },
3138
- cardProps: p,
3139
- imageProps: h,
3140
- prevArrowProps: {
3141
- onClick: m,
3142
- "aria-label": "Previous card",
3143
- disabled: !s
3144
- },
3145
- nextArrowProps: {
3146
- onClick: d,
3147
- "aria-label": "Next card",
3148
- disabled: !r
3149
- },
3150
- handleButtonClick: u,
3151
- variants: {
3152
- canScrollPrev: s,
3153
- canScrollNext: r
3154
- }
3155
- };
3156
- }
3157
- const Dt = O(
3158
- ({ elements: e, onButtonClick: t, onElementImageLoad: a, className: o, ...s }, i) => {
3159
- const {
3160
- containerProps: r,
3161
- sliderProps: l,
3162
- cardProps: f,
3163
- imageProps: _,
3164
- prevArrowProps: m,
3165
- nextArrowProps: d,
3166
- handleButtonClick: c,
3167
- variants: u
3168
- } = ar({ elements: e, onButtonClick: t, onElementImageLoad: a });
3169
- return /* @__PURE__ */ n(
3170
- ie,
3171
- {
3172
- ref: i,
3173
- className: I(k.carouselMessageBase, o),
3174
- isFullWidth: !0,
3175
- ...s,
3176
- children: /* @__PURE__ */ w("div", { ...r, className: k.carouselWrapper, children: [
3177
- /* @__PURE__ */ n("div", { ...l, className: k.carouselSlider, children: e.map((h, p) => /* @__PURE__ */ w(
3178
- "div",
3179
- {
3180
- ...f(p),
3181
- className: k.carouselCard,
3182
- children: [
3183
- /* @__PURE__ */ n("div", { className: k.imageContainer, children: /* @__PURE__ */ n(
3184
- "img",
3185
- {
3186
- src: h.image,
3187
- alt: h.title,
3188
- className: k.elementImage,
3189
- ..._(p)
3190
- }
3191
- ) }),
3192
- /* @__PURE__ */ w("div", { className: k.elementContent, children: [
3193
- /* @__PURE__ */ n("h3", { className: k.elementTitle, children: h.title }),
3194
- h.subtitle && /* @__PURE__ */ n("p", { className: k.elementSubtitle, children: h.subtitle })
3195
- ] }),
3196
- h.buttons.map((g, b) => /* @__PURE__ */ n(
3197
- "div",
3198
- {
3199
- className: k.buttonContainer,
3200
- children: /* @__PURE__ */ n(
3201
- Ae,
3202
- {
3203
- text: g.title,
3204
- button: g,
3205
- onClick: c,
3206
- variant: "secondary"
3207
- }
3208
- )
3209
- },
3210
- `${h.id}-btn-${b}`
3211
- ))
3212
- ]
3213
- },
3214
- h.id
3215
- )) }),
3216
- e.length > 1 && /* @__PURE__ */ w("div", { className: k.arrowLayer, children: [
3217
- u.canScrollPrev && /* @__PURE__ */ n(
3218
- "button",
3219
- {
3220
- ...m,
3221
- type: "button",
3222
- className: I(k.arrowButton, k.prevArrow),
3223
- children: /* @__PURE__ */ n(nr, {})
3224
- }
3225
- ),
3226
- u.canScrollNext && /* @__PURE__ */ n(
3227
- "button",
3228
- {
3229
- ...d,
3230
- type: "button",
3231
- className: I(k.arrowButton, k.nextArrow),
3232
- children: /* @__PURE__ */ n(or, {})
3233
- }
3234
- )
3235
- ] })
3236
- ] })
3237
- }
3238
- );
3239
- }
3240
- );
3241
- Dt.displayName = "CarouselMessage";
3242
- const sr = "document-message-module__documentMessageBase___hqh5-", rr = "document-message-module__fileRow___-dzrn", ir = "document-message-module__fileIcon___OwdXn", cr = "document-message-module__fileName___2d5yP", Se = {
3243
- documentMessageBase: sr,
3244
- fileRow: rr,
3245
- fileIcon: ir,
3246
- fileName: cr
3247
- };
3248
- function lr({
3249
- src: e,
3250
- filename: t,
3251
- onDownload: a
3252
- }) {
3253
- return {
3254
- downloadProps: {
3255
- onClick: v(() => {
3256
- const s = document.createElement("a");
3257
- s.href = e, s.download = t || "document", s.target = "_blank", s.rel = "noopener noreferrer", document.body.appendChild(s), s.click(), document.body.removeChild(s), a?.();
3258
- }, [e, t, a])
3259
- }
3260
- };
3261
- }
3262
- function dr(e) {
3263
- return e?.includes("pdf") ? /* @__PURE__ */ n(At, {}) : /* @__PURE__ */ n(Tt, {});
3264
- }
3265
- const Ot = O(
3266
- ({ src: e, filename: t, mimeType: a, onDownload: o, className: s, ...i }, r) => {
3267
- const { downloadProps: l } = lr({ src: e, filename: t, onDownload: o });
3268
- return /* @__PURE__ */ n(
3269
- ie,
3270
- {
3271
- ref: r,
3272
- className: I(Se.documentMessageBase, s),
3273
- ...i,
3274
- children: /* @__PURE__ */ w(
3275
- "button",
3276
- {
3277
- type: "button",
3278
- className: Se.fileRow,
3279
- "aria-label": `Download ${t || "document"}`,
3280
- ...l,
3281
- children: [
3282
- /* @__PURE__ */ n("span", { className: Se.fileIcon, "aria-hidden": !0, children: dr(a) }),
3283
- /* @__PURE__ */ n("span", { className: Se.fileName, children: t || "Document" })
3284
- ]
3285
- }
3286
- )
3287
- }
3288
- );
3289
- }
3290
- );
3291
- Ot.displayName = "DocumentMessage";
3292
- const ur = "image-message-module__imageMessageBase___FDwNN", mr = "image-message-module__mediaImage___xflT1", ht = {
3293
- imageMessageBase: ur,
3294
- mediaImage: mr
3295
- };
3296
- function _r({ onImageLoad: e }) {
3297
- const t = v(() => {
3298
- e?.();
3299
- }, [e]), a = v(() => {
3300
- e?.();
3301
- }, [e]);
3302
- return {
3303
- imageProps: {
3304
- onLoad: t,
3305
- onError: a
3306
- }
3307
- };
3308
- }
3309
- const Wt = O(
3310
- ({ src: e, alt: t = "Attached image", onImageLoad: a, className: o, ...s }, i) => {
3311
- const { imageProps: r } = _r({ onImageLoad: a });
3312
- return /* @__PURE__ */ n(
3313
- ie,
3314
- {
3315
- ref: i,
3316
- className: I(ht.imageMessageBase, o),
3317
- ...s,
3318
- children: /* @__PURE__ */ n(
3319
- "img",
3320
- {
3321
- src: e,
3322
- alt: t,
3323
- className: ht.mediaImage,
3324
- ...r
3325
- }
3326
- )
3327
- }
3328
- );
3329
- }
3330
- );
3331
- Wt.displayName = "ImageMessage";
3332
- const hr = "location-message-module__locationMessageBase___rY3d-", fr = "location-message-module__locationContainer___9Rukw", pr = "location-message-module__locationContent___2BRdV", gr = "location-message-module__locationIcon___rjObu", br = "location-message-module__locationInfo___NqVsR", vr = "location-message-module__locationTitle___RpUjH", wr = "location-message-module__locationCoordinates___lLfuf", Cr = "location-message-module__locationLink___Zq2I2", oe = {
3333
- locationMessageBase: hr,
3334
- locationContainer: fr,
3335
- locationContent: pr,
3336
- locationIcon: gr,
3337
- locationInfo: br,
3338
- locationTitle: vr,
3339
- locationCoordinates: wr,
3340
- locationLink: Cr
3341
- }, yr = O(
3342
- ({
3343
- latitude: e,
3344
- longitude: t,
3345
- alt: a = "Location coordinates",
3346
- onLocationLoad: o,
3347
- className: s,
3348
- ...i
3349
- }, r) => {
3350
- const l = v(() => {
3351
- o?.();
3352
- }, [o]), f = `https://www.google.com/maps?q=${e},${t}`;
3353
- return /* @__PURE__ */ n(
3354
- ie,
3355
- {
3356
- ref: r,
3357
- className: I(oe.locationMessageBase, s),
3358
- ...i,
3359
- children: /* @__PURE__ */ w("div", { className: oe.locationContainer, children: [
3360
- /* @__PURE__ */ w("div", { className: oe.locationContent, children: [
3361
- /* @__PURE__ */ n("div", { className: oe.locationIcon, children: /* @__PURE__ */ n(
3362
- "svg",
3363
- {
3364
- width: "24",
3365
- height: "24",
3366
- viewBox: "0 0 24 24",
3367
- fill: "none",
3368
- xmlns: "http://www.w3.org/2000/svg",
3369
- "aria-hidden": "true",
3370
- children: /* @__PURE__ */ n(
3371
- "path",
3372
- {
3373
- d: "M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z",
3374
- fill: "currentColor"
3375
- }
3376
- )
3377
- }
3378
- ) }),
3379
- /* @__PURE__ */ w("div", { className: oe.locationInfo, children: [
3380
- /* @__PURE__ */ n("div", { className: oe.locationTitle, children: "Location" }),
3381
- /* @__PURE__ */ w("div", { className: oe.locationCoordinates, children: [
3382
- e.toFixed(6),
3383
- ", ",
3384
- t.toFixed(6)
3385
- ] })
3386
- ] })
3387
- ] }),
3388
- /* @__PURE__ */ w(
3389
- "a",
3390
- {
3391
- href: f,
3392
- target: "_blank",
3393
- rel: "noopener noreferrer",
3394
- className: oe.locationLink,
3395
- onClick: l,
3396
- "aria-label": `Open location in Google Maps: ${e}, ${t}`,
3397
- children: [
3398
- /* @__PURE__ */ n("span", { children: "View on Map" }),
3399
- /* @__PURE__ */ n(
3400
- "svg",
3401
- {
3402
- width: "16",
3403
- height: "16",
3404
- viewBox: "0 0 24 24",
3405
- fill: "none",
3406
- xmlns: "http://www.w3.org/2000/svg",
3407
- "aria-hidden": "true",
3408
- children: /* @__PURE__ */ n(
3409
- "path",
3410
- {
3411
- d: "M7 17L17 7M17 7H7M17 7V17",
3412
- stroke: "currentColor",
3413
- strokeWidth: "2",
3414
- strokeLinecap: "round",
3415
- strokeLinejoin: "round"
3416
- }
3417
- )
3418
- }
3419
- )
3420
- ]
3421
- }
3422
- )
3423
- ] })
3424
- }
3425
- );
3426
- }
3427
- ), Mr = "text-message-module__textMessageBase___p4r-t", Pr = "text-message-module__textContent___yRb8d", ft = {
3428
- textMessageBase: Mr,
3429
- textContent: Pr
3430
- }, Nr = O(
3431
- ({ text: e, className: t, ...a }, o) => /* @__PURE__ */ n(
3432
- ie,
3433
- {
3434
- ref: o,
3435
- className: I(ft.textMessageBase, t),
3436
- ...a,
3437
- children: /* @__PURE__ */ n("div", { className: ft.textContent, children: e })
3438
- }
3439
- )
3440
- );
3441
- function Sr({
3442
- messageId: e,
3443
- onVideoLoad: t,
3444
- onPlay: a,
3445
- onPause: o,
3446
- onEnded: s
3447
- }) {
3448
- const i = y(null), [r, l] = N(!1), { activeId: f, setActive: _, clearActive: m } = Le();
3449
- T(() => {
3450
- e && f !== e && r && i.current?.pause();
3451
- }, [f, e, r]);
3452
- const d = v(() => {
3453
- t?.();
3454
- }, [t]), c = v(() => {
3455
- l(!0), e && _(e), a?.();
3456
- }, [e, a, _]), u = v(() => {
3457
- l(!1), e && m(e), o?.();
3458
- }, [e, o, m]), h = v(() => {
3459
- l(!1), e && m(e), s?.();
3460
- }, [e, s, m]), p = v(() => {
3461
- i.current?.play();
3462
- }, []);
3463
- return {
3464
- videoRef: i,
3465
- isPlaying: r,
3466
- videoProps: {
3467
- onLoadedMetadata: d,
3468
- onPlay: c,
3469
- onPause: u,
3470
- onEnded: h
3471
- },
3472
- playButtonProps: {
3473
- onClick: p
3474
- }
3475
- };
3476
- }
3477
- const Tr = "video-message-module__videoMessageBase___RX3Qk", Ar = "video-message-module__videoContainer___ctZrR", Er = "video-message-module__videoElement___dYbDh", Ir = "video-message-module__playOverlay___QrUG8", Rr = "video-message-module__playIconWrapper___z-w6D", we = {
3478
- videoMessageBase: Tr,
3479
- videoContainer: Ar,
3480
- videoElement: Er,
3481
- playOverlay: Ir,
3482
- playIconWrapper: Rr
3483
- }, Vt = O(
3484
- ({
3485
- src: e,
3486
- messageId: t,
3487
- alt: a = "Video message",
3488
- onVideoLoad: o,
3489
- onPlay: s,
3490
- onPause: i,
3491
- onEnded: r,
3492
- className: l,
3493
- ...f
3494
- }, _) => {
3495
- const { videoRef: m, isPlaying: d, videoProps: c, playButtonProps: u } = Sr({
3496
- messageId: t,
3497
- onVideoLoad: o,
3498
- onPlay: s,
3499
- onPause: i,
3500
- onEnded: r
3501
- });
3502
- return /* @__PURE__ */ n(
3503
- ie,
3504
- {
3505
- ref: _,
3506
- className: I(we.videoMessageBase, l),
3507
- ...f,
3508
- children: /* @__PURE__ */ w("div", { className: we.videoContainer, children: [
3509
- /* @__PURE__ */ n(
3510
- "video",
3511
- {
3512
- ref: m,
3513
- src: e,
3514
- "aria-label": a,
3515
- className: we.videoElement,
3516
- preload: "metadata",
3517
- controls: d,
3518
- ...c
3519
- }
3520
- ),
3521
- !d && /* @__PURE__ */ n(
3522
- "button",
3523
- {
3524
- type: "button",
3525
- className: we.playOverlay,
3526
- "aria-label": "Play video",
3527
- ...u,
3528
- children: /* @__PURE__ */ n("span", { className: we.playIconWrapper, "aria-hidden": !0, children: /* @__PURE__ */ n(Je, {}) })
3529
- }
3530
- )
3531
- ] })
3532
- }
3533
- );
3534
- }
3535
- );
3536
- Vt.displayName = "VideoMessage";
3537
- function xr({
3538
- messageActor: e,
3539
- baseProps: t = {}
3540
- }) {
3541
- const { message: a, status: o } = L(e, (l) => ({
3542
- message: l.context?.message,
3543
- status: l.context?.status
3544
- })), s = L(
3545
- e,
3546
- (l) => l.can?.({ type: "RETRY" }) ?? !1
3547
- ), i = _e(() => {
3548
- if (!a)
3549
- return {
3550
- ...t,
3551
- variant: "bot",
3552
- status: "sent",
3553
- showTimestamp: !0,
3554
- isClickable: !1
3555
- };
3556
- const l = (() => {
3557
- switch (o) {
3558
- case "unsent":
3559
- return "sending";
3560
- case "sent":
3561
- return "sent";
3562
- case "failed":
3563
- return "error";
3564
- default:
3565
- return "sent";
3566
- }
3567
- })(), f = (() => {
3568
- switch (a.sent_by) {
3569
- case me.User:
3570
- return "user";
3571
- case me.Bot:
3572
- return "bot";
3573
- case me.Agent:
3574
- return "agent";
3575
- default:
3576
- return "user";
3577
- }
3578
- })(), _ = s ? () => e.send({ type: "RETRY" }) : void 0, m = f === "bot" ? t.botAvatarConfig ?? void 0 : f === "agent" ? t.agentAvatarConfig ?? void 0 : void 0;
3579
- return {
3580
- ...t,
3581
- variant: f,
3582
- status: l,
3583
- timestamp: Xe(a.id),
3584
- showTimestamp: !0,
3585
- isClickable: s,
3586
- onPress: _,
3587
- avatarConfig: m
3588
- };
3589
- }, [a, o, s, e, t]), r = _e(
3590
- () => (l) => {
3591
- t.onUserInteraction?.(), e.send({
3592
- type: "BUTTON_CLICKED",
3593
- button: l
3594
- });
3595
- },
3596
- [t, e]
3597
- );
3598
- return {
3599
- message: a,
3600
- status: o,
3601
- canRetry: s,
3602
- messageProps: i,
3603
- handleButtonClick: r
3604
- };
3605
- }
3606
- const Lr = ({
3607
- messageActor: e,
3608
- customMessageRenderer: t,
3609
- baseProps: a = {
3610
- customMessages: {}
3611
- },
3612
- onContentLoad: o,
3613
- onImageLoadStart: s,
3614
- onImageLoadComplete: i
3615
- }) => {
3616
- const { message: r, messageProps: l, handleButtonClick: f } = xr({
3617
- messageActor: e,
3618
- baseProps: a
3619
- });
3620
- return T(() => {
3621
- if (r && r.type === "image") {
3622
- const m = `img-${r.id}-${r.data}`;
3623
- s?.(m);
3624
- }
3625
- }, [r, s]), r ? /* @__PURE__ */ n(Ie, { children: (() => {
3626
- const { id: m } = r;
3627
- if (r.isText())
3628
- return /* @__PURE__ */ n(Nr, { ...l, text: r.data.text }, m);
3629
- if (r.isAudio())
3630
- return /* @__PURE__ */ n(
3631
- kt,
3632
- {
3633
- ...l,
3634
- src: r.data.attachment_url ?? r.data.attachment_content ?? "",
3635
- messageId: m
3636
- },
3637
- m
3638
- );
3639
- if (r.isVideo())
3640
- return /* @__PURE__ */ n(
3641
- Vt,
3642
- {
3643
- ...l,
3644
- src: r.data.attachment_url ?? r.data.attachment_content ?? "",
3645
- messageId: m,
3646
- alt: "Video",
3647
- onVideoLoad: () => {
3648
- o?.();
3649
- }
3650
- },
3651
- m
3652
- );
3653
- if (r.isDocument())
3654
- return /* @__PURE__ */ n(
3655
- Ot,
3656
- {
3657
- ...l,
3658
- src: r.data.attachment_url ?? r.data.attachment_content ?? "",
3659
- mimeType: r.data.mime_type,
3660
- filename: r.data.filename
3661
- },
3662
- m
3663
- );
3664
- if (r.isLocation())
3665
- return /* @__PURE__ */ n(
3666
- yr,
3667
- {
3668
- ...l,
3669
- latitude: r.data.latitude,
3670
- longitude: r.data.longitude,
3671
- alt: "Location coordinates",
3672
- onLocationLoad: () => {
3673
- o?.();
3674
- }
3675
- },
3676
- m
3677
- );
3678
- if (r.isImage()) {
3679
- const d = r.data.attachment_url ?? r.data.attachment_content ?? "", c = `img-${m}-${d}`;
3680
- return /* @__PURE__ */ n(
3681
- Wt,
3682
- {
3683
- ...l,
3684
- src: d,
3685
- alt: "Image",
3686
- onImageLoad: () => {
3687
- o?.(), i?.(c);
3688
- }
3689
- },
3690
- m
3691
- );
3692
- }
3693
- return r.isButtonMessage() ? /* @__PURE__ */ n(
3694
- Hs,
3695
- {
3696
- ...l,
3697
- text: r.data.text,
3698
- buttons: r.data.buttons?.map(
3699
- (d) => ({
3700
- text: d.title,
3701
- value: d.payload || d.title,
3702
- type: d.type,
3703
- webview: d.webview,
3704
- disabled: !1,
3705
- onClick: () => {
3706
- f(d);
3707
- }
3708
- })
3709
- )
3710
- },
3711
- m
3712
- ) : r.isCarousel() ? /* @__PURE__ */ n(
3713
- Dt,
3714
- {
3715
- ...l,
3716
- elements: r.data.elements.map((d, c) => ({
3717
- id: `${m}-${c}`,
3718
- title: d.title,
3719
- subtitle: d.subtitle,
3720
- image: d.image,
3721
- buttons: d.buttons
3722
- })),
3723
- onButtonClick: (d) => {
3724
- f(d);
3725
- },
3726
- onElementImageLoad: () => {
3727
- o?.();
3728
- }
3729
- },
3730
- m
3731
- ) : r.isCustom() ? t ? t(r, r.data, f) : (console.warn(
3732
- `Custom message renderer not provided for message type: ${r.type}`
3733
- ), null) : (console.warn(`Unknown message type: ${r.type}`), null);
3734
- })() }) : null;
3735
- };
3736
- function Br(e) {
3737
- return _e(() => {
3738
- if (!e)
3739
- return { bot: null, agent: null };
3740
- const t = (a, o) => {
3741
- if (!a) return null;
3742
- const s = {
3743
- variant: o,
3744
- src: a.src,
3745
- alt: a.alt,
3746
- svg: a.svg,
3747
- showName: a.showName,
3748
- name: a.name
3749
- };
3750
- return {
3751
- placement: a.placement,
3752
- avatarProps: s
3753
- };
3754
- };
3755
- return {
3756
- bot: t(e.bot, "bot"),
3757
- agent: t(e.agent, "agent")
3758
- };
3759
- }, [e]);
3760
- }
3761
- function kr(e, t, a) {
3762
- const {
3763
- variant: o = "default",
3764
- hasUserInteracted: s = !1,
3765
- onScrollDepthChange: i,
3766
- onMessagesScrollAtTopChange: r,
3767
- onUserInteraction: l,
3768
- "aria-label": f,
3769
- className: _,
3770
- ...m
3771
- } = e, d = L(
3772
- t.controller.machine,
3773
- (h) => {
3774
- const p = h.context.messageActors;
3775
- return p ? Array.from(p.values()) : [];
3776
- },
3777
- (h, p) => h.length === p.length
3778
- ), c = Br(t.avatarConfig), u = L(
3779
- t.controller.machine,
3780
- (h) => h.context.isTypingOn,
3781
- (h, p) => h === p
3782
- );
3783
- return {
3784
- // Props to spread on wrapper element
3785
- messagesProps: {
3786
- ...m,
3787
- ref: a,
3788
- "aria-label": f || `Chat messages, ${d.length} messages`,
3789
- "aria-live": "polite",
3790
- "data-webchat-messages": ""
3791
- },
3792
- // Props for MessagesList component (using XState message actors)
3793
- messageListProps: {
3794
- messageActors: d,
3795
- // From XState selector
3796
- isTyping: u,
3797
- // From XState selector
3798
- hasUserInteracted: s,
3799
- customMessageRenderer: void 0,
3800
- // TODO: Add custom message renderer support
3801
- // Pre-computed avatar configs (performance optimization)
3802
- botAvatarConfig: c.bot,
3803
- agentAvatarConfig: c.agent,
3804
- onScrollDepthChange: i,
3805
- onMessagesScrollAtTopChange: r,
3806
- onUserInteraction: l
3807
- },
3808
- // CSS class variants
3809
- variants: {
3810
- variant: o,
3811
- className: _
3812
- }
3813
- };
3814
- }
3815
- const Dr = 8, Or = 1, Wr = 350, Vr = 2;
3816
- function $r({
3817
- scrollRef: e,
3818
- hasUserInteracted: t,
3819
- messageActorsLength: a,
3820
- isTyping: o,
3821
- onScrollDepthChange: s,
3822
- onMessagesScrollAtTopChange: i
3823
- }) {
3824
- const r = y(!1), l = y(!1), f = y(void 0), _ = v(() => {
3825
- if (!t) return;
3826
- const c = e.current;
3827
- if (!c) return;
3828
- const u = c.scrollTop <= Vr;
3829
- i?.(u);
3830
- }, [t, i]), m = v(() => {
3831
- const c = e.current;
3832
- if (!c) return;
3833
- const u = r.current ? c.scrollTop > Or : c.scrollTop > Dr;
3834
- r.current !== u && (r.current = u, s?.(u));
3835
- }, [s]), d = v(() => {
3836
- m(), !l.current && _();
3837
- }, [_, m]);
3838
- return jt(() => {
3839
- if (!e.current) return;
3840
- const c = e.current;
3841
- requestAnimationFrame(() => {
3842
- l.current = !0, f.current !== void 0 && window.clearTimeout(f.current), c.scrollTo({
3843
- top: c.scrollHeight,
3844
- behavior: "smooth"
3845
- }), f.current = window.setTimeout(() => {
3846
- l.current = !1, d();
3847
- }, Wr), requestAnimationFrame(d);
3848
- });
3849
- }, [a, o, d]), { handleScrollState: d };
3850
- }
3851
- const Hr = "webchat-messages-module__base___V7acY", ue = {
3852
- base: Hr,
3853
- "messages-container": "webchat-messages-module__messages-container___Ew2gS",
3854
- "scroll-fade-bottom": "webchat-messages-module__scroll-fade-bottom___WoP9u",
3855
- "typing-indicator-container": "webchat-messages-module__typing-indicator-container___v3bpq",
3856
- default: "webchat-messages-module__default___3C2qm"
3857
- }, Fr = F(ue.base, {
3858
- variants: {
3859
- variant: {
3860
- default: ue.default
3861
- }
3862
- },
3863
- defaultVariants: {
3864
- variant: "default"
3865
- }
3866
- }), Ur = 1, zr = /* @__PURE__ */ new Set([tn.Text]);
3867
- function pt(e) {
3868
- return zr.has(e.type);
3869
- }
3870
- function jr(e, t) {
3871
- return !e || !t ? !1 : Math.abs(t.getTime() - e.getTime()) <= Ur * 6e4;
3872
- }
3873
- function gt(e, t) {
3874
- return !e || !t || !pt(e) || !pt(t) || e.sent_by !== t.sent_by ? !1 : jr(
3875
- Xe(e.id),
3876
- Xe(t.id)
3877
- );
3878
- }
3879
- function qr({
3880
- messageActors: e,
3881
- isTyping: t,
3882
- hasUserInteracted: a = !1,
3883
- customMessages: o,
3884
- botAvatarConfig: s,
3885
- agentAvatarConfig: i,
3886
- scrollRef: r,
3887
- onScrollDepthChange: l,
3888
- onMessagesScrollAtTopChange: f,
3889
- onUserInteraction: _
3890
- }) {
3891
- const { handleScrollState: m } = $r({
3892
- scrollRef: r,
3893
- hasUserInteracted: a ?? !1,
3894
- messageActorsLength: e.length,
3895
- isTyping: t,
3896
- onScrollDepthChange: l,
3897
- onMessagesScrollAtTopChange: f
3898
- }), d = bt.useCallback(
3899
- (c, u, h) => {
3900
- const p = c;
3901
- if (p.type === "custom" && p.data && o) {
3902
- const g = o[p.data.name];
3903
- if (g && typeof g == "function")
3904
- return g({
3905
- ...p.data.props,
3906
- onButtonClick: h
3907
- });
3908
- }
3909
- return null;
3910
- },
3911
- [o]
3912
- );
3913
- return /* @__PURE__ */ w(
3914
- "div",
3915
- {
3916
- ref: r,
3917
- className: ue["messages-container"],
3918
- "data-testid": "webchat-messages-list",
3919
- onScroll: m,
3920
- children: [
3921
- e && e.length > 0 && e.map((c, u) => {
3922
- const h = e[u - 1]?.getSnapshot().context?.message, p = c.getSnapshot().context?.message, g = e[u + 1]?.getSnapshot().context?.message, b = gt(p, g), C = gt(h, p);
3923
- return /* @__PURE__ */ n(
3924
- Lr,
3925
- {
3926
- messageActor: c,
3927
- customMessageRenderer: d,
3928
- baseProps: {
3929
- className: ue.message,
3930
- // Pre-computed avatar configs (performance optimization)
3931
- botAvatarConfig: s,
3932
- agentAvatarConfig: i,
3933
- onUserInteraction: _,
3934
- hideFooter: b,
3935
- isContinuation: C,
3936
- botInteractionId: p?.bot_interaction_id
3937
- }
3938
- },
3939
- c.id
3940
- );
3941
- }),
3942
- t && /* @__PURE__ */ n("div", { className: ue["typing-indicator-container"], children: /* @__PURE__ */ n(es, { isVisible: t }) }),
3943
- /* @__PURE__ */ n("div", { className: ue["scroll-fade-bottom"], "aria-hidden": !0 })
3944
- ]
3945
- }
3946
- );
3947
- }
3948
- function Gr(e) {
3949
- const { state: t } = z(), a = y(null), o = y(null), { messagesProps: s, messageListProps: i, variants: r } = kr(
3950
- e,
3951
- t,
3952
- a
3953
- );
3954
- return /* @__PURE__ */ n(
3955
- "div",
3956
- {
3957
- ...s,
3958
- className: Fr(r),
3959
- "data-webchat-messages": !0,
3960
- children: /* @__PURE__ */ n(
3961
- qr,
3962
- {
3963
- ...i,
3964
- customMessages: t.customMessages,
3965
- scrollRef: o
3966
- }
3967
- )
3968
- }
3969
- );
3970
- }
3971
- function Kr({
3972
- isOpen: e,
3973
- onClose: t,
3974
- onControllerReady: a,
3975
- title: o = "Chat",
3976
- placeholder: s = "Type a message...",
3977
- showBranding: i = !0,
3978
- coverRegistry: r,
3979
- icons: l,
3980
- heroHeaderLayout: f
3981
- }) {
3982
- const { controller: _, state: m } = z(), d = y(!1), c = un({
3983
- controller: _,
3984
- isOpen: e,
3985
- layout: f,
3986
- enableResponsiveHeroHeader: m.enableResponsiveHeroHeader
3987
- }), { header: u, messages: h, onUserEngagement: p } = c;
3988
- return T(() => {
3989
- _ && !d.current && (d.current = !0, a?.(_));
3990
- }, [_, a]), T(() => {
3991
- if (!_) return;
3992
- const C = _.machine.getSnapshot().context.isOpen ?? !1;
3993
- e && !C ? _.open() : !e && C && _.close();
3994
- }, [e, _]), /* @__PURE__ */ w(Mo, { layout: "default", coverRegistry: r, children: [
3995
- /* @__PURE__ */ n(
3996
- ko,
3997
- {
3998
- title: o,
3999
- onClose: () => {
4000
- _?.close(), t?.();
4001
- },
4002
- variant: u.variant,
4003
- collapseProgress: u.collapseProgress,
4004
- hasShadow: u.hasShadow,
4005
- enableResponsiveHeroHeader: m.enableResponsiveHeroHeader,
4006
- children: /* @__PURE__ */ n(
4007
- Ut,
4008
- {
4009
- trigger: /* @__PURE__ */ n(Nt, { "aria-label": "Open menu" }),
4010
- placement: "bottom right",
4011
- children: ({ close: b }) => /* @__PURE__ */ w(zt, { children: [
4012
- /* @__PURE__ */ n(Vo, { onClose: b }),
4013
- /* @__PURE__ */ n(Oo, { onClose: b }),
4014
- /* @__PURE__ */ n(Ko, {}),
4015
- /* @__PURE__ */ n(qo, { onClose: b })
4016
- ] })
4017
- }
4018
- )
4019
- }
4020
- ),
4021
- /* @__PURE__ */ n(Gr, { variant: "default", ...h }),
4022
- /* @__PURE__ */ n(
4023
- Ua,
4024
- {
4025
- placeholder: s,
4026
- showBranding: i,
4027
- variant: "default",
4028
- icons: l,
4029
- onUserMessageSent: p
4030
- }
4031
- )
4032
- ] });
4033
- }
4034
- function Xr({
4035
- appId: e,
4036
- isOpen: t,
4037
- onClose: a,
4038
- onControllerReady: o,
4039
- title: s,
4040
- placeholder: i,
4041
- showBranding: r = !0,
4042
- customMessages: l = {},
4043
- avatarConfig: f,
4044
- coverRegistry: _,
4045
- icons: m,
4046
- heroHeaderLayout: d,
4047
- // Note: showTrigger is accepted but not implemented yet (reserved for future use)
4048
- ...c
4049
- }) {
4050
- return /* @__PURE__ */ n(
4051
- rn,
4052
- {
4053
- appId: e,
4054
- customMessages: l,
4055
- avatarConfig: f,
4056
- ...c,
4057
- children: /* @__PURE__ */ n(
4058
- Kr,
4059
- {
4060
- isOpen: t,
4061
- onClose: a,
4062
- onControllerReady: o,
4063
- title: s,
4064
- placeholder: i,
4065
- showBranding: r,
4066
- coverRegistry: _,
4067
- icons: m,
4068
- heroHeaderLayout: d
4069
- }
4070
- )
4071
- }
4072
- );
4073
- }
4074
- const ai = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4075
- __proto__: null,
4076
- WebchatApp: Xr
4077
- }, Symbol.toStringTag, { value: "Module" }));
4078
- export {
4079
- Be as A,
4080
- hn as B,
4081
- Lo as C,
4082
- cn as D,
4083
- uo as E,
4084
- wo as F,
4085
- z as G,
4086
- To as H,
4087
- un as I,
4088
- Ha as J,
4089
- kr as K,
4090
- sn as L,
4091
- Nt as M,
4092
- ai as N,
4093
- vo as O,
4094
- es as T,
4095
- Xr as W,
4096
- Ae as a,
4097
- En as b,
4098
- Mt as c,
4099
- xn as d,
4100
- Oo as e,
4101
- Vo as f,
4102
- qo as g,
4103
- Ko as h,
4104
- ie as i,
4105
- et as j,
4106
- Lr as k,
4107
- qn as l,
4108
- oo as m,
4109
- Pt as n,
4110
- Zn as o,
4111
- _o as p,
4112
- no as q,
4113
- Mo as r,
4114
- ko as s,
4115
- Ua as t,
4116
- Gr as u,
4117
- rn as v,
4118
- qe as w,
4119
- ln as x,
4120
- In as y,
4121
- po as z
4122
- };