@eduzz-automacoes/webchat-widget 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1435 @@
1
+ import { jsx as o, jsxs as l, Fragment as Ne } from "react/jsx-runtime";
2
+ import { forwardRef as Ie, createElement as he, useState as R, useEffect as A, useMemo as f, useRef as me, useCallback as ee, useReducer as We } from "react";
3
+ import { Container as Ge, MessageList as Ke, Composer as Je, WebchatProvider as Ze, useActiveConversation as Xe, useConversations as Ye, useUser as Qe, useConversationList as et, Block as tt, StylesheetProvider as ot } from "@botpress/webchat";
4
+ const j = {
5
+ botName: "Assistente Virtual",
6
+ subtitle: "Conectado ao bot real",
7
+ botAvatar: "",
8
+ color: "",
9
+ themeMode: "light",
10
+ variant: "solid",
11
+ headerVariant: "glass",
12
+ radius: 4,
13
+ fontFamily: "Inter",
14
+ additionalStylesheet: "",
15
+ additionalStylesheetUrl: "",
16
+ accentColor: "#2563eb",
17
+ brandColor: "#18181b",
18
+ brandTextColor: "#fafafa",
19
+ placeholder: "Escreva uma mensagem...",
20
+ fabBackgroundColor: "#2563eb",
21
+ fabIconColor: "#ffffff",
22
+ fabChatIconVariant: "messages-square",
23
+ primaryButtonBackgroundColor: "#18181b",
24
+ primaryButtonTextColor: "#fafafa",
25
+ primaryButtonHoverBackgroundColor: "#27272a",
26
+ panelBackgroundColor: "#ffffff",
27
+ panelElevatedBackgroundColor: "#ffffff",
28
+ panelSubtleBackgroundColor: "#fafafa",
29
+ panelMutedBackgroundColor: "#f4f4f5",
30
+ panelHoverBackgroundColor: "#f4f4f5",
31
+ panelSelectedBackgroundColor: "#f5f5f5",
32
+ panelBorderColor: "#e4e4e7",
33
+ panelStrongBorderColor: "#d4d4d8",
34
+ panelTextColor: "#18181b",
35
+ panelMutedTextColor: "#71717a",
36
+ panelHeaderBackgroundColor: "rgba(255, 255, 255, 0.96)",
37
+ welcomeBackground: "linear-gradient(180deg, #f4f4f5 0%, #fafafa 34%, #ffffff 34%, #ffffff 100%)",
38
+ welcomeHeroBackground: "linear-gradient(180deg, #f5f5f5 0%, #efeff1 100%)",
39
+ welcomeOnlineStatusColor: "#16a34a",
40
+ secondaryButtonBackgroundColor: "#ffffff",
41
+ secondaryButtonTextColor: "#18181b",
42
+ secondaryButtonBorderColor: "#e4e4e7",
43
+ secondaryButtonHoverBackgroundColor: "#f4f4f5",
44
+ iconButtonBackgroundColor: "#ffffff",
45
+ iconButtonIconColor: "#71717a",
46
+ iconButtonBorderColor: "#e4e4e7",
47
+ iconButtonHoverBackgroundColor: "#f4f4f5",
48
+ outgoingMessageBackgroundColor: "#ebf1fd",
49
+ outgoingMessageTextColor: "#0f2346",
50
+ incomingMessageBackgroundColor: "#f0f0f3",
51
+ incomingMessageTextColor: "#202127",
52
+ position: "bottom-right",
53
+ initiallyOpen: !0,
54
+ showWelcomeScreen: !0,
55
+ width: "380px",
56
+ height: "640px",
57
+ welcomeCoverImage: "",
58
+ welcomeCardImage: "",
59
+ welcomeCardTitle: "Suporte",
60
+ welcomeCardStatus: "Online agora!",
61
+ welcomeCardDescription: "Estamos disponíveis para esclarecer qualquer dúvida que você possa ter. Sinta-se a vontade para nos contatar a qualquer momento.",
62
+ welcomeCtaLabel: "Iniciar atendimento",
63
+ welcomeButtonDescription: "",
64
+ welcomeCloseLabel: "Fechar painel",
65
+ openFabBackgroundColor: "#2563eb",
66
+ openFabIconColor: "#ffffff"
67
+ }, Me = (e) => e === "bottom-left" || e === "top-left" ? "bottom-left" : "bottom-right", at = (e) => {
68
+ switch (Me(e)) {
69
+ case "bottom-left":
70
+ return {
71
+ bottom: "24px",
72
+ left: "24px",
73
+ "--widget-align": "flex-start",
74
+ "--panel-transform-origin": "left bottom"
75
+ };
76
+ case "bottom-right":
77
+ default:
78
+ return {
79
+ bottom: "24px",
80
+ right: "24px",
81
+ "--widget-align": "flex-end",
82
+ "--panel-transform-origin": "right bottom"
83
+ };
84
+ }
85
+ }, Se = (e, t, a) => Math.min(Math.max(e, t), a), pe = (e) => {
86
+ if (typeof e != "string") return null;
87
+ let t = e.trim();
88
+ return !t || (t.startsWith("#") && (t = t.slice(1)), t.length === 3 && (t = t.split("").map((a) => `${a}${a}`).join("")), !/^[0-9a-fA-F]{6}$/.test(t)) ? null : `#${t.toLowerCase()}`;
89
+ }, we = (e) => {
90
+ const t = pe(e);
91
+ if (!t) return null;
92
+ const a = t.slice(1);
93
+ return {
94
+ r: Number.parseInt(a.slice(0, 2), 16),
95
+ g: Number.parseInt(a.slice(2, 4), 16),
96
+ b: Number.parseInt(a.slice(4, 6), 16)
97
+ };
98
+ }, nt = ({ r: e, g: t, b: a }) => `#${[e, t, a].map(
99
+ (r) => Se(Math.round(r), 0, 255).toString(16).padStart(2, "0")
100
+ ).join("")}`, se = (e, t, a) => {
101
+ const r = we(e), s = we(t);
102
+ if (!r || !s) return null;
103
+ const n = Se(a, 0, 1);
104
+ return nt({
105
+ r: r.r * (1 - n) + s.r * n,
106
+ g: r.g * (1 - n) + s.g * n,
107
+ b: r.b * (1 - n) + s.b * n
108
+ });
109
+ }, rt = (e, t) => t < 0 ? se(e, "#000000", Math.abs(t)) : se(e, "#ffffff", t), ce = (e) => {
110
+ const t = we(e);
111
+ return t && [t.r, t.g, t.b].map((r) => {
112
+ const s = r / 255;
113
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
114
+ }).reduce(
115
+ (r, s, n) => r + s * [0.2126, 0.7152, 0.0722][n],
116
+ 0
117
+ ) > 0.42 ? "#18181b" : "#ffffff";
118
+ }, F = (e, t) => e && Object.prototype.hasOwnProperty.call(e, t) && e[t] != null && e[t] !== "", st = (e, t) => {
119
+ const a = pe(e.brandColor);
120
+ if (!a) return e;
121
+ const r = pe(e.brandTextColor) || ce(a), s = se(a, "#ffffff", 0.82) || j.secondaryButtonBorderColor, n = se(a, "#ffffff", 0.92) || j.secondaryButtonHoverBackgroundColor, c = rt(a, -0.12) || j.primaryButtonHoverBackgroundColor;
122
+ return {
123
+ ...e,
124
+ brandColor: a,
125
+ brandTextColor: r,
126
+ primaryButtonBackgroundColor: F(
127
+ t,
128
+ "primaryButtonBackgroundColor"
129
+ ) ? e.primaryButtonBackgroundColor : a,
130
+ primaryButtonTextColor: F(t, "primaryButtonTextColor") ? e.primaryButtonTextColor : r,
131
+ primaryButtonHoverBackgroundColor: F(
132
+ t,
133
+ "primaryButtonHoverBackgroundColor"
134
+ ) ? e.primaryButtonHoverBackgroundColor : c,
135
+ secondaryButtonBackgroundColor: F(
136
+ t,
137
+ "secondaryButtonBackgroundColor"
138
+ ) ? e.secondaryButtonBackgroundColor : "#ffffff",
139
+ secondaryButtonTextColor: F(t, "secondaryButtonTextColor") ? e.secondaryButtonTextColor : a,
140
+ secondaryButtonBorderColor: F(t, "secondaryButtonBorderColor") ? e.secondaryButtonBorderColor : s,
141
+ secondaryButtonHoverBackgroundColor: F(
142
+ t,
143
+ "secondaryButtonHoverBackgroundColor"
144
+ ) ? e.secondaryButtonHoverBackgroundColor : n,
145
+ iconButtonBackgroundColor: F(t, "iconButtonBackgroundColor") ? e.iconButtonBackgroundColor : "#ffffff",
146
+ iconButtonIconColor: F(t, "iconButtonIconColor") ? e.iconButtonIconColor : a,
147
+ iconButtonBorderColor: F(t, "iconButtonBorderColor") ? e.iconButtonBorderColor : s,
148
+ iconButtonHoverBackgroundColor: F(
149
+ t,
150
+ "iconButtonHoverBackgroundColor"
151
+ ) ? e.iconButtonHoverBackgroundColor : n
152
+ };
153
+ }, ct = (e) => {
154
+ const t = e.fabBackgroundColor || e.openFabBackgroundColor || j.fabBackgroundColor, a = e.fabIconColor || e.openFabIconColor || j.fabIconColor;
155
+ return {
156
+ ...e,
157
+ fabBackgroundColor: t,
158
+ fabIconColor: a,
159
+ openFabBackgroundColor: t,
160
+ openFabIconColor: a
161
+ };
162
+ }, lt = (e = {}) => ct(
163
+ st(
164
+ {
165
+ ...j,
166
+ ...e,
167
+ position: Me(e.position ?? j.position)
168
+ },
169
+ e
170
+ )
171
+ ), te = (e) => ({
172
+ ...at(e.position),
173
+ "--widget-width": e.width,
174
+ "--widget-height": e.height,
175
+ "--bpGray-1": "var(--ui-bg)",
176
+ "--bpGray-50": "var(--ui-bg-subtle)",
177
+ "--bpGray-100": "var(--ui-bg-muted)",
178
+ "--bpGray-200": "var(--ui-border)",
179
+ "--bpGray-300": "var(--ui-border-strong)",
180
+ "--bpGray-400": "var(--ui-text-muted)",
181
+ "--bpGray-500": "var(--ui-text-muted)",
182
+ "--bpGray-600": "var(--ui-text-muted)",
183
+ "--bpGray-700": "var(--ui-text)",
184
+ "--bpGray-800": "var(--ui-text)",
185
+ "--bpGray-900": "var(--ui-text)",
186
+ "--bpGray-950": "var(--ui-text)",
187
+ "--accent-color": e.accentColor,
188
+ "--accent-text-color": ce(e.accentColor),
189
+ "--header-avatar-bg": e.accentColor,
190
+ "--header-avatar-text": ce(e.accentColor),
191
+ "--primary-button-background-color": e.primaryButtonBackgroundColor,
192
+ "--primary-button-text-color": e.primaryButtonTextColor,
193
+ "--primary-button-hover-background-color": e.primaryButtonHoverBackgroundColor,
194
+ "--panel-background-color": e.panelBackgroundColor,
195
+ "--panel-elevated-background-color": e.panelElevatedBackgroundColor,
196
+ "--panel-subtle-background-color": e.panelSubtleBackgroundColor,
197
+ "--panel-muted-background-color": e.panelMutedBackgroundColor,
198
+ "--panel-hover-background-color": e.panelHoverBackgroundColor,
199
+ "--panel-selected-background-color": e.panelSelectedBackgroundColor,
200
+ "--panel-border-color": e.panelBorderColor,
201
+ "--panel-strong-border-color": e.panelStrongBorderColor,
202
+ "--panel-text-color": e.panelTextColor,
203
+ "--panel-muted-text-color": e.panelMutedTextColor,
204
+ "--panel-header-background-color": e.panelHeaderBackgroundColor,
205
+ "--welcome-background": e.welcomeBackground,
206
+ "--welcome-hero-background": e.welcomeHeroBackground,
207
+ "--welcome-online-status-color": e.welcomeOnlineStatusColor,
208
+ "--secondary-button-background-color": e.secondaryButtonBackgroundColor,
209
+ "--secondary-button-text-color": e.secondaryButtonTextColor,
210
+ "--secondary-button-border-color": e.secondaryButtonBorderColor,
211
+ "--secondary-button-hover-background-color": e.secondaryButtonHoverBackgroundColor,
212
+ "--icon-button-background-color": e.iconButtonBackgroundColor,
213
+ "--icon-button-icon-color": e.iconButtonIconColor,
214
+ "--icon-button-border-color": e.iconButtonBorderColor,
215
+ "--icon-button-hover-background-color": e.iconButtonHoverBackgroundColor,
216
+ "--outgoing-message-background-color": e.outgoingMessageBackgroundColor,
217
+ "--outgoing-message-text-color": e.outgoingMessageTextColor,
218
+ "--incoming-message-background-color": e.incomingMessageBackgroundColor,
219
+ "--incoming-message-text-color": e.incomingMessageTextColor,
220
+ "--message-bg": e.outgoingMessageBackgroundColor,
221
+ "--message-text": e.outgoingMessageTextColor,
222
+ "--message-bg-hover": e.outgoingMessageBackgroundColor,
223
+ "--send-button-bg": e.primaryButtonBackgroundColor,
224
+ "--send-button-bg-hover": e.primaryButtonHoverBackgroundColor,
225
+ "--send-button-text": e.primaryButtonTextColor,
226
+ "--button-bg": e.secondaryButtonBackgroundColor,
227
+ "--button-bg-hover": e.secondaryButtonHoverBackgroundColor,
228
+ "--button-text": e.secondaryButtonTextColor,
229
+ "--fab-background-color": e.fabBackgroundColor,
230
+ "--fab-icon-color": e.fabIconColor
231
+ }), it = (e) => ({
232
+ color: e.color || e.accentColor,
233
+ fontFamily: e.fontFamily,
234
+ radius: e.radius,
235
+ themeMode: e.themeMode,
236
+ variant: e.variant,
237
+ headerVariant: e.headerVariant,
238
+ additionalStylesheet: e.additionalStylesheet,
239
+ additionalStylesheetUrl: e.additionalStylesheetUrl
240
+ });
241
+ const dt = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), ut = (e) => e.replace(
242
+ /^([A-Z])|[\s-_]+(\w)/g,
243
+ (t, a, r) => r ? r.toUpperCase() : a.toLowerCase()
244
+ ), ve = (e) => {
245
+ const t = ut(e);
246
+ return t.charAt(0).toUpperCase() + t.slice(1);
247
+ }, Te = (...e) => e.filter((t, a, r) => !!t && t.trim() !== "" && r.indexOf(t) === a).join(" ").trim(), bt = (e) => {
248
+ for (const t in e)
249
+ if (t.startsWith("aria-") || t === "role" || t === "title")
250
+ return !0;
251
+ };
252
+ var ht = {
253
+ xmlns: "http://www.w3.org/2000/svg",
254
+ width: 24,
255
+ height: 24,
256
+ viewBox: "0 0 24 24",
257
+ fill: "none",
258
+ stroke: "currentColor",
259
+ strokeWidth: 2,
260
+ strokeLinecap: "round",
261
+ strokeLinejoin: "round"
262
+ };
263
+ const mt = Ie(
264
+ ({
265
+ color: e = "currentColor",
266
+ size: t = 24,
267
+ strokeWidth: a = 2,
268
+ absoluteStrokeWidth: r,
269
+ className: s = "",
270
+ children: n,
271
+ iconNode: c,
272
+ ...d
273
+ }, h) => he(
274
+ "svg",
275
+ {
276
+ ref: h,
277
+ ...ht,
278
+ width: t,
279
+ height: t,
280
+ stroke: e,
281
+ strokeWidth: r ? Number(a) * 24 / Number(t) : a,
282
+ className: Te("lucide", s),
283
+ ...!n && !bt(d) && { "aria-hidden": "true" },
284
+ ...d
285
+ },
286
+ [
287
+ ...c.map(([B, x]) => he(B, x)),
288
+ ...Array.isArray(n) ? n : [n]
289
+ ]
290
+ )
291
+ );
292
+ const M = (e, t) => {
293
+ const a = Ie(
294
+ ({ className: r, ...s }, n) => he(mt, {
295
+ ref: n,
296
+ iconNode: t,
297
+ className: Te(
298
+ `lucide-${dt(ve(e))}`,
299
+ `lucide-${e}`,
300
+ r
301
+ ),
302
+ ...s
303
+ })
304
+ );
305
+ return a.displayName = ve(e), a;
306
+ };
307
+ const pt = [
308
+ ["path", { d: "M5 12h14", key: "1ays0h" }],
309
+ ["path", { d: "m12 5 7 7-7 7", key: "xquz4c" }]
310
+ ], wt = M("arrow-right", pt);
311
+ const ft = [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]], gt = M("chevron-right", ft);
312
+ const yt = [
313
+ ["path", { d: "M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8", key: "5wwlr5" }],
314
+ [
315
+ "path",
316
+ {
317
+ d: "M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",
318
+ key: "r6nss1"
319
+ }
320
+ ]
321
+ ], Ct = M("house", yt);
322
+ const vt = [
323
+ [
324
+ "path",
325
+ {
326
+ d: "M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",
327
+ key: "1sd12s"
328
+ }
329
+ ],
330
+ ["path", { d: "M8 12h.01", key: "czm47f" }],
331
+ ["path", { d: "M12 12h.01", key: "1mp3jc" }],
332
+ ["path", { d: "M16 12h.01", key: "1l6xoz" }]
333
+ ], Bt = M("message-circle-more", vt);
334
+ const kt = [
335
+ [
336
+ "path",
337
+ {
338
+ d: "M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",
339
+ key: "1sd12s"
340
+ }
341
+ ]
342
+ ], xt = M("message-circle", kt);
343
+ const Nt = [
344
+ [
345
+ "path",
346
+ {
347
+ d: "M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",
348
+ key: "18887p"
349
+ }
350
+ ]
351
+ ], Ae = M("message-square", Nt);
352
+ const It = [
353
+ [
354
+ "path",
355
+ {
356
+ d: "M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z",
357
+ key: "1n2ejm"
358
+ }
359
+ ],
360
+ [
361
+ "path",
362
+ {
363
+ d: "M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1",
364
+ key: "1qfcsi"
365
+ }
366
+ ]
367
+ ], Ve = M("messages-square", It);
368
+ const Mt = [
369
+ ["path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8", key: "1357e3" }],
370
+ ["path", { d: "M3 3v5h5", key: "1xhq8a" }]
371
+ ], St = M("rotate-ccw", Mt);
372
+ const Tt = [
373
+ ["path", { d: "M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7", key: "1m0v6g" }],
374
+ [
375
+ "path",
376
+ {
377
+ d: "M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",
378
+ key: "ohrbg2"
379
+ }
380
+ ]
381
+ ], At = M("square-pen", Tt);
382
+ const Vt = [
383
+ [
384
+ "path",
385
+ {
386
+ d: "M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z",
387
+ key: "m61m77"
388
+ }
389
+ ],
390
+ ["path", { d: "M17 14V2", key: "8ymqnk" }]
391
+ ], Ut = M("thumbs-down", Vt);
392
+ const Ft = [
393
+ [
394
+ "path",
395
+ {
396
+ d: "M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",
397
+ key: "emmmcr"
398
+ }
399
+ ],
400
+ ["path", { d: "M7 10v12", key: "1qc93n" }]
401
+ ], Pt = M("thumbs-up", Ft);
402
+ const Ht = [
403
+ ["circle", { cx: "12", cy: "8", r: "5", key: "1hypcn" }],
404
+ ["path", { d: "M20 21a8 8 0 0 0-16 0", key: "rfgkzh" }]
405
+ ], Rt = M("user-round", Ht);
406
+ const $t = [
407
+ ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
408
+ ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
409
+ ], Ue = M("x", $t), v = { "aria-hidden": !0, strokeWidth: 1.9 }, _t = /* @__PURE__ */ o(St, { ...v }), le = /* @__PURE__ */ o(Ue, { ...v }), Lt = /* @__PURE__ */ o(Ue, { ...v }), Be = {
410
+ "message-circle-more": /* @__PURE__ */ o(Bt, { ...v }),
411
+ "message-circle": /* @__PURE__ */ o(xt, { ...v }),
412
+ "message-square": /* @__PURE__ */ o(Ae, { ...v }),
413
+ "messages-square": /* @__PURE__ */ o(Ve, { ...v })
414
+ }, zt = (e = "messages-square") => Be[e] || Be["messages-square"], Dt = /* @__PURE__ */ o(wt, { ...v }), Fe = /* @__PURE__ */ o(Ct, { ...v }), qt = /* @__PURE__ */ o(Ae, { ...v }), Ot = /* @__PURE__ */ o(Pt, { ...v }), jt = /* @__PURE__ */ o(Ut, { ...v }), Et = /* @__PURE__ */ o(Ve, { ...v }), Wt = /* @__PURE__ */ o(gt, { ...v }), Gt = /* @__PURE__ */ o(At, { ...v }), Kt = /* @__PURE__ */ o(Rt, { ...v }), re = (e) => String(e).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;"), Jt = ({ name: e, backgroundColor: t }) => {
415
+ const a = (e || "B").trim().charAt(0).toUpperCase() || "B", r = ce(t), s = `
416
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" role="img" aria-label="${re(e || "Bot")}">
417
+ <rect width="96" height="96" rx="48" fill="${re(t)}" />
418
+ <text x="50%" y="52%" dominant-baseline="middle" text-anchor="middle" font-family="Arial, Helvetica, sans-serif" font-size="42" font-weight="700" fill="${re(r)}">${re(a)}</text>
419
+ </svg>
420
+ `.trim();
421
+ return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(s)}`;
422
+ }, Zt = (e) => e ? e.payload?.type === "text" ? e.payload.text : e.payload?.type === "bloc" && e.payload.items?.some((t) => t.type === "text") ? e.payload.items.find((a) => a.type === "text")?.payload.text ?? "Conversa sem mensagens" : "Anexo enviado" : "Conversa sem mensagens", ke = [
423
+ { unit: "minute", seconds: 60 },
424
+ { unit: "hour", seconds: 3600 },
425
+ { unit: "day", seconds: 3600 * 24 },
426
+ { unit: "week", seconds: 3600 * 24 * 7 },
427
+ { unit: "month", seconds: 3600 * 24 * 30 },
428
+ { unit: "year", seconds: 3600 * 24 * 365 }
429
+ ], Xt = new Intl.RelativeTimeFormat("pt-BR", { numeric: "auto" }), Yt = (e) => {
430
+ const t = Math.round((new Date(e).getTime() - Date.now()) / 1e3);
431
+ if (Math.abs(t) < 45) return "agora";
432
+ let a = ke[0];
433
+ for (const r of ke)
434
+ Math.abs(t) >= r.seconds && (a = r);
435
+ return Xt.format(Math.round(t / a.seconds), a.unit);
436
+ }, Qt = ({ messages: e, user: t, botName: a, botAvatar: r }) => e.map((s) => {
437
+ const n = s.authorId === t?.userId;
438
+ return {
439
+ ...s,
440
+ direction: n ? "outgoing" : "incoming",
441
+ sender: n ? { name: t?.name ?? "Você", avatar: t?.pictureUrl } : { name: a, avatar: r }
442
+ };
443
+ }), eo = ({ activeView: e, clientState: t, conversationId: a, messagesLength: r }) => {
444
+ const [s, n] = R(!1), c = e === "chat", d = c && t === "connecting", h = c && t === "connected" && r === 0, B = s && (!c || r > 0 || t !== "connecting" && t !== "connected");
445
+ return A(() => {
446
+ if (s) {
447
+ if (h) {
448
+ const x = window.setTimeout(() => n(!1), 900);
449
+ return () => window.clearTimeout(x);
450
+ }
451
+ if (B) {
452
+ const x = window.setTimeout(() => n(!1), 0);
453
+ return () => window.clearTimeout(x);
454
+ }
455
+ }
456
+ }, [a, s, h, B]), {
457
+ showInitialLoading: d || s && c,
458
+ setShowInitialLoading: n
459
+ };
460
+ };
461
+ function to({
462
+ botName: e,
463
+ botAvatar: t,
464
+ subtitle: a,
465
+ onShowHome: r,
466
+ onOpenHistory: s,
467
+ onRestartConversation: n,
468
+ onCloseWidget: c
469
+ }) {
470
+ return /* @__PURE__ */ l("div", { className: "bp-webchat-header", children: [
471
+ /* @__PURE__ */ l("div", { className: "bp-webchat-header-meta", children: [
472
+ /* @__PURE__ */ o("div", { className: "bp-webchat-avatar", children: t ? /* @__PURE__ */ o("img", { src: t, alt: "" }) : /* @__PURE__ */ o("span", { children: (e || "B").slice(0, 1).toUpperCase() }) }),
473
+ /* @__PURE__ */ l("div", { className: "bp-webchat-header-text", children: [
474
+ /* @__PURE__ */ o("h2", { className: "bp-webchat-header-title", children: e }),
475
+ /* @__PURE__ */ o("p", { className: "bp-webchat-header-subtitle", children: a })
476
+ ] })
477
+ ] }),
478
+ /* @__PURE__ */ l("div", { className: "bp-webchat-header-actions", children: [
479
+ r ? /* @__PURE__ */ o(
480
+ "button",
481
+ {
482
+ className: "bp-webchat-icon-button",
483
+ type: "button",
484
+ "aria-label": "Abrir início",
485
+ onClick: r,
486
+ children: Fe
487
+ }
488
+ ) : null,
489
+ /* @__PURE__ */ o(
490
+ "button",
491
+ {
492
+ className: "bp-webchat-icon-button",
493
+ type: "button",
494
+ "aria-label": "Abrir conversas",
495
+ onClick: s,
496
+ children: Et
497
+ }
498
+ ),
499
+ /* @__PURE__ */ o(
500
+ "button",
501
+ {
502
+ className: "bp-webchat-icon-button",
503
+ type: "button",
504
+ "aria-label": "Reiniciar conversa",
505
+ onClick: n,
506
+ children: _t
507
+ }
508
+ ),
509
+ c ? /* @__PURE__ */ o(
510
+ "button",
511
+ {
512
+ className: "bp-webchat-icon-button bp-webchat-mobile-close",
513
+ type: "button",
514
+ "aria-label": "Fechar webchat",
515
+ onClick: c,
516
+ children: le
517
+ }
518
+ ) : null
519
+ ] })
520
+ ] });
521
+ }
522
+ function Pe() {
523
+ return /* @__PURE__ */ l("div", { className: "bp-webchat-loading", children: [
524
+ /* @__PURE__ */ l("div", { className: "bp-webchat-loading-hero", children: [
525
+ /* @__PURE__ */ o("div", { className: "bp-webchat-loading-circle" }),
526
+ /* @__PURE__ */ o("div", { className: "bp-webchat-loading-line bp-webchat-loading-line--title" }),
527
+ /* @__PURE__ */ o("div", { className: "bp-webchat-loading-line bp-webchat-loading-line--subtitle" })
528
+ ] }),
529
+ /* @__PURE__ */ l("div", { className: "bp-webchat-loading-bubble", children: [
530
+ /* @__PURE__ */ o("div", { className: "bp-webchat-loading-line", style: { width: "82%", height: "12px" } }),
531
+ /* @__PURE__ */ o("div", { className: "bp-webchat-loading-line", style: { width: "58%", height: "12px" } })
532
+ ] }),
533
+ /* @__PURE__ */ o("div", { className: "bp-webchat-loading-bubble bp-webchat-loading-bubble--right", children: /* @__PURE__ */ o("div", { className: "bp-webchat-loading-line", style: { width: "72%", height: "12px" } }) }),
534
+ /* @__PURE__ */ l("div", { className: "bp-webchat-loading-composer", children: [
535
+ /* @__PURE__ */ o("div", { className: "bp-webchat-loading-input" }),
536
+ /* @__PURE__ */ o("div", { className: "bp-webchat-loading-mic" })
537
+ ] })
538
+ ] });
539
+ }
540
+ function oo({
541
+ config: e,
542
+ allowFileUpload: t,
543
+ clientState: a,
544
+ isTyping: r,
545
+ messages: s,
546
+ renderers: n,
547
+ sendMessage: c,
548
+ uploadFile: d,
549
+ addMessageFeedback: h,
550
+ showInitialLoading: B,
551
+ onShowHome: x,
552
+ onOpenHistory: p,
553
+ onRestartConversation: I,
554
+ onCloseWidget: N
555
+ }) {
556
+ return /* @__PURE__ */ l("div", { className: "bp-webchat-layout", children: [
557
+ /* @__PURE__ */ o(
558
+ to,
559
+ {
560
+ botName: e.botName,
561
+ botAvatar: e.botAvatar,
562
+ subtitle: e.subtitle,
563
+ onShowHome: x,
564
+ onOpenHistory: p,
565
+ onRestartConversation: I,
566
+ onCloseWidget: N
567
+ }
568
+ ),
569
+ /* @__PURE__ */ o(
570
+ Ge,
571
+ {
572
+ className: "bp-webchat-container",
573
+ uploadFile: d,
574
+ allowFileUpload: t,
575
+ children: B ? /* @__PURE__ */ o(Pe, {}) : /* @__PURE__ */ l(Ne, { children: [
576
+ /* @__PURE__ */ o(
577
+ Ke,
578
+ {
579
+ botName: e.botName,
580
+ botDescription: e.subtitle,
581
+ botAvatar: e.botAvatar,
582
+ isTyping: r,
583
+ messages: s,
584
+ sendMessage: c,
585
+ addMessageFeedback: h,
586
+ renderers: n,
587
+ showDateSystemMessage: !1,
588
+ showMessageStatus: !1,
589
+ showIncomingMessageAvatar: !0,
590
+ showOutgoingMessageAvatar: !1
591
+ }
592
+ ),
593
+ /* @__PURE__ */ o(
594
+ Je,
595
+ {
596
+ connected: a !== "disconnected",
597
+ sendMessage: c,
598
+ uploadFile: d,
599
+ allowFileUpload: t,
600
+ composerPlaceholder: e.placeholder,
601
+ disableSendButton: !1
602
+ }
603
+ )
604
+ ] })
605
+ }
606
+ )
607
+ ] });
608
+ }
609
+ function He({ activeView: e, onShowHome: t, onShowConversations: a }) {
610
+ return /* @__PURE__ */ l("div", { className: "bp-webchat-tabs bp-webchat-welcome-bottom", children: [
611
+ /* @__PURE__ */ l(
612
+ "button",
613
+ {
614
+ className: "bp-webchat-tab bp-webchat-welcome-tab",
615
+ "data-active": e === "home",
616
+ type: "button",
617
+ onClick: t,
618
+ children: [
619
+ /* @__PURE__ */ o("span", { className: "bp-webchat-tab-icon bp-webchat-welcome-tab-icon", children: Fe }),
620
+ /* @__PURE__ */ o("span", { children: "Início" })
621
+ ]
622
+ }
623
+ ),
624
+ /* @__PURE__ */ l(
625
+ "button",
626
+ {
627
+ className: "bp-webchat-tab bp-webchat-welcome-tab",
628
+ "data-active": e === "conversations",
629
+ type: "button",
630
+ onClick: a,
631
+ children: [
632
+ /* @__PURE__ */ o("span", { className: "bp-webchat-tab-icon bp-webchat-welcome-tab-icon", children: qt }),
633
+ /* @__PURE__ */ o("span", { children: "Conversas" })
634
+ ]
635
+ }
636
+ )
637
+ ] });
638
+ }
639
+ function ao({
640
+ conversations: e,
641
+ currentConversationId: t,
642
+ isLoading: a,
643
+ botAvatar: r,
644
+ botName: s,
645
+ onClose: n,
646
+ onCloseWidget: c,
647
+ onShowHome: d,
648
+ onShowConversations: h,
649
+ onNewConversation: B,
650
+ onConversationClick: x
651
+ }) {
652
+ return /* @__PURE__ */ l("div", { className: "bp-webchat-history", children: [
653
+ /* @__PURE__ */ l("div", { className: "bp-webchat-history-header", children: [
654
+ /* @__PURE__ */ o("h2", { className: "bp-webchat-history-title", children: "Conversas" }),
655
+ /* @__PURE__ */ l("div", { className: "bp-webchat-header-actions", children: [
656
+ /* @__PURE__ */ o(
657
+ "button",
658
+ {
659
+ className: "bp-webchat-icon-button",
660
+ type: "button",
661
+ onClick: n,
662
+ "aria-label": "Fechar conversas",
663
+ children: le
664
+ }
665
+ ),
666
+ c ? /* @__PURE__ */ o(
667
+ "button",
668
+ {
669
+ className: "bp-webchat-icon-button bp-webchat-mobile-close",
670
+ type: "button",
671
+ onClick: c,
672
+ "aria-label": "Fechar webchat",
673
+ children: le
674
+ }
675
+ ) : null
676
+ ] })
677
+ ] }),
678
+ /* @__PURE__ */ o("div", { className: "bp-webchat-history-list", children: a ? /* @__PURE__ */ o("div", { className: "bp-webchat-history-loading", children: "Carregando conversas..." }) : e.length === 0 ? /* @__PURE__ */ o("div", { className: "bp-webchat-history-empty", children: "Nenhuma conversa iniciada ainda." }) : e.map((p) => {
679
+ const I = Zt(p.lastMessage), N = p.lastMessage?.author?.type === "bot";
680
+ return /* @__PURE__ */ l(
681
+ "button",
682
+ {
683
+ className: "bp-webchat-history-item",
684
+ type: "button",
685
+ onClick: () => x(p.id),
686
+ "data-current": p.id === t || void 0,
687
+ children: [
688
+ /* @__PURE__ */ o("div", { className: "bp-webchat-history-avatar", "data-kind": N ? "bot" : "user", children: N && r ? /* @__PURE__ */ o("img", { src: r, alt: "" }) : N ? /* @__PURE__ */ o("span", { children: (s || "B").slice(0, 1).toUpperCase() }) : Kt }),
689
+ /* @__PURE__ */ l("div", { className: "bp-webchat-history-content", children: [
690
+ /* @__PURE__ */ o("span", { className: "bp-webchat-history-name", children: I }),
691
+ /* @__PURE__ */ o("span", { className: "bp-webchat-history-time", children: Yt(p.updatedAt) })
692
+ ] }),
693
+ /* @__PURE__ */ o("span", { className: "bp-webchat-history-chevron", children: Wt })
694
+ ]
695
+ },
696
+ p.id
697
+ );
698
+ }) }),
699
+ /* @__PURE__ */ o("div", { className: "bp-webchat-history-footer", children: /* @__PURE__ */ l("button", { className: "bp-webchat-history-new", type: "button", onClick: B, children: [
700
+ Gt,
701
+ /* @__PURE__ */ o("span", { children: "Nova conversa" })
702
+ ] }) }),
703
+ /* @__PURE__ */ o(
704
+ He,
705
+ {
706
+ activeView: "conversations",
707
+ onShowHome: d,
708
+ onShowConversations: h
709
+ }
710
+ )
711
+ ] });
712
+ }
713
+ function no({ open: e, draft: t, setDraft: a, onConfirm: r, onCancel: s }) {
714
+ return e ? /* @__PURE__ */ o("div", { className: "bp-webchat-modal-backdrop", children: /* @__PURE__ */ l("div", { className: "bp-webchat-modal", children: [
715
+ /* @__PURE__ */ o("h3", { className: "bp-webchat-modal-title", children: "Nos ajude a melhorar" }),
716
+ /* @__PURE__ */ o("p", { className: "bp-webchat-modal-description", children: "Conte o que não ficou bom nesta resposta." }),
717
+ /* @__PURE__ */ o("div", { className: "bp-webchat-modal-field-wrap", children: /* @__PURE__ */ o(
718
+ "textarea",
719
+ {
720
+ className: "bp-webchat-modal-textarea",
721
+ value: t,
722
+ onChange: (n) => a(n.target.value),
723
+ placeholder: "Descreva o problema encontrado..."
724
+ }
725
+ ) }),
726
+ /* @__PURE__ */ l("div", { className: "bp-webchat-modal-actions", children: [
727
+ /* @__PURE__ */ o(
728
+ "button",
729
+ {
730
+ className: "bp-webchat-modal-button bp-webchat-modal-button--primary",
731
+ type: "button",
732
+ onClick: r,
733
+ children: "Enviar feedback"
734
+ }
735
+ ),
736
+ /* @__PURE__ */ o("button", { className: "bp-webchat-modal-button", type: "button", onClick: s, children: "Cancelar" })
737
+ ] })
738
+ ] }) }) : null;
739
+ }
740
+ function ro({ open: e, onConfirm: t, onCancel: a }) {
741
+ return e ? /* @__PURE__ */ o("div", { className: "bp-webchat-modal-backdrop", children: /* @__PURE__ */ l("div", { className: "bp-webchat-modal", children: [
742
+ /* @__PURE__ */ o("h3", { className: "bp-webchat-modal-title", children: "Criar nova conversa" }),
743
+ /* @__PURE__ */ o("p", { className: "bp-webchat-modal-description", children: "Isso vai limpar a conversa atual e iniciar uma nova sessão com o bot." }),
744
+ /* @__PURE__ */ l("div", { className: "bp-webchat-modal-actions", children: [
745
+ /* @__PURE__ */ o(
746
+ "button",
747
+ {
748
+ className: "bp-webchat-modal-button bp-webchat-modal-button--primary",
749
+ type: "button",
750
+ onClick: t,
751
+ children: "Nova conversa"
752
+ }
753
+ ),
754
+ /* @__PURE__ */ o("button", { className: "bp-webchat-modal-button", type: "button", onClick: a, children: "Cancelar" })
755
+ ] })
756
+ ] }) }) : null;
757
+ }
758
+ function so({ config: e, activeView: t, onShowHome: a, onShowConversations: r, onStart: s, onClose: n }) {
759
+ const c = e.welcomeCardImage || e.botAvatar;
760
+ return /* @__PURE__ */ l("div", { className: "bp-webchat-welcome", children: [
761
+ /* @__PURE__ */ l("div", { className: "bp-webchat-welcome-hero", children: [
762
+ /* @__PURE__ */ o(
763
+ "button",
764
+ {
765
+ className: "bp-webchat-icon-button bp-webchat-welcome-close",
766
+ type: "button",
767
+ onClick: n,
768
+ "aria-label": e.welcomeCloseLabel,
769
+ children: le
770
+ }
771
+ ),
772
+ e.welcomeCoverImage ? /* @__PURE__ */ o("img", { className: "bp-webchat-welcome-cover", src: e.welcomeCoverImage, alt: "" }) : null
773
+ ] }),
774
+ /* @__PURE__ */ o("div", { className: "bp-webchat-welcome-card-wrap", children: /* @__PURE__ */ l("div", { className: "bp-webchat-welcome-card", children: [
775
+ /* @__PURE__ */ o("div", { className: "bp-webchat-welcome-card-badge", children: c ? /* @__PURE__ */ o("img", { src: c, alt: "" }) : /* @__PURE__ */ o("span", { children: (e.botName || "B").slice(0, 1).toUpperCase() }) }),
776
+ /* @__PURE__ */ o("h3", { className: "bp-webchat-welcome-card-title", children: e.welcomeCardTitle }),
777
+ /* @__PURE__ */ o("p", { className: "bp-webchat-welcome-card-status", children: /* @__PURE__ */ o("strong", { children: e.welcomeCardStatus }) }),
778
+ /* @__PURE__ */ o("p", { className: "bp-webchat-welcome-card-description", children: e.welcomeCardDescription }),
779
+ /* @__PURE__ */ l("button", { className: "bp-webchat-welcome-cta", type: "button", onClick: s, children: [
780
+ /* @__PURE__ */ o("span", { className: "bp-webchat-welcome-cta-left", children: /* @__PURE__ */ l("span", { className: "bp-webchat-welcome-cta-copy", children: [
781
+ /* @__PURE__ */ o("span", { className: "bp-webchat-welcome-cta-title", children: e.welcomeCtaLabel }),
782
+ e.welcomeButtonDescription ? /* @__PURE__ */ o("span", { className: "bp-webchat-welcome-cta-description", children: e.welcomeButtonDescription }) : null
783
+ ] }) }),
784
+ /* @__PURE__ */ o("span", { className: "bp-webchat-welcome-cta-right", children: Dt })
785
+ ] })
786
+ ] }) }),
787
+ /* @__PURE__ */ o(
788
+ He,
789
+ {
790
+ activeView: t,
791
+ onShowHome: a,
792
+ onShowConversations: r
793
+ }
794
+ )
795
+ ] });
796
+ }
797
+ const co = 220, ie = "eduzz-webchat", be = Object.freeze({
798
+ allowFileUpload: !1,
799
+ allowMessageFeedback: !1
800
+ }), lo = "anonymous-id", io = (e) => !!e && typeof e == "object" && !Array.isArray(e), Re = (e) => e.replace(/\/+$/, ""), fe = ({ webchatProxyUrl: e }) => {
801
+ if (typeof e != "string" || !e.trim())
802
+ return null;
803
+ const t = Re(e.trim()), a = "/webchat/proxy";
804
+ return t.endsWith(a) ? t.slice(0, -a.length) : null;
805
+ }, uo = ({ webchatProxyUrl: e, clientId: t }) => !e || !t ? null : `${e.endsWith("/") ? e.slice(0, -1) : e}/${encodeURIComponent(t)}/runtime-config`, bo = ({ webchatProxyUrl: e, clientId: t, presetSlug: a }) => {
806
+ if (!e || !t)
807
+ return null;
808
+ const r = fe({ webchatProxyUrl: e });
809
+ if (!r)
810
+ return null;
811
+ const s = new URLSearchParams();
812
+ typeof a == "string" && a.trim() && s.set("slug", a.trim());
813
+ const n = s.toString();
814
+ return `${r}/webchat/bootstrap/${encodeURIComponent(t)}${n ? `?${n}` : ""}`;
815
+ }, ho = (e) => {
816
+ const t = e && typeof e == "object" && e.data && typeof e.data == "object" ? e.data : e;
817
+ return t && typeof t == "object" ? t : null;
818
+ }, J = (e) => io(e) ? e : null, mo = (e) => {
819
+ if (!e) return "";
820
+ try {
821
+ return JSON.stringify(e);
822
+ } catch {
823
+ return String(Date.now());
824
+ }
825
+ }, $e = (e) => {
826
+ if (typeof window > "u") return null;
827
+ try {
828
+ return e === "sessionStorage" ? window.sessionStorage : window.localStorage;
829
+ } catch {
830
+ return null;
831
+ }
832
+ }, _e = ({ storageKey: e, storageLocation: t }) => {
833
+ const a = $e(t);
834
+ if (!a) return null;
835
+ try {
836
+ const r = a.getItem(
837
+ `${e || ie}-client`
838
+ );
839
+ if (!r) return null;
840
+ const s = JSON.parse(r), n = typeof s?.state == "string" ? JSON.parse(s.state) : s?.state ?? s;
841
+ return n && typeof n == "object" ? n : null;
842
+ } catch {
843
+ return;
844
+ }
845
+ }, po = ({ storageKey: e, storageLocation: t }) => {
846
+ const a = _e({ storageKey: e, storageLocation: t });
847
+ return typeof a?.conversationId == "string" && a.conversationId.trim() || void 0;
848
+ }, xe = () => {
849
+ try {
850
+ if (typeof crypto < "u" && typeof crypto.randomUUID == "function")
851
+ return crypto.randomUUID();
852
+ } catch {
853
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
854
+ const t = Math.random() * 16 | 0;
855
+ return (e === "x" ? t : t & 3 | 8).toString(16);
856
+ });
857
+ }
858
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
859
+ const t = Math.random() * 16 | 0;
860
+ return (e === "x" ? t : t & 3 | 8).toString(16);
861
+ });
862
+ }, wo = (e) => `${e || ie}-${lo}`, fo = ({ storageKey: e, storageLocation: t }) => {
863
+ const a = $e(t), r = wo(e);
864
+ try {
865
+ const s = a?.getItem(r);
866
+ if (s)
867
+ return s;
868
+ const n = `anon_${xe()}`;
869
+ return a?.setItem(r, n), n;
870
+ } catch {
871
+ return `anon_${xe()}`;
872
+ }
873
+ }, go = async ({ webchatProxyUrl: e, clientId: t, accountId: a }) => {
874
+ const r = fe({ webchatProxyUrl: e });
875
+ if (!r)
876
+ throw new Error("public session request requires a valid webchatProxyUrl");
877
+ const s = await fetch(
878
+ `${r}/webchat/session/open/${encodeURIComponent(t)}`,
879
+ {
880
+ method: "POST",
881
+ headers: {
882
+ "Content-Type": "application/json"
883
+ },
884
+ body: JSON.stringify({ accountId: a })
885
+ }
886
+ );
887
+ if (!s.ok)
888
+ throw new Error(`public session request failed with status ${s.status}`);
889
+ const n = await s.json(), c = n && typeof n == "object" && n.data && typeof n.data == "object" ? n.data : n;
890
+ if (!c || typeof c != "object")
891
+ throw new Error("public session response is invalid");
892
+ if (typeof c.userId != "string" || typeof c.userToken != "string")
893
+ throw new Error("public session response is missing credentials");
894
+ return {
895
+ userId: c.userId,
896
+ userToken: c.userToken
897
+ };
898
+ }, yo = (e) => ({
899
+ ...typeof e.name == "string" && e.name.trim() ? { name: e.name.trim() } : {},
900
+ ...typeof e.pictureUrl == "string" && e.pictureUrl.trim() ? { pictureUrl: e.pictureUrl.trim() } : {},
901
+ userData: e
902
+ }), Co = ({
903
+ showWelcomeScreen: e,
904
+ storageKey: t,
905
+ storageLocation: a,
906
+ conversationId: r,
907
+ userToken: s
908
+ }) => {
909
+ if (!e)
910
+ return { activeView: "chat", historyReturnView: "chat", bootstrapView: "chat" };
911
+ if (r && s)
912
+ return { activeView: "chat", historyReturnView: "chat", bootstrapView: "chat" };
913
+ const n = _e({ storageKey: t, storageLocation: a });
914
+ if (n == null)
915
+ return { activeView: "home", historyReturnView: "home", bootstrapView: "home" };
916
+ if (n === void 0)
917
+ return { activeView: "pending", historyReturnView: "home", bootstrapView: "pending" };
918
+ const c = typeof n.conversationId == "string" ? n.conversationId.trim() : "", d = typeof n.user?.userToken == "string" ? n.user.userToken.trim() : "";
919
+ return c && d ? { activeView: "chat", historyReturnView: "chat", bootstrapView: "chat" } : !c && !d ? { activeView: "home", historyReturnView: "home", bootstrapView: "home" } : { activeView: "pending", historyReturnView: "home", bootstrapView: "pending" };
920
+ }, vo = (e, t) => {
921
+ switch (t.type) {
922
+ case "show":
923
+ return { isPanelMounted: !0, isPanelVisible: e.isPanelVisible };
924
+ case "visible":
925
+ return { isPanelMounted: !0, isPanelVisible: !0 };
926
+ case "hide":
927
+ return { isPanelMounted: e.isPanelMounted, isPanelVisible: !1 };
928
+ case "unmount":
929
+ return { isPanelMounted: !1, isPanelVisible: !1 };
930
+ default:
931
+ return e;
932
+ }
933
+ };
934
+ function Io({
935
+ clientId: e,
936
+ webchatProxyUrl: t,
937
+ userCredentials: a,
938
+ conversationId: r,
939
+ config: s,
940
+ defaultUserData: n,
941
+ presetSlug: c,
942
+ storageKey: d = ie,
943
+ storageLocation: h = "localStorage",
944
+ defaultOpen: B,
945
+ onUserApiChange: x
946
+ }) {
947
+ const p = f(
948
+ () => typeof c == "string" && c.trim() ? c.trim() : void 0,
949
+ [c]
950
+ ), I = f(
951
+ () => typeof t == "string" && t.trim() ? Re(t.trim()) : void 0,
952
+ [t]
953
+ );
954
+ f(
955
+ () => I ? fe({ webchatProxyUrl: I }) : null,
956
+ [I]
957
+ );
958
+ const N = !!(e && I && (p || !a)), g = f(
959
+ () => N ? bo({
960
+ webchatProxyUrl: I,
961
+ clientId: e,
962
+ presetSlug: p
963
+ }) : null,
964
+ [e, p, I, N]
965
+ ), [V, D] = R({
966
+ error: null,
967
+ isLoading: !1,
968
+ payload: null,
969
+ url: null
970
+ });
971
+ A(() => {
972
+ if (!g) {
973
+ D({ error: null, isLoading: !1, payload: null, url: null });
974
+ return;
975
+ }
976
+ const u = new AbortController();
977
+ return D({ error: null, isLoading: !0, payload: null, url: g }), fetch(g, {
978
+ headers: {
979
+ accept: "application/json"
980
+ },
981
+ signal: u.signal
982
+ }).then(async (m) => {
983
+ if (!m.ok)
984
+ throw new Error(`bootstrap request failed with status ${m.status}`);
985
+ return m.json();
986
+ }).then((m) => {
987
+ const k = ho(m);
988
+ if (!k)
989
+ throw new Error("bootstrap response is invalid");
990
+ D({
991
+ error: null,
992
+ isLoading: !1,
993
+ payload: k,
994
+ url: g
995
+ });
996
+ }).catch((m) => {
997
+ u.signal.aborted || (console.warn("[EduzzWebchat] failed to load bootstrap", m), D({ error: m, isLoading: !1, payload: null, url: g }));
998
+ }), () => u.abort();
999
+ }, [g]);
1000
+ const y = g && V.url === g ? V.payload : null, q = g && V.url === g ? V.error : null, S = y?.clientId || e, P = I || y?.webchatProxyUrl || void 0, T = d === ie && y?.storageKey ? y.storageKey : d, Z = typeof B == "boolean" ? B : typeof y?.defaultOpen == "boolean" ? y.defaultOpen : B, oe = f(
1001
+ () => ({
1002
+ ...J(y?.config) || {},
1003
+ ...J(s) || {}
1004
+ }),
1005
+ [y, s]
1006
+ ), E = f(
1007
+ () => {
1008
+ const u = {
1009
+ ...J(y?.defaultUserData) || {},
1010
+ ...J(n) || {}
1011
+ };
1012
+ return Object.keys(u).length > 0 ? u : null;
1013
+ },
1014
+ [n, y]
1015
+ ), W = !!(!a && y?.sessionMode === "service-hub" && P && S), [$, G] = R({
1016
+ error: null,
1017
+ isLoading: !1,
1018
+ payload: null,
1019
+ key: null
1020
+ });
1021
+ A(() => {
1022
+ if (!W) {
1023
+ G({ error: null, isLoading: !1, payload: null, key: null });
1024
+ return;
1025
+ }
1026
+ const u = fo({
1027
+ storageKey: T,
1028
+ storageLocation: h
1029
+ }), m = `${S}:${P}:${u}`;
1030
+ let k = !1;
1031
+ return G({
1032
+ error: null,
1033
+ isLoading: !0,
1034
+ payload: null,
1035
+ key: m
1036
+ }), go({
1037
+ webchatProxyUrl: P,
1038
+ clientId: S,
1039
+ accountId: u
1040
+ }).then((b) => {
1041
+ k || G({
1042
+ error: null,
1043
+ isLoading: !1,
1044
+ payload: b,
1045
+ key: m
1046
+ });
1047
+ }).catch((b) => {
1048
+ k || (console.warn("[EduzzWebchat] failed to open public session", b), G({
1049
+ error: b,
1050
+ isLoading: !1,
1051
+ payload: null,
1052
+ key: m
1053
+ }));
1054
+ }), () => {
1055
+ k = !0;
1056
+ };
1057
+ }, [
1058
+ S,
1059
+ T,
1060
+ P,
1061
+ W,
1062
+ h
1063
+ ]);
1064
+ const _ = W ? $.payload : null, K = a || _, H = f(() => lt(oe), [oe]), L = f(
1065
+ () => r || po({
1066
+ storageKey: T,
1067
+ storageLocation: h
1068
+ }),
1069
+ [r, T, h]
1070
+ ), w = Z ?? H.initiallyOpen ?? !0, [de, z] = R(w), ae = me(w), [ue, O] = R(be), X = ee(() => z((u) => !u), []);
1071
+ A(() => {
1072
+ ae.current !== w && (ae.current = w, z(w));
1073
+ }, [w]);
1074
+ const Y = N && !y && !q, Q = W && !_ && !$.error;
1075
+ return A(() => {
1076
+ const u = uo({
1077
+ webchatProxyUrl: P,
1078
+ clientId: S
1079
+ });
1080
+ if (O(be), !u)
1081
+ return;
1082
+ const m = new AbortController();
1083
+ let k = !1;
1084
+ return fetch(u, {
1085
+ headers: {
1086
+ accept: "application/json"
1087
+ },
1088
+ signal: m.signal
1089
+ }).then(async (b) => {
1090
+ if (!b.ok)
1091
+ throw new Error(`runtime config request failed with status ${b.status}`);
1092
+ return b.json();
1093
+ }).then((b) => {
1094
+ if (k)
1095
+ return;
1096
+ const U = b && typeof b == "object" && b.data && typeof b.data == "object" ? b.data : {};
1097
+ O({
1098
+ allowFileUpload: U.allowFileUpload === !0,
1099
+ allowMessageFeedback: U.allowMessageFeedback === !0
1100
+ });
1101
+ }).catch((b) => {
1102
+ m.signal.aborted || k || (console.warn("[EduzzWebchat] failed to load runtime config", b), O(be));
1103
+ }), () => {
1104
+ k = !0, m.abort();
1105
+ };
1106
+ }, [S, P]), Y || Q ? null : q && !y ? /* @__PURE__ */ o("div", { className: "bp-webchat-shell", style: te(H), children: /* @__PURE__ */ o("div", { className: "bp-webchat-error", children: "Nao foi possivel carregar a configuracao publica do webchat." }) }) : $.error && !_ ? /* @__PURE__ */ o("div", { className: "bp-webchat-shell", style: te(H), children: /* @__PURE__ */ o("div", { className: "bp-webchat-error", children: "Nao foi possivel abrir a sessao publica do webchat." }) }) : P ? S ? /* @__PURE__ */ o(
1107
+ Ze,
1108
+ {
1109
+ clientId: S,
1110
+ apiUrl: P,
1111
+ conversationId: L,
1112
+ userCredentials: K,
1113
+ storageKey: T,
1114
+ storageLocation: h,
1115
+ children: /* @__PURE__ */ o(
1116
+ Bo,
1117
+ {
1118
+ clientId: S,
1119
+ config: H,
1120
+ defaultUserData: E,
1121
+ conversationIdProp: L,
1122
+ isOpen: de,
1123
+ onUserApiChange: x,
1124
+ onToggle: X,
1125
+ runtimeCapabilities: ue,
1126
+ storageKey: T,
1127
+ storageLocation: h,
1128
+ userToken: K?.userToken
1129
+ }
1130
+ )
1131
+ }
1132
+ ) : /* @__PURE__ */ o("div", { className: "bp-webchat-shell", style: te(H), children: /* @__PURE__ */ o("div", { className: "bp-webchat-error", children: "Nenhum clientId foi informado." }) }) : /* @__PURE__ */ o("div", { className: "bp-webchat-shell", style: te(H), children: /* @__PURE__ */ o("div", { className: "bp-webchat-error", children: "Nenhuma URL publica do proxy do webchat foi informada." }) });
1133
+ }
1134
+ function Bo({
1135
+ clientId: e,
1136
+ config: t,
1137
+ defaultUserData: a,
1138
+ conversationIdProp: r,
1139
+ isOpen: s,
1140
+ onUserApiChange: n,
1141
+ onToggle: c,
1142
+ runtimeCapabilities: d,
1143
+ storageKey: h,
1144
+ storageLocation: B,
1145
+ userToken: x
1146
+ }) {
1147
+ const p = f(
1148
+ () => Co({
1149
+ showWelcomeScreen: t.showWelcomeScreen,
1150
+ storageKey: h,
1151
+ storageLocation: B,
1152
+ conversationId: r,
1153
+ userToken: x
1154
+ }),
1155
+ [
1156
+ t.showWelcomeScreen,
1157
+ r,
1158
+ h,
1159
+ B,
1160
+ x
1161
+ ]
1162
+ ), [I, N] = R(!1), [g, V] = R({ open: !1, messageId: null, draft: "" }), [{ isPanelMounted: D, isPanelVisible: y }, q] = We(vo, {
1163
+ isPanelMounted: s,
1164
+ isPanelVisible: s
1165
+ }), {
1166
+ conversationId: S,
1167
+ isTyping: P,
1168
+ messages: T,
1169
+ saveMessageFeedback: Z,
1170
+ sendMessage: oe,
1171
+ status: E,
1172
+ uploadFile: W
1173
+ } = Xe(), { openConversation: $, listConversations: G } = Ye(), { updateUser: _, userCredentials: K } = Qe(), H = me({}), [L, w] = R(() => p.activeView), [de, z] = R(() => p.historyReturnView), { conversations: ae, isLoading: ue, refresh: O } = et({
1174
+ userCredentials: K,
1175
+ listConversations: G,
1176
+ clientId: e
1177
+ }), X = f(
1178
+ () => mo(a),
1179
+ [a]
1180
+ ), Y = ee(
1181
+ async (C = {}) => {
1182
+ if (!_)
1183
+ return;
1184
+ const i = {
1185
+ ...J(a) || {},
1186
+ ...H.current,
1187
+ ...J(C) || {}
1188
+ };
1189
+ return H.current = i, _(yo(i));
1190
+ },
1191
+ [a, _]
1192
+ ), Q = me(Y);
1193
+ A(() => {
1194
+ Q.current = Y;
1195
+ }, [Y]);
1196
+ const u = !!_;
1197
+ A(() => {
1198
+ H.current = {};
1199
+ }, [X]), A(() => {
1200
+ if (n)
1201
+ return n({
1202
+ updateUserData: u ? (C) => Q.current(C) : void 0
1203
+ }), () => n(null);
1204
+ }, [n, u]), A(() => {
1205
+ !u || !X || Q.current();
1206
+ }, [X, u]), A(() => {
1207
+ d.allowMessageFeedback || V({ open: !1, messageId: null, draft: "" });
1208
+ }, [d.allowMessageFeedback]);
1209
+ const { showInitialLoading: m, setShowInitialLoading: k } = eo({
1210
+ activeView: L,
1211
+ clientState: E,
1212
+ conversationId: S,
1213
+ messagesLength: T.length
1214
+ }), b = f(
1215
+ () => t.botAvatar || Jt({ name: t.botName, backgroundColor: t.accentColor }),
1216
+ [t.accentColor, t.botAvatar, t.botName]
1217
+ ), U = f(
1218
+ () => ({ ...t, botAvatar: b }),
1219
+ [t, b]
1220
+ ), ge = ee(
1221
+ async (C) => {
1222
+ z(C), w("conversations"), await O();
1223
+ },
1224
+ [O]
1225
+ ), Le = ee(
1226
+ (C) => {
1227
+ k(!0), $(C), w("chat");
1228
+ },
1229
+ [$, k]
1230
+ ), ye = ee(() => {
1231
+ k(!0), $(), w("chat");
1232
+ }, [$, k]), ze = f(
1233
+ () => Qt({
1234
+ messages: T,
1235
+ user: K,
1236
+ botName: U.botName,
1237
+ botAvatar: U.botAvatar
1238
+ }),
1239
+ [T, U.botAvatar, U.botName, K]
1240
+ ), De = te(t), qe = f(() => it(t), [t]), Oe = f(() => zt(t.fabChatIconVariant), [t.fabChatIconVariant]);
1241
+ A(() => {
1242
+ if (s) {
1243
+ q({ type: "show" });
1244
+ const ne = window.requestAnimationFrame(() => q({ type: "visible" }));
1245
+ return () => window.cancelAnimationFrame(ne);
1246
+ }
1247
+ q({ type: "hide" });
1248
+ const C = window.setTimeout(() => {
1249
+ N(!1), V({ open: !1, messageId: null, draft: "" });
1250
+ }, 0), i = window.setTimeout(() => q({ type: "unmount" }), co);
1251
+ return () => {
1252
+ window.clearTimeout(C), window.clearTimeout(i);
1253
+ };
1254
+ }, [s]), A(() => {
1255
+ if (p.bootstrapView === "pending") {
1256
+ if (T.length > 0) {
1257
+ const C = window.setTimeout(() => {
1258
+ w("chat"), z("chat");
1259
+ }, 0);
1260
+ return () => window.clearTimeout(C);
1261
+ }
1262
+ if (E !== "connecting") {
1263
+ const C = window.setTimeout(() => {
1264
+ w("home"), z("home");
1265
+ }, 0);
1266
+ return () => window.clearTimeout(C);
1267
+ }
1268
+ }
1269
+ }, [E, p.bootstrapView, T.length]);
1270
+ const Ce = f(
1271
+ () => function(i) {
1272
+ const ne = d.allowMessageFeedback && i.direction === "incoming" && typeof i.addMessageFeedback == "function", Ee = {
1273
+ ...i.block,
1274
+ direction: i.direction,
1275
+ sender: i.sender,
1276
+ timestamp: i.timestamp,
1277
+ messageId: i.messageId,
1278
+ metadata: i.metadata,
1279
+ isReadOnly: i.isReadOnly,
1280
+ status: i.status,
1281
+ feedback: i.feedback,
1282
+ sendMessage: i.sendMessage,
1283
+ addMessageFeedback: i.addMessageFeedback
1284
+ };
1285
+ return /* @__PURE__ */ l(
1286
+ "div",
1287
+ {
1288
+ className: "bpMessageBlocksBubble",
1289
+ "data-direction": i.direction,
1290
+ "data-feedback": ne || void 0,
1291
+ children: [
1292
+ /* @__PURE__ */ o(tt, { block: Ee }),
1293
+ ne ? /* @__PURE__ */ l("div", { className: "bpMessageBlocksBubbleFeedbackContainer", children: [
1294
+ /* @__PURE__ */ o(
1295
+ "button",
1296
+ {
1297
+ className: "bpMessageBlocksBubbleFeedbackIcon",
1298
+ type: "button",
1299
+ "data-selected": i.feedback === "positive",
1300
+ "aria-label": "Feedback positivo",
1301
+ onClick: () => i.addMessageFeedback(i.messageId, { value: "positive" }),
1302
+ children: Ot
1303
+ }
1304
+ ),
1305
+ /* @__PURE__ */ o(
1306
+ "button",
1307
+ {
1308
+ className: "bpMessageBlocksBubbleFeedbackIcon",
1309
+ type: "button",
1310
+ "data-selected": i.feedback === "negative",
1311
+ "aria-label": "Feedback negativo",
1312
+ onClick: () => V({
1313
+ open: !0,
1314
+ messageId: i.messageId,
1315
+ draft: ""
1316
+ }),
1317
+ children: jt
1318
+ }
1319
+ )
1320
+ ] }) : null
1321
+ ]
1322
+ }
1323
+ );
1324
+ },
1325
+ [d.allowMessageFeedback]
1326
+ ), je = f(() => ({ bubble: Ce }), [Ce]);
1327
+ return /* @__PURE__ */ l(
1328
+ "div",
1329
+ {
1330
+ className: "bp-webchat-shell",
1331
+ "data-panel-mounted": D,
1332
+ "data-panel-open": y,
1333
+ style: De,
1334
+ children: [
1335
+ /* @__PURE__ */ o(ot, { ...qe }),
1336
+ D ? /* @__PURE__ */ o("div", { className: "bp-webchat-panel", "data-state": y ? "open" : "closed", children: L === "home" ? /* @__PURE__ */ o(
1337
+ so,
1338
+ {
1339
+ config: U,
1340
+ activeView: L,
1341
+ onClose: c,
1342
+ onShowHome: () => w("home"),
1343
+ onShowConversations: () => ge("home"),
1344
+ onStart: () => w("chat")
1345
+ }
1346
+ ) : L === "conversations" ? /* @__PURE__ */ o(
1347
+ ao,
1348
+ {
1349
+ conversations: ae,
1350
+ currentConversationId: S,
1351
+ isLoading: ue,
1352
+ botAvatar: U.botAvatar,
1353
+ botName: U.botName,
1354
+ onClose: () => w(de),
1355
+ onCloseWidget: c,
1356
+ onShowHome: () => {
1357
+ w("home"), z("home");
1358
+ },
1359
+ onShowConversations: O,
1360
+ onNewConversation: ye,
1361
+ onConversationClick: Le
1362
+ }
1363
+ ) : L === "pending" ? /* @__PURE__ */ o("div", { className: "bp-webchat-layout", children: /* @__PURE__ */ o(Pe, {}) }) : /* @__PURE__ */ l(Ne, { children: [
1364
+ /* @__PURE__ */ o(
1365
+ oo,
1366
+ {
1367
+ config: U,
1368
+ allowFileUpload: d.allowFileUpload,
1369
+ clientState: E,
1370
+ isTyping: P,
1371
+ messages: ze,
1372
+ renderers: je,
1373
+ sendMessage: oe,
1374
+ uploadFile: W,
1375
+ addMessageFeedback: d.allowMessageFeedback ? Z : void 0,
1376
+ showInitialLoading: m,
1377
+ onShowHome: t.showWelcomeScreen ? () => {
1378
+ w("home"), z("home");
1379
+ } : void 0,
1380
+ onOpenHistory: () => ge("chat"),
1381
+ onRestartConversation: () => N(!0),
1382
+ onCloseWidget: c
1383
+ }
1384
+ ),
1385
+ /* @__PURE__ */ o(
1386
+ ro,
1387
+ {
1388
+ open: I,
1389
+ onCancel: () => N(!1),
1390
+ onConfirm: () => {
1391
+ N(!1), ye();
1392
+ }
1393
+ }
1394
+ ),
1395
+ d.allowMessageFeedback ? /* @__PURE__ */ o(
1396
+ no,
1397
+ {
1398
+ open: g.open,
1399
+ draft: g.draft,
1400
+ setDraft: (C) => V((i) => ({ ...i, draft: C })),
1401
+ onCancel: () => V({ open: !1, messageId: null, draft: "" }),
1402
+ onConfirm: async () => {
1403
+ g.messageId && Z && await Z(g.messageId, {
1404
+ value: "negative",
1405
+ comment: g.draft
1406
+ }), V({ open: !1, messageId: null, draft: "" });
1407
+ }
1408
+ }
1409
+ ) : null
1410
+ ] }) }) : null,
1411
+ /* @__PURE__ */ l(
1412
+ "button",
1413
+ {
1414
+ className: "bp-webchat-fab",
1415
+ "data-open": s,
1416
+ onClick: c,
1417
+ type: "button",
1418
+ "aria-label": s ? "Fechar webchat" : "Abrir webchat",
1419
+ children: [
1420
+ /* @__PURE__ */ o("span", { className: "bp-webchat-fab-icon bp-webchat-fab-icon--chat", children: Oe }),
1421
+ /* @__PURE__ */ o("span", { className: "bp-webchat-fab-icon bp-webchat-fab-icon--close", children: Lt })
1422
+ ]
1423
+ }
1424
+ )
1425
+ ]
1426
+ }
1427
+ );
1428
+ }
1429
+ export {
1430
+ Io as Webchat,
1431
+ j as defaultConfig,
1432
+ ce as getContrastingTextColor,
1433
+ te as getShellStyle,
1434
+ lt as normalizeConfig
1435
+ };