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