vpschatbotwidget 1.0.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 (63) hide show
  1. package/Chatbot.svg +1 -0
  2. package/README.md +86 -0
  3. package/dist/assets/index-C0fUDi2s.css +1 -0
  4. package/dist/assets/index-foGq5_Av.js +159 -0
  5. package/dist/index.html +17 -0
  6. package/index.html +16 -0
  7. package/package.json +47 -0
  8. package/src/App.tsx +85 -0
  9. package/src/chatbot/api/chatbot-api.ts +258 -0
  10. package/src/chatbot/api/chatbot-types.ts +145 -0
  11. package/src/chatbot/chatbot.test.tsx +274 -0
  12. package/src/chatbot/config/colors.ts +166 -0
  13. package/src/chatbot/config/suggestions.ts +21 -0
  14. package/src/chatbot/core/ChatContext.tsx +43 -0
  15. package/src/chatbot/core/ChatEmptyState.tsx +21 -0
  16. package/src/chatbot/core/ChatError.tsx +26 -0
  17. package/src/chatbot/core/ChatHeader.tsx +108 -0
  18. package/src/chatbot/core/ChatInput.tsx +103 -0
  19. package/src/chatbot/core/ChatMarkdown.tsx +87 -0
  20. package/src/chatbot/core/ChatMessage.tsx +115 -0
  21. package/src/chatbot/core/ChatMessageList.tsx +47 -0
  22. package/src/chatbot/core/ChatPanel.tsx +66 -0
  23. package/src/chatbot/core/ChatProvider.tsx +185 -0
  24. package/src/chatbot/core/ChatSuggestions.tsx +71 -0
  25. package/src/chatbot/core/ChatTicketConfirmation.tsx +59 -0
  26. package/src/chatbot/core/ChatTypingIndicator.tsx +16 -0
  27. package/src/chatbot/core/ticket-intent.ts +12 -0
  28. package/src/chatbot/embedded/EmbeddedChatbot.tsx +47 -0
  29. package/src/chatbot/embedded/EmbeddedChatbotPanel.tsx +56 -0
  30. package/src/chatbot/embedded/EmbeddedChatbotTrigger.tsx +167 -0
  31. package/src/chatbot/hooks/useChatbot.ts +5 -0
  32. package/src/chatbot/index.ts +7 -0
  33. package/src/chatbot/widget/ChatbotWidget.tsx +43 -0
  34. package/src/chatbot/widget/ChatbotWidgetPanel.tsx +39 -0
  35. package/src/chatbot/widget/ChatbotWidgetTrigger.tsx +32 -0
  36. package/src/components/AgentSummaryCard.tsx +37 -0
  37. package/src/components/ChatHeader.tsx +142 -0
  38. package/src/components/ChatInput.tsx +123 -0
  39. package/src/components/ChatWidget.tsx +295 -0
  40. package/src/components/ConnectingStatus.tsx +16 -0
  41. package/src/components/EnvBadge.tsx +103 -0
  42. package/src/components/FeedbackRatingCard.tsx +123 -0
  43. package/src/components/MessageItem.tsx +157 -0
  44. package/src/components/MessageList.tsx +143 -0
  45. package/src/components/OrderTrackingCard.tsx +104 -0
  46. package/src/components/QuickPrompts.tsx +46 -0
  47. package/src/components/ResponseIconMapper.tsx +155 -0
  48. package/src/components/SourceCitations.tsx +46 -0
  49. package/src/components/ToolCallBadge.tsx +29 -0
  50. package/src/components/TypingProgressBar.tsx +113 -0
  51. package/src/components/ui/message-scroller.tsx +128 -0
  52. package/src/index.css +550 -0
  53. package/src/lib/cn.ts +5 -0
  54. package/src/lib/gibberishDetector.ts +159 -0
  55. package/src/lib/textHighlighter.tsx +206 -0
  56. package/src/main.tsx +10 -0
  57. package/src/services/api.ts +74 -0
  58. package/src/test/message-scroller-stub.tsx +60 -0
  59. package/src/test/setup.ts +8 -0
  60. package/src/types/chat.ts +66 -0
  61. package/src/vite-env.d.ts +14 -0
  62. package/tsconfig.json +21 -0
  63. package/vite.config.ts +28 -0
