@gauravrathod674/super-customizable-chatbot 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,752 @@
1
+ import { jsxs as d, jsx as e } from "react/jsx-runtime";
2
+ import { useState as D, useRef as P, useMemo as I, useEffect as S, useCallback as ge } from "react";
3
+ import { AnimatePresence as J, motion as C } from "framer-motion";
4
+ import { FontAwesomeIcon as Te } from "@fortawesome/react-fontawesome";
5
+ import { faCommentDots as $e } from "@fortawesome/free-solid-svg-icons";
6
+ import { GoogleGenerativeAI as Ie } from "@google/generative-ai";
7
+ import De from "openai";
8
+ import Se from "@anthropic-ai/sdk";
9
+ import ze from "groq-sdk";
10
+ import T from "react-markdown";
11
+ const Ee = () => /* @__PURE__ */ d(
12
+ "svg",
13
+ {
14
+ viewBox: "0 0 24 24",
15
+ fill: "none",
16
+ stroke: "currentColor",
17
+ strokeWidth: "1.5",
18
+ className: "w-full h-full",
19
+ children: [
20
+ /* @__PURE__ */ e("path", { d: "M12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4Z" }),
21
+ /* @__PURE__ */ e(
22
+ "path",
23
+ {
24
+ d: "M16.5 14C16.5 14 15 15.5 12 15.5C9 15.5 7.5 14 7.5 14",
25
+ strokeLinecap: "round"
26
+ }
27
+ ),
28
+ /* @__PURE__ */ e("circle", { cx: "9", cy: "10", r: "1", fill: "currentColor" }),
29
+ /* @__PURE__ */ e("circle", { cx: "15", cy: "10", r: "1", fill: "currentColor" })
30
+ ]
31
+ }
32
+ ), Le = () => /* @__PURE__ */ d(
33
+ "svg",
34
+ {
35
+ viewBox: "0 0 24 24",
36
+ fill: "none",
37
+ stroke: "currentColor",
38
+ strokeWidth: "1.5",
39
+ className: "w-full h-full",
40
+ children: [
41
+ /* @__PURE__ */ e(
42
+ "path",
43
+ {
44
+ d: "M12 12C14.2091 12 16 10.2091 16 8C16 5.79086 14.2091 4 12 4C9.79086 4 8 5.79086 8 8C8 10.2091 9.79086 12 12 12Z",
45
+ strokeLinecap: "round"
46
+ }
47
+ ),
48
+ /* @__PURE__ */ e(
49
+ "path",
50
+ {
51
+ d: "M19.21 17.14C19.21 17.14 19 19 12 19C5 19 4.79 17.14 4.79 17.14C4.79 17.14 6.33 15 12 15C17.67 15 19.21 17.14 19.21 17.14Z",
52
+ strokeLinecap: "round"
53
+ }
54
+ )
55
+ ]
56
+ }
57
+ ), Re = () => /* @__PURE__ */ d(
58
+ "svg",
59
+ {
60
+ fill: "none",
61
+ viewBox: "0 0 24 24",
62
+ strokeWidth: 1.5,
63
+ stroke: "currentColor",
64
+ className: "w-5 h-5",
65
+ children: [
66
+ /* @__PURE__ */ e(
67
+ "path",
68
+ {
69
+ strokeLinecap: "round",
70
+ strokeLinejoin: "round",
71
+ d: "M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.875L6 12z"
72
+ }
73
+ ),
74
+ /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 12h9" })
75
+ ]
76
+ }
77
+ ), Ae = () => /* @__PURE__ */ d("div", { className: "flex items-center space-x-1 p-3", children: [
78
+ /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse [animation-delay:-0.3s]" }),
79
+ /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse [animation-delay:-0.15s]" }),
80
+ /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse" })
81
+ ] }), Fe = ({ fullText: i, onComplete: l }) => {
82
+ const c = typeof i == "string" ? i : "", [p, k] = D("");
83
+ return S(() => {
84
+ if (c.length === 0) {
85
+ l == null || l();
86
+ return;
87
+ }
88
+ let r = 0;
89
+ k("");
90
+ const y = setInterval(() => {
91
+ if (r < c.length) {
92
+ const u = c.charAt(r);
93
+ k((f) => f + u), r++;
94
+ } else
95
+ clearInterval(y), l == null || l();
96
+ }, 25);
97
+ return () => clearInterval(y);
98
+ }, [c, l]), /* @__PURE__ */ e(
99
+ "div",
100
+ {
101
+ className: "prose prose-sm max-w-none text-inherit prose-p:my-0 prose-headings:my-2 prose-ul:my-1 prose-li:my-0.5",
102
+ style: { color: "inherit" },
103
+ children: /* @__PURE__ */ e(T, { children: p || "" })
104
+ }
105
+ );
106
+ }, Oe = ({ text: i, animationType: l }) => {
107
+ const c = "prose prose-sm max-w-none text-inherit prose-p:my-0 prose-headings:my-2 prose-ul:my-1 prose-li:my-0.5";
108
+ switch (l) {
109
+ case "typing":
110
+ return /* @__PURE__ */ e(Fe, { fullText: i });
111
+ case "fade-in":
112
+ return /* @__PURE__ */ e(
113
+ C.div,
114
+ {
115
+ initial: { opacity: 0, y: 10 },
116
+ animate: { opacity: 1, y: 0 },
117
+ transition: { duration: 1.5, ease: "easeOut" },
118
+ children: /* @__PURE__ */ e("div", { className: c, children: /* @__PURE__ */ e(T, { children: i }) })
119
+ }
120
+ );
121
+ case "slide-up":
122
+ return /* @__PURE__ */ e(
123
+ C.div,
124
+ {
125
+ initial: { y: 50, opacity: 0 },
126
+ animate: { y: 0, opacity: 1 },
127
+ transition: { duration: 0.7, ease: "anticipate" },
128
+ children: /* @__PURE__ */ e("div", { className: c, children: /* @__PURE__ */ e(T, { children: i }) })
129
+ }
130
+ );
131
+ case "zoom-in":
132
+ return /* @__PURE__ */ e(
133
+ C.div,
134
+ {
135
+ initial: { scale: 0.5, opacity: 0 },
136
+ animate: { scale: 1, opacity: 1 },
137
+ transition: { duration: 1, ease: "backOut" },
138
+ children: /* @__PURE__ */ e("div", { className: c, children: /* @__PURE__ */ e(T, { children: i }) })
139
+ }
140
+ );
141
+ case "flip":
142
+ return /* @__PURE__ */ e(
143
+ C.div,
144
+ {
145
+ initial: { rotateX: -90, opacity: 0 },
146
+ animate: { rotateX: 0, opacity: 1 },
147
+ transition: { duration: 1, ease: "easeOut" },
148
+ style: { transformPerspective: 400 },
149
+ children: /* @__PURE__ */ e("div", { className: c, children: /* @__PURE__ */ e(T, { children: i }) })
150
+ }
151
+ );
152
+ default:
153
+ return /* @__PURE__ */ e("div", { className: c, children: /* @__PURE__ */ e(T, { children: i }) });
154
+ }
155
+ }, Pe = (i) => {
156
+ const l = [];
157
+ if (!i || i.length === 0)
158
+ return l;
159
+ let p = i.reduce((r, y) => {
160
+ const u = r.length > 0 ? r[r.length - 1] : null;
161
+ if (u && u.sender === y.sender) {
162
+ const f = {
163
+ ...u,
164
+ text: `${u.text}
165
+ ${y.text}`
166
+ };
167
+ r[r.length - 1] = f;
168
+ } else
169
+ r.push({ ...y });
170
+ return r;
171
+ }, []).map((r) => ({
172
+ role: r.sender === "bot" ? "model" : "user",
173
+ parts: [{ text: r.text }]
174
+ }));
175
+ const k = p.findIndex((r) => r.role === "user");
176
+ if (k > -1)
177
+ p = p.slice(k);
178
+ else
179
+ return [];
180
+ return p;
181
+ }, Je = ({
182
+ botName: i = "ChatBot",
183
+ botAvatar: l = /* @__PURE__ */ e(Ee, {}),
184
+ userAvatar: c = /* @__PURE__ */ e(Le, {}),
185
+ welcomeMessage: p = "Hello! How can I help?",
186
+ placeholderText: k = "Type a message...",
187
+ customInstruction: r = "",
188
+ isOpen: y = !1,
189
+ disabled: u = !1,
190
+ isTyping: f = !1,
191
+ onSend: Q = () => {
192
+ },
193
+ theme: g = {},
194
+ geminiApiKey: j,
195
+ geminiModelName: K = "gemini-1.5-flash",
196
+ openaiApiKey: W,
197
+ openaiModelName: ee = "gpt-4o-mini",
198
+ anthropicApiKey: G,
199
+ anthropicModelName: te = "claude-3-haiku-20240307",
200
+ grokApiKey: H,
201
+ grokModelName: oe = "llama3-8b-8192",
202
+ messages: re
203
+ }) => {
204
+ const [N] = D(
205
+ () => `chatbot-instance-${Math.random().toString(36).substring(2, 9)}`
206
+ ), [M, R] = D(y), [we, ye] = D(() => p ? [{ id: 1, text: p, sender: "bot" }] : []), [A, se] = D(""), [F, h] = D(!1), z = typeof re < "u", x = z ? re : we, b = z ? () => {
207
+ } : ye, ne = P(null), ae = P(null), ie = P(null), xe = P(null), q = I(() => {
208
+ if (!j) return null;
209
+ try {
210
+ return new Ie(j).getGenerativeModel({
211
+ model: K,
212
+ systemInstruction: r
213
+ });
214
+ } catch (t) {
215
+ return console.error("Failed to initialize Gemini:", t), null;
216
+ }
217
+ }, [j, K, r]), U = I(() => W ? new De({ apiKey: W, dangerouslyAllowBrowser: !0 }) : null, [W]), V = I(() => G ? new Se({ apiKey: G, dangerouslyAllowBrowser: !0 }) : null, [G]), Z = I(() => H ? new ze({ apiKey: H, dangerouslyAllowBrowser: !0 }) : null, [H]), o = I(() => {
218
+ var v;
219
+ const t = ((v = g == null ? void 0 : g.window) == null ? void 0 : v.placement) === "center", n = {
220
+ launcher: {
221
+ backgroundColor: "#4f46e5",
222
+ iconColor: "#ffffff",
223
+ size: "3.5rem"
224
+ },
225
+ header: {
226
+ backgroundColor: "#4f46e5",
227
+ textColor: "#ffffff",
228
+ fontFamily: "inherit",
229
+ fontWeight: "600"
230
+ },
231
+ messages: {
232
+ userBackgroundColor: "#4f46e5",
233
+ userTextColor: "#ffffff",
234
+ botBackgroundColor: "#f3f4f6",
235
+ botTextColor: "#1f2937",
236
+ fontFamily: "inherit",
237
+ fontSize: "0.9rem",
238
+ showAvatars: !0,
239
+ bubbleShape: "rounded",
240
+ bubblePointer: !0,
241
+ animation: "fade-in"
242
+ },
243
+ input: {
244
+ backgroundColor: "#ffffff",
245
+ textColor: "#1f2937",
246
+ placeholderTextColor: "#9ca3af",
247
+ borderColor: "#e5e7eb",
248
+ focusRingColor: "#4f46e5"
249
+ },
250
+ window: {
251
+ backgroundColor: "#ffffff",
252
+ borderColor: "#e5e7eb",
253
+ borderRadius: "0.75rem",
254
+ width: t ? "80vw" : "22rem",
255
+ height: t ? "80vh" : "30rem",
256
+ placement: "bottom-right",
257
+ backdrop: !1,
258
+ backdropColor: "rgba(0, 0, 0, 0.4)",
259
+ backdropBlur: "4px",
260
+ scrollbarThumbColor: "#a1a1aa",
261
+ // neutral-400
262
+ scrollbarTrackColor: "#f1f5f9"
263
+ // slate-100
264
+ }
265
+ };
266
+ return {
267
+ launcher: { ...n.launcher, ...g.launcher },
268
+ header: { ...n.header, ...g.header },
269
+ messages: { ...n.messages, ...g.messages },
270
+ input: { ...n.input, ...g.input },
271
+ window: { ...n.window, ...g.window }
272
+ };
273
+ }, [g]), ve = I(
274
+ () => ({
275
+ // Launcher
276
+ "--chatbot-launcher-bg": o.launcher.backgroundColor,
277
+ "--chatbot-launcher-icon-color": o.launcher.iconColor,
278
+ "--chatbot-launcher-size": o.launcher.size,
279
+ // Header
280
+ "--chatbot-header-bg": o.header.backgroundColor,
281
+ "--chatbot-header-text-color": o.header.textColor,
282
+ "--chatbot-header-font-family": o.header.fontFamily,
283
+ "--chatbot-header-font-weight": o.header.fontWeight,
284
+ // Messages
285
+ "--chatbot-user-msg-bg": o.messages.userBackgroundColor,
286
+ "--chatbot-user-msg-text-color": o.messages.userTextColor,
287
+ "--chatbot-bot-msg-bg": o.messages.botBackgroundColor,
288
+ "--chatbot-bot-msg-text-color": o.messages.botTextColor,
289
+ "--chatbot-msg-font-family": o.messages.fontFamily,
290
+ "--chatbot-msg-font-size": o.messages.fontSize,
291
+ // Input
292
+ "--chatbot-input-bg": o.input.backgroundColor,
293
+ "--chatbot-input-text-color": o.input.textColor,
294
+ "--chatbot-input-placeholder-color": o.input.placeholderTextColor,
295
+ "--chatbot-input-border-color": o.input.borderColor,
296
+ "--chatbot-input-focus-ring": o.input.focusRingColor,
297
+ // Window
298
+ "--chatbot-window-bg": o.window.backgroundColor,
299
+ "--chatbot-window-border-color": o.window.borderColor,
300
+ "--chatbot-window-border-radius": o.window.borderRadius,
301
+ "--chatbot-window-width": o.window.width,
302
+ "--chatbot-window-height": o.window.height
303
+ }),
304
+ [o]
305
+ );
306
+ S(() => {
307
+ var E;
308
+ const t = o.window.scrollbarThumbColor, n = o.window.scrollbarTrackColor, v = `scrollbar-style-${N}`;
309
+ (E = document.getElementById(v)) == null || E.remove();
310
+ const $ = document.createElement("style");
311
+ return $.id = v, $.innerHTML = `
312
+ /* Modern browsers */
313
+ #${N} .chatbot-message-list {
314
+ scrollbar-width: thin;
315
+ scrollbar-color: ${t} ${n};
316
+ }
317
+ /* WebKit-based browsers (Chrome, Safari, Edge) */
318
+ #${N} .chatbot-message-list::-webkit-scrollbar {
319
+ width: 8px;
320
+ }
321
+ #${N} .chatbot-message-list::-webkit-scrollbar-track {
322
+ background: ${n};
323
+ border-radius: 4px;
324
+ }
325
+ #${N} .chatbot-message-list::-webkit-scrollbar-thumb {
326
+ background-color: ${t};
327
+ border-radius: 4px;
328
+ border: 2px solid ${n};
329
+ }
330
+ `, document.head.appendChild($), () => {
331
+ var L;
332
+ (L = document.getElementById(v)) == null || L.remove();
333
+ };
334
+ }, [
335
+ N,
336
+ o.window.scrollbarThumbColor,
337
+ o.window.scrollbarTrackColor
338
+ ]), S(() => {
339
+ h(f);
340
+ }, [f]), S(() => {
341
+ var t;
342
+ (t = ae.current) == null || t.scrollIntoView({ behavior: "smooth" });
343
+ }, [x, F, f]), S(() => {
344
+ var t, n;
345
+ M ? (t = ne.current) == null || t.focus() : (n = ie.current) == null || n.focus();
346
+ }, [M]), S(() => {
347
+ const t = (n) => {
348
+ n.key === "Escape" && M && R(!1);
349
+ };
350
+ return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
351
+ }, [M]);
352
+ const X = ge(async () => {
353
+ var $, E, L, ce, de, ue, he, be, fe, me, pe;
354
+ const t = A.trim();
355
+ if (!t || u || F || f) return;
356
+ const n = {
357
+ id: Date.now(),
358
+ text: t,
359
+ sender: "user"
360
+ }, v = [...x, n];
361
+ if (z || b((s) => [...s, n]), Q(t), se(""), q) {
362
+ h(!0);
363
+ try {
364
+ const s = Pe(v), a = s.slice(0, -1), B = ((E = ($ = s[s.length - 1]) == null ? void 0 : $.parts[0]) == null ? void 0 : E.text) || "", Ne = await (await (await q.startChat({ history: a }).sendMessage(B)).response).text() || "(no response)", Me = { id: Date.now() + 1, text: Ne, sender: "bot" };
365
+ b((Be) => [...Be, Me]);
366
+ } catch (s) {
367
+ console.error("Gemini API Error:", s);
368
+ const a = {
369
+ id: Date.now() + 1,
370
+ text: "Sorry, an error occurred. Please try again.",
371
+ sender: "bot"
372
+ };
373
+ b((B) => [...B, a]);
374
+ } finally {
375
+ h(!1);
376
+ }
377
+ } else if (U) {
378
+ h(!0);
379
+ try {
380
+ const s = r ? [{ role: "system", content: r }] : [], a = x.map((m) => ({
381
+ role: m.sender === "bot" ? "assistant" : "user",
382
+ content: m.text
383
+ })), w = ((ue = (de = (ce = (L = (await U.chat.completions.create({
384
+ model: ee,
385
+ messages: [
386
+ ...s,
387
+ ...a,
388
+ { role: "user", content: t }
389
+ ]
390
+ })).choices) == null ? void 0 : L[0]) == null ? void 0 : ce.message) == null ? void 0 : de.content) == null ? void 0 : ue.trim()) || "(no response)";
391
+ b((m) => [
392
+ ...m,
393
+ { id: Date.now() + 1, text: w, sender: "bot" }
394
+ ]);
395
+ } catch (s) {
396
+ console.error("OpenAI Error:", s), b((a) => [
397
+ ...a,
398
+ {
399
+ id: Date.now() + 1,
400
+ text: "Sorry, something went wrong with OpenAI.",
401
+ sender: "bot"
402
+ }
403
+ ]);
404
+ } finally {
405
+ h(!1);
406
+ }
407
+ } else if (V) {
408
+ h(!0);
409
+ try {
410
+ const s = x.map((w) => ({
411
+ role: w.sender === "bot" ? "assistant" : "user",
412
+ content: w.text
413
+ })), B = ((be = (he = (await V.messages.create({
414
+ model: te,
415
+ system: r,
416
+ // Pass instruction to the dedicated 'system' parameter
417
+ messages: [
418
+ ...s,
419
+ { role: "user", content: t }
420
+ ],
421
+ max_tokens: 1024
422
+ })).content[0]) == null ? void 0 : he.text) == null ? void 0 : be.trim()) || "(no response)";
423
+ b((w) => [
424
+ ...w,
425
+ { id: Date.now() + 1, text: B, sender: "bot" }
426
+ ]);
427
+ } catch (s) {
428
+ console.error("Anthropic API Error:", s), b((a) => [
429
+ ...a,
430
+ {
431
+ id: Date.now() + 1,
432
+ text: "Sorry, an error occurred with Claude.",
433
+ sender: "bot"
434
+ }
435
+ ]);
436
+ } finally {
437
+ h(!1);
438
+ }
439
+ } else if (Z) {
440
+ h(!0);
441
+ try {
442
+ const s = r ? [{ role: "system", content: r }] : [], a = x.map((m) => ({
443
+ role: m.sender === "bot" ? "assistant" : "user",
444
+ content: m.text
445
+ })), w = ((pe = (me = (fe = (await Z.chat.completions.create({
446
+ messages: [
447
+ ...s,
448
+ ...a,
449
+ { role: "user", content: t }
450
+ ],
451
+ model: oe
452
+ })).choices[0]) == null ? void 0 : fe.message) == null ? void 0 : me.content) == null ? void 0 : pe.trim()) || "(no response)";
453
+ b((m) => [
454
+ ...m,
455
+ { id: Date.now() + 1, text: w, sender: "bot" }
456
+ ]);
457
+ } catch (s) {
458
+ console.error("Groq API Error:", s), b((a) => [
459
+ ...a,
460
+ {
461
+ id: Date.now() + 1,
462
+ text: "Sorry, an error occurred with Groq.",
463
+ sender: "bot"
464
+ }
465
+ ]);
466
+ } finally {
467
+ h(!1);
468
+ }
469
+ } else z || (h(!0), setTimeout(() => {
470
+ const s = {
471
+ id: Date.now() + 1,
472
+ text: `You said: "${t}"`,
473
+ sender: "bot"
474
+ };
475
+ b((a) => [...a, s]), h(!1);
476
+ }, 800));
477
+ }, [
478
+ A,
479
+ u,
480
+ F,
481
+ f,
482
+ Q,
483
+ q,
484
+ U,
485
+ V,
486
+ Z,
487
+ z,
488
+ x,
489
+ b,
490
+ ee,
491
+ te,
492
+ oe,
493
+ r
494
+ // Add to dependency array
495
+ ]), Ce = ge(
496
+ (t) => {
497
+ t.key === "Enter" && X();
498
+ },
499
+ [X]
500
+ ), Y = (t) => typeof t == "string" ? /* @__PURE__ */ e(
501
+ "img",
502
+ {
503
+ src: t,
504
+ alt: "avatar",
505
+ className: "w-8 h-8 rounded-full object-cover"
506
+ }
507
+ ) : /* @__PURE__ */ e("div", { className: "w-8 h-8 rounded-full text-gray-500", children: t }), _ = F || f, le = {
508
+ "bottom-right": "bottom-5 right-5",
509
+ "bottom-left": "bottom-5 left-5",
510
+ center: "top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2"
511
+ }, ke = o.window.placement === "center", O = {
512
+ rounded: "rounded-xl",
513
+ square: "rounded-md"
514
+ };
515
+ return /* @__PURE__ */ d("div", { id: N, style: ve, className: "font-sans", children: [
516
+ /* @__PURE__ */ e(J, { children: !M && /* @__PURE__ */ e(
517
+ C.button,
518
+ {
519
+ ref: ie,
520
+ onClick: () => R(!0),
521
+ "aria-label": "Open Chat",
522
+ initial: { scale: 0, opacity: 0 },
523
+ animate: { scale: 1, opacity: 1 },
524
+ exit: { scale: 0, opacity: 0 },
525
+ transition: { duration: 0.2, ease: "easeOut" },
526
+ className: "fixed bottom-10 right-10 z-50 rounded-full shadow-lg flex items-center justify-center cursor-pointer border-2 border-white/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-[--chatbot-launcher-bg]",
527
+ style: {
528
+ backgroundColor: "var(--chatbot-launcher-bg)",
529
+ color: "var(--chatbot-launcher-icon-color)",
530
+ width: "var(--chatbot-launcher-size)",
531
+ height: "var(--chatbot-launcher-size)"
532
+ },
533
+ children: /* @__PURE__ */ e(Te, { icon: $e })
534
+ }
535
+ ) }),
536
+ /* @__PURE__ */ d(J, { children: [
537
+ M && ke && o.window.backdrop && /* @__PURE__ */ e(
538
+ C.div,
539
+ {
540
+ initial: { opacity: 0 },
541
+ animate: { opacity: 1 },
542
+ exit: { opacity: 0 },
543
+ style: {
544
+ backgroundColor: o.window.backdropColor,
545
+ backdropFilter: `blur(${o.window.backdropBlur})`,
546
+ // For Safari compatibility
547
+ WebkitBackdropFilter: `blur(${o.window.backdropBlur})`
548
+ },
549
+ className: "fixed inset-0 z-40",
550
+ onClick: () => R(!1)
551
+ },
552
+ "chatbot-backdrop"
553
+ ),
554
+ M && /* @__PURE__ */ d(
555
+ "div",
556
+ {
557
+ ref: xe,
558
+ "aria-modal": "true",
559
+ role: "dialog",
560
+ className: `fixed ${le[o.window.placement] || le["bottom-right"]} z-50 flex flex-col overflow-hidden shadow-2xl border`,
561
+ style: {
562
+ width: "var(--chatbot-window-width)",
563
+ height: "var(--chatbot-window-height)",
564
+ borderRadius: "var(--chatbot-window-border-radius)",
565
+ backgroundColor: "var(--chatbot-window-bg)",
566
+ borderColor: "var(--chatbot-window-border-color)"
567
+ },
568
+ children: [
569
+ /* @__PURE__ */ d(
570
+ "header",
571
+ {
572
+ className: "flex items-center justify-between p-3 flex-shrink-0",
573
+ style: {
574
+ background: "var(--chatbot-header-bg)",
575
+ color: "var(--chatbot-header-text-color)"
576
+ },
577
+ children: [
578
+ /* @__PURE__ */ d("div", { className: "flex items-center space-x-3", children: [
579
+ /* @__PURE__ */ e("div", { className: "w-10 h-10 rounded-full bg-white/30 flex items-center justify-center p-1", children: Y(l) }),
580
+ /* @__PURE__ */ e(
581
+ "span",
582
+ {
583
+ style: {
584
+ fontFamily: "var(--chatbot-header-font-family)",
585
+ fontWeight: "var(--chatbot-header-font-weight)"
586
+ },
587
+ className: "text-lg",
588
+ children: i
589
+ }
590
+ )
591
+ ] }),
592
+ /* @__PURE__ */ e(
593
+ "button",
594
+ {
595
+ onClick: () => R(!1),
596
+ "aria-label": "Close Chat",
597
+ className: "p-1 rounded-full hover:bg-white/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-white",
598
+ children: /* @__PURE__ */ e(
599
+ "svg",
600
+ {
601
+ xmlns: "http://www.w3.org/2000/svg",
602
+ fill: "none",
603
+ viewBox: "0 0 24 24",
604
+ strokeWidth: 2,
605
+ stroke: "currentColor",
606
+ className: "w-6 h-6",
607
+ children: /* @__PURE__ */ e(
608
+ "path",
609
+ {
610
+ strokeLinecap: "round",
611
+ strokeLinejoin: "round",
612
+ d: "M6 18L18 6M6 6l12 12"
613
+ }
614
+ )
615
+ }
616
+ )
617
+ }
618
+ )
619
+ ]
620
+ }
621
+ ),
622
+ /* @__PURE__ */ d(
623
+ "div",
624
+ {
625
+ role: "log",
626
+ "aria-live": "polite",
627
+ className: "chatbot-message-list flex-1 p-4 overflow-y-auto space-y-4",
628
+ children: [
629
+ /* @__PURE__ */ e(J, { initial: !1, children: x.map((t, n) => /* @__PURE__ */ d(
630
+ C.div,
631
+ {
632
+ layout: !0,
633
+ initial: { opacity: 0, y: 20 },
634
+ animate: { opacity: 1, y: 0 },
635
+ exit: { opacity: 0, y: -10 },
636
+ transition: { duration: 0.3, ease: "easeOut" },
637
+ className: `flex items-end max-w-[85%] gap-2 ${t.sender === "user" ? "ml-auto flex-row-reverse" : "mr-auto"}`,
638
+ children: [
639
+ o.messages.showAvatars && /* @__PURE__ */ e("div", { className: "w-7 h-7 rounded-full flex-shrink-0 overflow-hidden", children: Y(
640
+ t.sender === "user" ? c : l
641
+ ) }),
642
+ /* @__PURE__ */ e(
643
+ C.div,
644
+ {
645
+ layout: "position",
646
+ transition: { duration: 0.2, ease: "easeOut" },
647
+ className: `px-3 py-2 ${O[o.messages.bubbleShape] || O.rounded} ${o.messages.bubblePointer ? t.sender === "user" ? "rounded-br-none" : "rounded-bl-none" : ""}`,
648
+ style: {
649
+ backgroundColor: t.sender === "user" ? "var(--chatbot-user-msg-bg)" : "var(--chatbot-bot-msg-bg)",
650
+ color: t.sender === "user" ? "var(--chatbot-user-msg-text-color)" : "var(--chatbot-bot-msg-text-color)",
651
+ fontFamily: "var(--chatbot-msg-font-family)",
652
+ fontSize: "var(--chatbot-msg-font-size)"
653
+ },
654
+ children: t.sender === "bot" && n === x.length - 1 ? /* @__PURE__ */ e(
655
+ Oe,
656
+ {
657
+ text: t.text,
658
+ animationType: o.messages.animation
659
+ }
660
+ ) : /* @__PURE__ */ e(
661
+ "div",
662
+ {
663
+ className: "prose prose-sm max-w-none text-inherit prose-p:my-0 prose-headings:my-2 prose-ul:my-1 prose-li:my-0.5",
664
+ style: { color: "inherit" },
665
+ children: /* @__PURE__ */ e(T, { children: t.text })
666
+ }
667
+ )
668
+ }
669
+ )
670
+ ]
671
+ },
672
+ t.id
673
+ )) }),
674
+ _ && /* @__PURE__ */ d(
675
+ "div",
676
+ {
677
+ className: "flex items-end max-w-[85%] gap-2 mr-auto",
678
+ children: [
679
+ " ",
680
+ o.messages.showAvatars && /* @__PURE__ */ e("div", { className: "w-7 h-7 rounded-full flex-shrink-0 overflow-hidden", children: Y(l) }),
681
+ /* @__PURE__ */ e(
682
+ "div",
683
+ {
684
+ className: `px-3 py-2 ${O[o.messages.bubbleShape] || O.rounded} rounded-bl-none`,
685
+ style: { backgroundColor: "var(--chatbot-bot-msg-bg)" },
686
+ children: /* @__PURE__ */ e(Ae, {})
687
+ }
688
+ )
689
+ ]
690
+ },
691
+ "typing-indicator"
692
+ ),
693
+ /* @__PURE__ */ e("div", { ref: ae })
694
+ ]
695
+ }
696
+ ),
697
+ /* @__PURE__ */ e(
698
+ "footer",
699
+ {
700
+ className: "p-3 border-t flex-shrink-0",
701
+ style: {
702
+ borderColor: "var(--chatbot-window-border-color)",
703
+ backgroundColor: "var(--chatbot-input-bg)"
704
+ },
705
+ children: /* @__PURE__ */ d("div", { className: "flex items-center space-x-2", children: [
706
+ /* @__PURE__ */ e(
707
+ "input",
708
+ {
709
+ ref: ne,
710
+ type: "text",
711
+ value: A,
712
+ onChange: (t) => se(t.target.value),
713
+ onKeyPress: Ce,
714
+ placeholder: k,
715
+ disabled: u || _,
716
+ "aria-label": "Chat input",
717
+ className: "flex-1 w-full px-4 py-2 bg-transparent rounded-full border focus:outline-none focus:ring-2 disabled:cursor-not-allowed disabled:opacity-60",
718
+ style: {
719
+ color: "var(--chatbot-input-text-color)",
720
+ borderColor: "var(--chatbot-input-border-color)",
721
+ "--tw-ring-color": "var(--chatbot-input-focus-ring)"
722
+ }
723
+ }
724
+ ),
725
+ /* @__PURE__ */ e(
726
+ "button",
727
+ {
728
+ onClick: X,
729
+ disabled: !A.trim() || u || _,
730
+ "aria-label": "Send Message",
731
+ className: "px-4 h-10 rounded-full flex items-center justify-center flex-shrink-0 font-semibold text-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",
732
+ style: {
733
+ backgroundColor: "var(--chatbot-user-msg-bg)",
734
+ color: "var(--chatbot-user-msg-text-color)",
735
+ "--tw-ring-color": "var(--chatbot-user-msg-bg)"
736
+ },
737
+ children: /* @__PURE__ */ e(Re, {})
738
+ }
739
+ )
740
+ ] })
741
+ }
742
+ )
743
+ ]
744
+ },
745
+ "chatbot-window"
746
+ )
747
+ ] })
748
+ ] });
749
+ };
750
+ export {
751
+ Je as ChatBot
752
+ };