@@ -0,0 +1,59 @@
1
+ import React, { useState } from "react";
2
+ import { useChatbot } from "../hooks/useChatbot";
3
+
4
+ export const ChatTicketConfirmation: React.FC = () => {
5
+ const { pendingTicket, ticketBusy, userContext, confirmTicket, cancelTicket } =
6
+ useChatbot();
7
+ const needsIdentity = !userContext.customerId && !userContext.email;
8
+ const [identity, setIdentity] = useState("");
9
+
10
+ if (!pendingTicket) return null;
11
+
12
+ return (
13
+ <div
14
+ className="mx-4 mb-3 rounded-xl border border-border bg-card p-4 shadow-sm"
15
+ role="region"
16
+ aria-label="Create support ticket"
17
+ >
18
+ <h3 className="text-[13.5px] font-bold text-foreground">
19
+ Create support ticket?
20
+ </h3>
21
+ <p className="mt-1.5 text-[12.5px] leading-5 text-muted-foreground">
22
+ I can open a support request for you. Nothing is created until you confirm.
23
+ </p>
24
+ <p className="mt-2 rounded-md bg-muted px-2.5 py-2 text-[12.5px] text-foreground">
25
+ {pendingTicket.description}
26
+ </p>
27
+ {needsIdentity && (
28
+ <label className="mt-3 block text-[12px] font-semibold text-foreground">
29
+ Customer ID or email
30
+ <input
31
+ value={identity}
32
+ onChange={(event) => setIdentity(event.target.value)}
33
+ className="mt-1 w-full rounded-md border border-border px-2.5 py-2 text-[13px] font-normal outline-none focus-visible:ring-2 focus-visible:ring-primary"
34
+ placeholder="CUST-1001 or you@company.com"
35
+ autoComplete="email"
36
+ />
37
+ </label>
38
+ )}
39
+ <div className="mt-3 flex justify-end gap-2">
40
+ <button
41
+ type="button"
42
+ onClick={cancelTicket}
43
+ disabled={ticketBusy}
44
+ className="rounded-lg border border-border bg-card px-3.5 py-1.5 text-[12.5px] font-semibold text-muted-foreground hover:bg-muted"
45
+ >
46
+ Cancel
47
+ </button>
48
+ <button
49
+ type="button"
50
+ onClick={() => void confirmTicket(identity)}
51
+ disabled={ticketBusy || (needsIdentity && !identity.trim())}
52
+ className="rounded-lg bg-action px-3.5 py-1.5 text-[12.5px] font-semibold text-action-foreground hover:bg-[var(--action-hover)] disabled:opacity-40"
53
+ >
54
+ {ticketBusy ? "Creating…" : "Create ticket"}
55
+ </button>
56
+ </div>
57
+ </div>
58
+ );
59
+ };
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import { cn } from "../../lib/cn";
3
+
4
+ export const ChatTypingIndicator: React.FC<{ className?: string }> = ({ className }) => {
5
+ return (
6
+ <div
7
+ className={cn("flex items-center gap-1 py-0.5", className)}
8
+ role="status"
9
+ aria-label="Assistant is preparing a reply"
10
+ >
11
+ <span className="h-1.5 w-1.5 rounded-full bg-[var(--text-subtle)] motion-safe:animate-pulse" />
12
+ <span className="h-1.5 w-1.5 rounded-full bg-[var(--text-subtle)] motion-safe:animate-pulse [animation-delay:150ms]" />
13
+ <span className="h-1.5 w-1.5 rounded-full bg-[var(--text-subtle)] motion-safe:animate-pulse [animation-delay:300ms]" />
14
+ </div>
15
+ );
16
+ };
@@ -0,0 +1,12 @@
1
+ const TICKET_INTENT =
2
+ /\b(create (a )?support ticket|open (a )?ticket|raise (a )?ticket|submit (a )?ticket|create (a )?ticket|contact support|speak to support)\b/i;
3
+
4
+ export function detectTicketIntent(text: string): boolean {
5
+ return TICKET_INTENT.test(text.trim());
6
+ }
7
+
8
+ export function ticketSubjectFromText(text: string): string {
9
+ const cleaned = text.replace(/\s+/g, " ").trim();
10
+ if (cleaned.length <= 80) return cleaned;
11
+ return `${cleaned.slice(0, 77)}...`;
12
+ }
@@ -0,0 +1,47 @@
1
+ import React, { useState } from "react";
2
+ import { EmbeddedChatbotPanel } from "./EmbeddedChatbotPanel";
3
+ import { EmbeddedChatbotTrigger } from "./EmbeddedChatbotTrigger";
4
+ import { type EnvStage } from "../../components/EnvBadge";
5
+
6
+ interface EmbeddedChatbotProps {
7
+ defaultOpen?: boolean;
8
+ open?: boolean;
9
+ onOpenChange?: (open: boolean) => void;
10
+ showTrigger?: boolean;
11
+ /** Environment badge stage. Omit for production. */
12
+ envStage?: EnvStage;
13
+ envPulse?: boolean;
14
+ }
15
+
16
+ export const EmbeddedChatbot: React.FC<EmbeddedChatbotProps> = ({
17
+ defaultOpen = false,
18
+ open,
19
+ onOpenChange,
20
+ showTrigger = true,
21
+ envStage,
22
+ envPulse = true,
23
+ }) => {
24
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
25
+ const isOpen = open ?? uncontrolledOpen;
26
+
27
+ const setOpen = (next: boolean) => {
28
+ onOpenChange?.(next);
29
+ if (open === undefined) {
30
+ setUncontrolledOpen(next);
31
+ }
32
+ };
33
+
34
+ return (
35
+ <>
36
+ {showTrigger && !isOpen && (
37
+ <EmbeddedChatbotTrigger onOpen={() => setOpen(true)} />
38
+ )}
39
+ <EmbeddedChatbotPanel
40
+ open={isOpen}
41
+ onClose={() => setOpen(false)}
42
+ envStage={envStage}
43
+ envPulse={envPulse}
44
+ />
45
+ </>
46
+ );
47
+ };
@@ -0,0 +1,56 @@
1
+ import React from "react";
2
+ import { ChatPanel } from "../core/ChatPanel";
3
+ import { cn } from "../../lib/cn";
4
+ import { type EnvStage } from "../../components/EnvBadge";
5
+
6
+ interface EmbeddedChatbotPanelProps {
7
+ open: boolean;
8
+ onClose: () => void;
9
+ subtitle?: string;
10
+ title?: string;
11
+ envStage?: EnvStage;
12
+ envPulse?: boolean;
13
+ }
14
+
15
+ export const EmbeddedChatbotPanel: React.FC<EmbeddedChatbotPanelProps> = ({
16
+ open,
17
+ onClose,
18
+ subtitle,
19
+ title,
20
+ envStage,
21
+ envPulse = true,
22
+ }) => {
23
+ return (
24
+ <>
25
+ <div
26
+ className={cn(
27
+ "fixed inset-0 z-[90] bg-[var(--overlay)] sm:hidden",
28
+ open ? "opacity-100" : "pointer-events-none opacity-0",
29
+ "transition-opacity duration-200 motion-reduce:transition-none"
30
+ )}
31
+ hidden={!open}
32
+ onClick={onClose}
33
+ aria-hidden="true"
34
+ />
35
+ <aside
36
+ id="vps-embedded-chat-panel"
37
+ className={cn(
38
+ "fixed inset-y-0 right-0 z-[100] flex w-full max-w-[440px] flex-col border-l border-border bg-card shadow-xl",
39
+ "transition-transform duration-300 ease-out motion-reduce:transition-none",
40
+ open ? "translate-x-0" : "translate-x-full"
41
+ )}
42
+ aria-hidden={!open}
43
+ >
44
+ {open && (
45
+ <ChatPanel
46
+ onClose={onClose}
47
+ title={title || "VPS AI Assistant"}
48
+ subtitle={subtitle}
49
+ envStage={envStage}
50
+ envPulse={envPulse}
51
+ />
52
+ )}
53
+ </aside>
54
+ </>
55
+ );
56
+ };
@@ -0,0 +1,167 @@
1
+ import React, { useEffect, useRef, useState } from "react";
2
+ import { MessageSquare } from "lucide-react";
3
+
4
+ const DRAG_THRESHOLD_PX = 5;
5
+ const EDGE_PADDING_PX = 8;
6
+ const POSITION_STORAGE_KEY = "vps-embedded-assistant-top";
7
+
8
+ function clamp(value: number, min: number, max: number) {
9
+ return Math.min(max, Math.max(min, value));
10
+ }
11
+
12
+ function clampToViewport(nextTop: number, height: number) {
13
+ const maxTop = Math.max(
14
+ EDGE_PADDING_PX,
15
+ window.innerHeight - height - EDGE_PADDING_PX
16
+ );
17
+ return clamp(nextTop, EDGE_PADDING_PX, maxTop);
18
+ }
19
+
20
+ function readStoredTop(): number | null {
21
+ try {
22
+ const stored = window.localStorage.getItem(POSITION_STORAGE_KEY);
23
+ if (!stored) return null;
24
+ const parsed = Number(stored);
25
+ return Number.isFinite(parsed) ? parsed : null;
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ function persistTop(top: number) {
32
+ try {
33
+ window.localStorage.setItem(POSITION_STORAGE_KEY, String(top));
34
+ } catch {
35
+ // Ignore quota / private-mode failures.
36
+ }
37
+ }
38
+
39
+ interface EmbeddedChatbotTriggerProps {
40
+ onOpen: () => void;
41
+ }
42
+
43
+ export const EmbeddedChatbotTrigger: React.FC<EmbeddedChatbotTriggerProps> = ({
44
+ onOpen,
45
+ }) => {
46
+ const buttonRef = useRef<HTMLButtonElement>(null);
47
+ const dragRef = useRef({
48
+ pointerId: null as number | null,
49
+ startY: 0,
50
+ startTop: 0,
51
+ moved: false,
52
+ });
53
+ const [top, setTop] = useState<number | null>(() =>
54
+ typeof window === "undefined" ? null : readStoredTop()
55
+ );
56
+ const topRef = useRef(top);
57
+ const suppressClickRef = useRef(false);
58
+ const [dragging, setDragging] = useState(false);
59
+
60
+ useEffect(() => {
61
+ topRef.current = top;
62
+ }, [top]);
63
+
64
+ useEffect(() => {
65
+ const button = buttonRef.current;
66
+ if (!button) return;
67
+
68
+ const applyBounds = () => {
69
+ setTop((current) => {
70
+ const fallback =
71
+ current ??
72
+ Math.round(window.innerHeight / 2 - button.offsetHeight / 2);
73
+ const next = clampToViewport(fallback, button.offsetHeight);
74
+ topRef.current = next;
75
+ return next;
76
+ });
77
+ };
78
+
79
+ applyBounds();
80
+ window.addEventListener("resize", applyBounds);
81
+ return () => window.removeEventListener("resize", applyBounds);
82
+ }, []);
83
+
84
+ const handlePointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {
85
+ if (event.button !== 0) return;
86
+ const button = event.currentTarget;
87
+ const rect = button.getBoundingClientRect();
88
+ dragRef.current = {
89
+ pointerId: event.pointerId,
90
+ startY: event.clientY,
91
+ startTop: rect.top,
92
+ moved: false,
93
+ };
94
+ try {
95
+ button.setPointerCapture(event.pointerId);
96
+ } catch {
97
+ // jsdom and some browsers may not implement pointer capture.
98
+ }
99
+ };
100
+
101
+ const handlePointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {
102
+ if (dragRef.current.pointerId !== event.pointerId) return;
103
+ const deltaY = event.clientY - dragRef.current.startY;
104
+ if (!dragRef.current.moved && Math.abs(deltaY) < DRAG_THRESHOLD_PX) return;
105
+
106
+ dragRef.current.moved = true;
107
+ setDragging(true);
108
+ const nextTop = clampToViewport(
109
+ dragRef.current.startTop + deltaY,
110
+ event.currentTarget.offsetHeight
111
+ );
112
+ topRef.current = nextTop;
113
+ setTop(nextTop);
114
+ };
115
+
116
+ const finishPointer = (event: React.PointerEvent<HTMLButtonElement>) => {
117
+ if (dragRef.current.pointerId !== event.pointerId) return;
118
+ try {
119
+ if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
120
+ event.currentTarget.releasePointerCapture(event.pointerId);
121
+ }
122
+ } catch {
123
+ // Ignore missing pointer-capture support.
124
+ }
125
+
126
+ const wasDrag = dragRef.current.moved;
127
+ dragRef.current.pointerId = null;
128
+ dragRef.current.moved = false;
129
+ setDragging(false);
130
+
131
+ if (wasDrag) {
132
+ suppressClickRef.current = true;
133
+ if (topRef.current != null) persistTop(topRef.current);
134
+ }
135
+ };
136
+
137
+ return (
138
+ <button
139
+ ref={buttonRef}
140
+ type="button"
141
+ onPointerDown={handlePointerDown}
142
+ onPointerMove={handlePointerMove}
143
+ onPointerUp={finishPointer}
144
+ onPointerCancel={finishPointer}
145
+ onClick={() => {
146
+ if (suppressClickRef.current) {
147
+ suppressClickRef.current = false;
148
+ return;
149
+ }
150
+ onOpen();
151
+ }}
152
+ aria-expanded={false}
153
+ aria-controls="vps-embedded-chat-panel"
154
+ aria-label="Assistant"
155
+ className={`fixed right-0 z-[80] flex touch-none items-center gap-2 rounded-l-lg bg-action px-3 py-2.5 text-[12.5px] font-semibold text-action-foreground shadow-lg hover:bg-[var(--action-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${
156
+ dragging ? "cursor-grabbing" : "cursor-grab"
157
+ }`}
158
+ style={{
159
+ top: top ?? "50%",
160
+ transform: top == null ? "translateY(-50%)" : undefined,
161
+ }}
162
+ >
163
+ <MessageSquare size={16} />
164
+ Assistant
165
+ </button>
166
+ );
167
+ };
@@ -0,0 +1,5 @@
1
+ import { useChatContext } from "../core/ChatContext";
2
+
3
+ export function useChatbot() {
4
+ return useChatContext();
5
+ }
@@ -0,0 +1,7 @@
1
+ export { ChatProvider } from "./core/ChatProvider";
2
+ export { useChatbot } from "./hooks/useChatbot";
3
+ export { ChatbotWidget } from "./widget/ChatbotWidget";
4
+ export { EmbeddedChatbot } from "./embedded/EmbeddedChatbot";
5
+ export { chatApi } from "./api/chatbot-api";
6
+ export { ColorPalette } from "./config/colors";
7
+ export type { ChatUserContext, ChatMessage } from "./api/chatbot-types";
@@ -0,0 +1,43 @@
1
+ import React, { useState } from "react";
2
+ import { ChatbotWidgetPanel } from "./ChatbotWidgetPanel";
3
+ import { ChatbotWidgetTrigger } from "./ChatbotWidgetTrigger";
4
+ import { type EnvStage } from "../../components/EnvBadge";
5
+
6
+ interface ChatbotWidgetProps {
7
+ defaultOpen?: boolean;
8
+ open?: boolean;
9
+ onOpenChange?: (open: boolean) => void;
10
+ /** Environment badge stage. Omit for production. */
11
+ envStage?: EnvStage;
12
+ envPulse?: boolean;
13
+ }
14
+
15
+ export const ChatbotWidget: React.FC<ChatbotWidgetProps> = ({
16
+ defaultOpen = false,
17
+ open,
18
+ onOpenChange,
19
+ envStage,
20
+ envPulse = true,
21
+ }) => {
22
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
23
+ const isOpen = open ?? uncontrolledOpen;
24
+
25
+ const setOpen = (next: boolean) => {
26
+ onOpenChange?.(next);
27
+ if (open === undefined) {
28
+ setUncontrolledOpen(next);
29
+ }
30
+ };
31
+
32
+ return (
33
+ <>
34
+ <ChatbotWidgetPanel
35
+ open={isOpen}
36
+ onClose={() => setOpen(false)}
37
+ envStage={envStage}
38
+ envPulse={envPulse}
39
+ />
40
+ <ChatbotWidgetTrigger open={isOpen} onToggle={() => setOpen(!isOpen)} />
41
+ </>
42
+ );
43
+ };
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+ import { ChatPanel } from "../core/ChatPanel";
3
+ import { cn } from "../../lib/cn";
4
+ import { type EnvStage } from "../../components/EnvBadge";
5
+
6
+ interface ChatbotWidgetPanelProps {
7
+ open: boolean;
8
+ onClose: () => void;
9
+ envStage?: EnvStage;
10
+ envPulse?: boolean;
11
+ }
12
+
13
+ export const ChatbotWidgetPanel: React.FC<ChatbotWidgetPanelProps> = ({
14
+ open,
15
+ onClose,
16
+ envStage,
17
+ envPulse = true,
18
+ }) => {
19
+ if (!open) return null;
20
+
21
+ return (
22
+ <div
23
+ id="vps-chatbot-widget-panel"
24
+ className={cn(
25
+ "fixed bottom-[98px] right-7 z-[999] flex h-[min(660px,calc(100vh-120px))] w-[min(420px,calc(100vw-32px))] flex-col overflow-hidden rounded-[20px] border border-border bg-card",
26
+ "shadow-[0_20px_40px_-15px_rgba(0,0,0,0.12)]",
27
+ "origin-bottom-right animate-[chat-pop_180ms_ease-out] motion-reduce:animate-none"
28
+ )}
29
+ >
30
+ <ChatPanel
31
+ onClose={onClose}
32
+ showMinimize
33
+ title="VPS AI Assistant"
34
+ envStage={envStage}
35
+ envPulse={envPulse}
36
+ />
37
+ </div>
38
+ );
39
+ };
@@ -0,0 +1,32 @@
1
+ import React from "react";
2
+ import { MessageSquare, X } from "lucide-react";
3
+ import { cn } from "../../lib/cn";
4
+
5
+ interface ChatbotWidgetTriggerProps {
6
+ open: boolean;
7
+ onToggle: () => void;
8
+ }
9
+
10
+ export const ChatbotWidgetTrigger: React.FC<ChatbotWidgetTriggerProps> = ({
11
+ open,
12
+ onToggle,
13
+ }) => {
14
+ return (
15
+ <button
16
+ type="button"
17
+ onClick={onToggle}
18
+ aria-expanded={open}
19
+ aria-controls="vps-chatbot-widget-panel"
20
+ aria-label={open ? "Close assistant" : "Open assistant"}
21
+ className={cn(
22
+ "fixed bottom-7 right-7 z-[1000] flex h-[58px] w-[58px] items-center justify-center rounded-xl text-primary-foreground",
23
+ "bg-primary hover:bg-[var(--primary-hover)]",
24
+ "shadow-md",
25
+ "transition duration-200 motion-reduce:transition-none motion-reduce:hover:scale-100",
26
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-primary"
27
+ )}
28
+ >
29
+ {open ? <X size={22} /> : <MessageSquare size={24} />}
30
+ </button>
31
+ );
32
+ };
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ import { Clock } from "lucide-react";
3
+
4
+ interface AgentSummaryCardProps {
5
+ agentName?: string;
6
+ agentInitials?: string;
7
+ duration?: string;
8
+ }
9
+
10
+ export const AgentSummaryCard: React.FC<AgentSummaryCardProps> = ({
11
+ agentName = "Fikri Studio",
12
+ agentInitials = "FIK",
13
+ duration = "12 Mins 23 Sec",
14
+ }) => {
15
+ return (
16
+ <div className="summary-talk-card">
17
+ <h3 className="summary-talk-title">Summary talk with agent</h3>
18
+ <div className="summary-talk-grid">
19
+ <div className="summary-talk-col">
20
+ <span className="summary-talk-label">Chat with</span>
21
+ <div className="summary-agent-info">
22
+ <span className="summary-agent-avatar">{agentInitials}</span>
23
+ <span className="summary-agent-name">{agentName}</span>
24
+ </div>
25
+ </div>
26
+
27
+ <div className="summary-talk-col">
28
+ <span className="summary-talk-label">Chat Duration</span>
29
+ <div className="summary-duration-info">
30
+ <Clock size={15} className="summary-clock-icon" />
31
+ <span className="summary-duration-text">{duration}</span>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ );
37
+ };
@@ -0,0 +1,142 @@
1
+ import React from "react";
2
+ import { ArrowLeft, Clock, RefreshCw, Minus, Bot } from "lucide-react";
3
+ import { EnvBadge, EnvStage } from "./EnvBadge";
4
+
5
+ export type HeaderMode = "bot" | "agent" | "ended";
6
+
7
+ interface ChatHeaderProps {
8
+ headerMode?: HeaderMode;
9
+ ticketId?: string;
10
+ subtitle?: string;
11
+ duration?: string;
12
+ agentInitials?: string;
13
+ onBack?: () => void;
14
+ onReset?: () => void;
15
+ onClose?: () => void;
16
+ isFloating?: boolean;
17
+ /** Environment stage badge — omit for production */
18
+ envStage?: EnvStage;
19
+ /** Whether the status dot inside the badge pulses. Default: true */
20
+ envPulse?: boolean;
21
+ }
22
+
23
+ export const ChatHeader: React.FC<ChatHeaderProps> = ({
24
+ headerMode = "bot",
25
+ ticketId = "#TC-192",
26
+ subtitle = "Help, I order wrong product",
27
+ duration = "2:02",
28
+ agentInitials = "FIK",
29
+ onBack,
30
+ onReset,
31
+ onClose,
32
+ isFloating,
33
+ envStage,
34
+ envPulse = true,
35
+ }) => {
36
+ return (
37
+ <div className="chat-header">
38
+ <div className="chat-header-left">
39
+ <button
40
+ className="header-back-btn"
41
+ onClick={onBack}
42
+ title="Go back"
43
+ aria-label="Back"
44
+ >
45
+ <ArrowLeft size={18} />
46
+ </button>
47
+
48
+ {headerMode === "bot" ? (
49
+ <div className="header-title-container">
50
+ <div className="header-title-row">
51
+ <h1 className="header-title-main">Chat Bot</h1>
52
+ {/* ── Env badge lives right next to the title ── */}
53
+ <EnvBadge stage={envStage} pulse={envPulse} />
54
+ </div>
55
+ </div>
56
+ ) : (
57
+ <div className="header-title-container">
58
+ <div className="header-title-row">
59
+ <div className="header-ticket-title">{ticketId}</div>
60
+ {/* ── Env badge next to ticket id ── */}
61
+ <EnvBadge stage={envStage} pulse={envPulse} />
62
+ </div>
63
+ <div className="header-ticket-subtitle">{subtitle}</div>
64
+ </div>
65
+ )}
66
+ </div>
67
+
68
+ <div className="chat-header-right">
69
+ {headerMode === "agent" && (
70
+ <div className="header-timer-badge">
71
+ <Clock size={13} />
72
+ <span>{duration}</span>
73
+ </div>
74
+ )}
75
+
76
+ {headerMode === "ended" && (
77
+ <div className="header-ended-badge">
78
+ <Clock size={13} />
79
+ <span>Ended</span>
80
+ </div>
81
+ )}
82
+
83
+ {/* Dual Avatars Badge */}
84
+ <div className="header-avatar-badge-group">
85
+ {headerMode === "bot" ? (
86
+ <>
87
+ <div className="header-avatar-bot">
88
+ <Bot size={14} />
89
+ </div>
90
+ <div className="header-avatar-user-overlap">
91
+ <img
92
+ src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=100&auto=format&fit=crop&q=80"
93
+ alt="User"
94
+ className="header-avatar-img"
95
+ onError={(e) => {
96
+ e.currentTarget.style.display = "none";
97
+ }}
98
+ />
99
+ </div>
100
+ </>
101
+ ) : (
102
+ <>
103
+ <div className="header-avatar-agent-tag">{agentInitials}</div>
104
+ <div className="header-avatar-user-overlap">
105
+ <img
106
+ src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=100&auto=format&fit=crop&q=80"
107
+ alt="Agent"
108
+ className="header-avatar-img"
109
+ onError={(e) => {
110
+ e.currentTarget.style.display = "none";
111
+ }}
112
+ />
113
+ </div>
114
+ </>
115
+ )}
116
+ </div>
117
+
118
+ {onReset && (
119
+ <button
120
+ className="header-icon-action-btn"
121
+ onClick={onReset}
122
+ title="Start New Conversation"
123
+ aria-label="New Session"
124
+ >
125
+ <RefreshCw size={15} />
126
+ </button>
127
+ )}
128
+
129
+ {isFloating && onClose && (
130
+ <button
131
+ className="header-icon-action-btn"
132
+ onClick={onClose}
133
+ title="Minimize"
134
+ aria-label="Minimize"
135
+ >
136
+ <Minus size={15} />
137
+ </button>
138
+ )}
139
+ </div>
140
+ </div>
141
+ );
142
+ };