@aigentyc/chat-sdk 0.1.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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -0
  3. package/dist/JsonRenderResult-Ftw4AKwb.d.cts +18 -0
  4. package/dist/JsonRenderResult-Ftw4AKwb.d.ts +18 -0
  5. package/dist/JsonRenderResult-GQOYPLVH.cjs +15 -0
  6. package/dist/JsonRenderResult-GQOYPLVH.cjs.map +1 -0
  7. package/dist/JsonRenderResult-ZFJ6VWMS.js +6 -0
  8. package/dist/JsonRenderResult-ZFJ6VWMS.js.map +1 -0
  9. package/dist/SlotsContext-CBtt36al.d.ts +148 -0
  10. package/dist/SlotsContext-CHvISDJT.d.cts +148 -0
  11. package/dist/VisualizationRenderer-FNFYNN66.js +5 -0
  12. package/dist/VisualizationRenderer-FNFYNN66.js.map +1 -0
  13. package/dist/VisualizationRenderer-VKMZXRUX.cjs +20 -0
  14. package/dist/VisualizationRenderer-VKMZXRUX.cjs.map +1 -0
  15. package/dist/ai-elements.cjs +4608 -0
  16. package/dist/ai-elements.cjs.map +1 -0
  17. package/dist/ai-elements.d.cts +897 -0
  18. package/dist/ai-elements.d.ts +897 -0
  19. package/dist/ai-elements.js +4363 -0
  20. package/dist/ai-elements.js.map +1 -0
  21. package/dist/chunk-3MP2EGEJ.cjs +270 -0
  22. package/dist/chunk-3MP2EGEJ.cjs.map +1 -0
  23. package/dist/chunk-3RW7O444.js +26 -0
  24. package/dist/chunk-3RW7O444.js.map +1 -0
  25. package/dist/chunk-42ARGQXE.js +51 -0
  26. package/dist/chunk-42ARGQXE.js.map +1 -0
  27. package/dist/chunk-4FBVV64J.js +257 -0
  28. package/dist/chunk-4FBVV64J.js.map +1 -0
  29. package/dist/chunk-4QT25AXI.js +21 -0
  30. package/dist/chunk-4QT25AXI.js.map +1 -0
  31. package/dist/chunk-525KS5HM.cjs +30 -0
  32. package/dist/chunk-525KS5HM.cjs.map +1 -0
  33. package/dist/chunk-5F3O3ZJH.js +299 -0
  34. package/dist/chunk-5F3O3ZJH.js.map +1 -0
  35. package/dist/chunk-5QSXB6UL.cjs +259 -0
  36. package/dist/chunk-5QSXB6UL.cjs.map +1 -0
  37. package/dist/chunk-5T4FJ2SR.js +664 -0
  38. package/dist/chunk-5T4FJ2SR.js.map +1 -0
  39. package/dist/chunk-7BNYTOTE.cjs +67 -0
  40. package/dist/chunk-7BNYTOTE.cjs.map +1 -0
  41. package/dist/chunk-AWAJOSFP.cjs +96 -0
  42. package/dist/chunk-AWAJOSFP.cjs.map +1 -0
  43. package/dist/chunk-BKDV2H6Z.js +224 -0
  44. package/dist/chunk-BKDV2H6Z.js.map +1 -0
  45. package/dist/chunk-FQN6OBGN.cjs +171 -0
  46. package/dist/chunk-FQN6OBGN.cjs.map +1 -0
  47. package/dist/chunk-FYPJSHCL.js +190 -0
  48. package/dist/chunk-FYPJSHCL.js.map +1 -0
  49. package/dist/chunk-J2H6MLQF.cjs +680 -0
  50. package/dist/chunk-J2H6MLQF.cjs.map +1 -0
  51. package/dist/chunk-J2K7EJYP.cjs +198 -0
  52. package/dist/chunk-J2K7EJYP.cjs.map +1 -0
  53. package/dist/chunk-JI5KCSOI.cjs +23 -0
  54. package/dist/chunk-JI5KCSOI.cjs.map +1 -0
  55. package/dist/chunk-JOO6C3XT.cjs +44 -0
  56. package/dist/chunk-JOO6C3XT.cjs.map +1 -0
  57. package/dist/chunk-KBGPBUTI.cjs +78 -0
  58. package/dist/chunk-KBGPBUTI.cjs.map +1 -0
  59. package/dist/chunk-MT2AMINB.js +75 -0
  60. package/dist/chunk-MT2AMINB.js.map +1 -0
  61. package/dist/chunk-MZQKGNWF.js +4 -0
  62. package/dist/chunk-MZQKGNWF.js.map +1 -0
  63. package/dist/chunk-NG7OTWXQ.cjs +226 -0
  64. package/dist/chunk-NG7OTWXQ.cjs.map +1 -0
  65. package/dist/chunk-NPJKLYLV.js +68 -0
  66. package/dist/chunk-NPJKLYLV.js.map +1 -0
  67. package/dist/chunk-NW2ESHRV.js +685 -0
  68. package/dist/chunk-NW2ESHRV.js.map +1 -0
  69. package/dist/chunk-NWF735F5.js +1631 -0
  70. package/dist/chunk-NWF735F5.js.map +1 -0
  71. package/dist/chunk-NYQSM3EB.cjs +305 -0
  72. package/dist/chunk-NYQSM3EB.cjs.map +1 -0
  73. package/dist/chunk-OU7OROOE.cjs +1643 -0
  74. package/dist/chunk-OU7OROOE.cjs.map +1 -0
  75. package/dist/chunk-PS3U7T37.js +42 -0
  76. package/dist/chunk-PS3U7T37.js.map +1 -0
  77. package/dist/chunk-Q7T3VAJV.cjs +687 -0
  78. package/dist/chunk-Q7T3VAJV.cjs.map +1 -0
  79. package/dist/chunk-QYCEHFAB.js +265 -0
  80. package/dist/chunk-QYCEHFAB.js.map +1 -0
  81. package/dist/chunk-RPDJXB3U.js +676 -0
  82. package/dist/chunk-RPDJXB3U.js.map +1 -0
  83. package/dist/chunk-UKEL7FWS.js +64 -0
  84. package/dist/chunk-UKEL7FWS.js.map +1 -0
  85. package/dist/chunk-VS3NZ7FX.js +164 -0
  86. package/dist/chunk-VS3NZ7FX.js.map +1 -0
  87. package/dist/chunk-WZLWAVSS.cjs +73 -0
  88. package/dist/chunk-WZLWAVSS.cjs.map +1 -0
  89. package/dist/chunk-X5YEOOPK.cjs +758 -0
  90. package/dist/chunk-X5YEOOPK.cjs.map +1 -0
  91. package/dist/chunk-X7R334SB.cjs +5 -0
  92. package/dist/chunk-X7R334SB.cjs.map +1 -0
  93. package/dist/chunk-XXNDL5SJ.cjs +432 -0
  94. package/dist/chunk-XXNDL5SJ.cjs.map +1 -0
  95. package/dist/chunk-YQELMJW5.js +429 -0
  96. package/dist/chunk-YQELMJW5.js.map +1 -0
  97. package/dist/components.cjs +551 -0
  98. package/dist/components.cjs.map +1 -0
  99. package/dist/components.d.cts +181 -0
  100. package/dist/components.d.ts +181 -0
  101. package/dist/components.js +483 -0
  102. package/dist/components.js.map +1 -0
  103. package/dist/core.cjs +283 -0
  104. package/dist/core.cjs.map +1 -0
  105. package/dist/core.d.cts +455 -0
  106. package/dist/core.d.ts +455 -0
  107. package/dist/core.js +241 -0
  108. package/dist/core.js.map +1 -0
  109. package/dist/hooks.cjs +324 -0
  110. package/dist/hooks.cjs.map +1 -0
  111. package/dist/hooks.d.cts +163 -0
  112. package/dist/hooks.d.ts +163 -0
  113. package/dist/hooks.js +277 -0
  114. package/dist/hooks.js.map +1 -0
  115. package/dist/i18n.cjs +26 -0
  116. package/dist/i18n.cjs.map +1 -0
  117. package/dist/i18n.d.cts +50 -0
  118. package/dist/i18n.d.ts +50 -0
  119. package/dist/i18n.js +5 -0
  120. package/dist/i18n.js.map +1 -0
  121. package/dist/index.cjs +466 -0
  122. package/dist/index.cjs.map +1 -0
  123. package/dist/index.d.cts +80 -0
  124. package/dist/index.d.ts +80 -0
  125. package/dist/index.js +438 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/interaction-tracker-D9P1Oq4j.d.cts +83 -0
  128. package/dist/interaction-tracker-D9P1Oq4j.d.ts +83 -0
  129. package/dist/json-render.cjs +23 -0
  130. package/dist/json-render.cjs.map +1 -0
  131. package/dist/json-render.d.cts +857 -0
  132. package/dist/json-render.d.ts +857 -0
  133. package/dist/json-render.js +6 -0
  134. package/dist/json-render.js.map +1 -0
  135. package/dist/live-chat-transport-4XLOIPOE.js +4 -0
  136. package/dist/live-chat-transport-4XLOIPOE.js.map +1 -0
  137. package/dist/live-chat-transport-ALVRGWX7.cjs +13 -0
  138. package/dist/live-chat-transport-ALVRGWX7.cjs.map +1 -0
  139. package/dist/select-B4l9yoyn.d.cts +99 -0
  140. package/dist/select-B4l9yoyn.d.ts +99 -0
  141. package/dist/styles.css +2 -0
  142. package/dist/theme.cjs +18 -0
  143. package/dist/theme.cjs.map +1 -0
  144. package/dist/theme.d.cts +55 -0
  145. package/dist/theme.d.ts +55 -0
  146. package/dist/theme.js +5 -0
  147. package/dist/theme.js.map +1 -0
  148. package/dist/tools.cjs +32 -0
  149. package/dist/tools.cjs.map +1 -0
  150. package/dist/tools.d.cts +117 -0
  151. package/dist/tools.d.ts +117 -0
  152. package/dist/tools.js +11 -0
  153. package/dist/tools.js.map +1 -0
  154. package/dist/types-DKJ_-nbG.d.cts +349 -0
  155. package/dist/types-DKJ_-nbG.d.ts +349 -0
  156. package/dist/ui.cjs +667 -0
  157. package/dist/ui.cjs.map +1 -0
  158. package/dist/ui.d.cts +95 -0
  159. package/dist/ui.d.ts +95 -0
  160. package/dist/ui.js +414 -0
  161. package/dist/ui.js.map +1 -0
  162. package/package.json +255 -0
@@ -0,0 +1,1631 @@
1
+ "use client";
2
+ import { useIsMobile, useLiveChat, usePreviewEmbed } from './chunk-5F3O3ZJH.js';
3
+ import { useTheme } from './chunk-UKEL7FWS.js';
4
+ import { Conversation, ConversationContent, Loader } from './chunk-VS3NZ7FX.js';
5
+ import { useI18n } from './chunk-QYCEHFAB.js';
6
+ import { ToolRenderer } from './chunk-YQELMJW5.js';
7
+ import { useChatContext, useSlots, renderSlot } from './chunk-FYPJSHCL.js';
8
+ import { cn } from './chunk-3RW7O444.js';
9
+ import { memo, useState, useRef, useEffect, useCallback, useMemo } from 'react';
10
+ import { X, ArrowLeft, ShoppingCart, Plus, Ticket, FerrisWheel, Flag, Building, Heart, Star, Calendar, MapPin, Hotel, Coffee, Utensils, Settings, Users, FileText, HelpCircle, Search, Zap, MessageSquare, Shield, Minus, Trash2, SparklesIcon, Headset, Send, ThumbsUp, ThumbsDown, ExternalLink } from 'lucide-react';
11
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
12
+
13
+ function BotIcon({ className }) {
14
+ return /* @__PURE__ */ jsxs("svg", { className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
15
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "8", width: "18", height: "12", rx: "2" }),
16
+ /* @__PURE__ */ jsx("circle", { cx: "8.5", cy: "14", r: "1" }),
17
+ /* @__PURE__ */ jsx("circle", { cx: "15.5", cy: "14", r: "1" }),
18
+ /* @__PURE__ */ jsx("path", { d: "M12 4v4" }),
19
+ /* @__PURE__ */ jsx("path", { d: "M8 2h8" })
20
+ ] });
21
+ }
22
+ var ChatHeader = memo(function ChatHeader2({
23
+ isWelcome = false,
24
+ onNewConversation,
25
+ onClose,
26
+ clientName,
27
+ logoUrl,
28
+ cartCount,
29
+ onCartClick
30
+ }) {
31
+ const { t, direction } = useI18n();
32
+ const ctx = useChatContext();
33
+ const displayName = clientName || ctx.config.clientName || "AI Assistant";
34
+ const LogoOrIcon = () => {
35
+ if (logoUrl) {
36
+ return /* @__PURE__ */ jsx(
37
+ "img",
38
+ {
39
+ src: logoUrl,
40
+ alt: displayName,
41
+ className: "max-h-[40px] w-auto max-w-[120px] object-contain"
42
+ }
43
+ );
44
+ }
45
+ return /* @__PURE__ */ jsx(BotIcon, { className: "w-6 h-6" });
46
+ };
47
+ const SmallLogoOrIcon = () => {
48
+ if (logoUrl) {
49
+ return /* @__PURE__ */ jsx(
50
+ "img",
51
+ {
52
+ src: logoUrl,
53
+ alt: displayName,
54
+ className: "h-5 w-auto max-w-[100px] object-contain"
55
+ }
56
+ );
57
+ }
58
+ return /* @__PURE__ */ jsx(BotIcon, { className: "w-5 h-5" });
59
+ };
60
+ const handleCloseAction = () => {
61
+ onClose?.();
62
+ if (typeof document !== "undefined") {
63
+ const event = new CustomEvent("aigentyc:close-chat", {
64
+ bubbles: true,
65
+ composed: true
66
+ });
67
+ document.dispatchEvent(event);
68
+ }
69
+ };
70
+ if (isWelcome) {
71
+ return /* @__PURE__ */ jsxs(
72
+ "header",
73
+ {
74
+ className: "flex items-center justify-between px-6 py-4 border-b",
75
+ style: { background: "var(--ac-background)", borderColor: "var(--ac-border)" },
76
+ children: [
77
+ /* @__PURE__ */ jsx(
78
+ "button",
79
+ {
80
+ type: "button",
81
+ onClick: handleCloseAction,
82
+ className: "p-1 hover:bg-secondary rounded transition-colors",
83
+ children: /* @__PURE__ */ jsx(X, { className: "w-6 h-6" })
84
+ }
85
+ ),
86
+ logoUrl ? /* @__PURE__ */ jsxs(Fragment, { children: [
87
+ /* @__PURE__ */ jsx("span", { className: "text-lg font-medium", children: displayName }),
88
+ /* @__PURE__ */ jsx(LogoOrIcon, {})
89
+ ] }) : /* @__PURE__ */ jsx("span", { className: "text-lg font-medium", children: displayName }),
90
+ !logoUrl && /* @__PURE__ */ jsx(BotIcon, { className: "w-6 h-6" })
91
+ ]
92
+ }
93
+ );
94
+ }
95
+ return /* @__PURE__ */ jsxs(
96
+ "header",
97
+ {
98
+ className: "flex items-center justify-between px-6 py-4 border-b",
99
+ style: { background: "var(--ac-background)", borderColor: "var(--ac-border)" },
100
+ children: [
101
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
102
+ /* @__PURE__ */ jsx(
103
+ "button",
104
+ {
105
+ type: "button",
106
+ onClick: onNewConversation,
107
+ className: "p-2 hover:bg-secondary rounded-lg transition-colors",
108
+ title: t("backToStart"),
109
+ children: /* @__PURE__ */ jsx(ArrowLeft, { className: cn("w-5 h-5", direction === "rtl" && "rotate-180") })
110
+ }
111
+ ),
112
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
113
+ /* @__PURE__ */ jsx(SmallLogoOrIcon, {}),
114
+ !logoUrl && /* @__PURE__ */ jsx("span", { className: "font-medium text-sm", children: displayName })
115
+ ] })
116
+ ] }),
117
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
118
+ cartCount !== void 0 && cartCount >= 0 && onCartClick && /* @__PURE__ */ jsxs(
119
+ "button",
120
+ {
121
+ type: "button",
122
+ onClick: onCartClick,
123
+ className: "relative p-2 hover:bg-secondary rounded-lg transition-colors",
124
+ title: t("cart"),
125
+ children: [
126
+ /* @__PURE__ */ jsx(ShoppingCart, { className: "w-5 h-5" }),
127
+ cartCount > 0 && /* @__PURE__ */ jsx("span", { className: "absolute -top-0.5 -end-0.5 min-w-[18px] h-[18px] flex items-center justify-center bg-red-500 text-white text-[10px] font-bold rounded-full px-1", children: cartCount })
128
+ ]
129
+ }
130
+ ),
131
+ /* @__PURE__ */ jsx(
132
+ "button",
133
+ {
134
+ type: "button",
135
+ onClick: onNewConversation,
136
+ className: "p-2 hover:bg-secondary rounded-lg transition-colors",
137
+ title: t("newConversation"),
138
+ children: /* @__PURE__ */ jsx(Plus, { className: "w-5 h-5" })
139
+ }
140
+ ),
141
+ /* @__PURE__ */ jsx(
142
+ "button",
143
+ {
144
+ type: "button",
145
+ onClick: handleCloseAction,
146
+ className: "p-2 hover:bg-secondary rounded-lg transition-colors",
147
+ title: t("closeChat"),
148
+ children: /* @__PURE__ */ jsx(X, { className: "w-5 h-5" })
149
+ }
150
+ )
151
+ ] })
152
+ ]
153
+ }
154
+ );
155
+ });
156
+ var ChatInput = memo(function ChatInput2({
157
+ value,
158
+ onChange,
159
+ onSubmit,
160
+ isProcessing = false,
161
+ placeholder
162
+ }) {
163
+ const [isFocused, setIsFocused] = useState(false);
164
+ const { t, direction } = useI18n();
165
+ const handleKeyDown = (e) => {
166
+ if (e.key === "Enter" && value.trim() && !isProcessing) {
167
+ e.preventDefault();
168
+ onSubmit(value);
169
+ }
170
+ };
171
+ const hasValue = value.trim().length > 0;
172
+ return /* @__PURE__ */ jsxs(
173
+ "div",
174
+ {
175
+ className: `
176
+ relative flex items-center gap-3
177
+ rounded-2xl
178
+ border-2 transition-all duration-300
179
+ ${isFocused ? "shadow-lg" : "shadow-md hover:shadow-lg"}
180
+ ps-4 md:ps-5 pe-1.5 md:pe-2
181
+ `,
182
+ style: {
183
+ backgroundColor: "var(--ac-background)",
184
+ borderColor: isFocused ? "var(--ac-primary)" : "var(--ac-border, #e8e8e8)"
185
+ },
186
+ children: [
187
+ /* @__PURE__ */ jsx(
188
+ "div",
189
+ {
190
+ className: "shrink-0 transition-colors duration-300",
191
+ style: { color: isFocused ? "var(--ac-primary)" : "#a0a0a0" },
192
+ children: /* @__PURE__ */ jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
193
+ /* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "8" }),
194
+ /* @__PURE__ */ jsx("path", { d: "m21 21-4.3-4.3" })
195
+ ] })
196
+ }
197
+ ),
198
+ /* @__PURE__ */ jsx(
199
+ "input",
200
+ {
201
+ dir: direction,
202
+ type: "text",
203
+ value,
204
+ onChange: (e) => onChange(e.target.value),
205
+ onKeyDown: handleKeyDown,
206
+ onFocus: () => setIsFocused(true),
207
+ onBlur: () => setIsFocused(false),
208
+ disabled: isProcessing,
209
+ placeholder: placeholder || t("typeMessage"),
210
+ className: "\n flex-1 bg-transparent text-start\n outline-none text-base\n min-h-[52px] md:min-h-[60px]\n disabled:opacity-50\n ",
211
+ style: { color: "var(--ac-text)" }
212
+ }
213
+ ),
214
+ /* @__PURE__ */ jsx(
215
+ "button",
216
+ {
217
+ type: "button",
218
+ onClick: () => onSubmit(value),
219
+ disabled: !hasValue || isProcessing,
220
+ className: `
221
+ group relative flex items-center justify-center
222
+ w-10 h-10 md:w-12 md:h-12
223
+ rounded-xl shrink-0
224
+ transition-all duration-300 overflow-hidden
225
+ ${hasValue && !isProcessing ? "shadow-md hover:shadow-lg hover:scale-105" : "cursor-not-allowed"}
226
+ disabled:hover:scale-100
227
+ `,
228
+ style: {
229
+ backgroundColor: hasValue && !isProcessing ? "var(--ac-primary)" : "#f0f0f0",
230
+ color: hasValue && !isProcessing ? "var(--ac-primary-foreground, #fff)" : "#a0a0a0"
231
+ },
232
+ title: t("send"),
233
+ children: isProcessing ? /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2" }) }) : /* @__PURE__ */ jsxs(
234
+ "svg",
235
+ {
236
+ className: `w-5 h-5 md:w-6 md:h-6 relative z-10 transition-transform duration-300 group-hover:translate-x-0.5 ${direction === "rtl" ? "rotate-180" : ""}`,
237
+ viewBox: "0 0 24 24",
238
+ fill: "none",
239
+ stroke: "currentColor",
240
+ strokeWidth: "2.5",
241
+ strokeLinecap: "round",
242
+ strokeLinejoin: "round",
243
+ children: [
244
+ /* @__PURE__ */ jsx("path", { d: "M5 12h14" }),
245
+ /* @__PURE__ */ jsx("path", { d: "m12 5 7 7-7 7" })
246
+ ]
247
+ }
248
+ )
249
+ }
250
+ )
251
+ ]
252
+ }
253
+ );
254
+ });
255
+ function ChatFooter({ footerText }) {
256
+ const { t } = useI18n();
257
+ return /* @__PURE__ */ jsxs(
258
+ "div",
259
+ {
260
+ className: "flex flex-wrap items-center justify-center gap-1.5 sm:gap-2 py-2 sm:py-3 text-xs sm:text-sm px-4",
261
+ style: { color: "var(--ac-chat-footer-text, #c4c4c4)" },
262
+ children: [
263
+ /* @__PURE__ */ jsx("span", { className: "text-center", children: footerText || t("alwaysVerify") }),
264
+ /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: "|" }),
265
+ /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: t("poweredBy") }),
266
+ /* @__PURE__ */ jsx(
267
+ "a",
268
+ {
269
+ href: "https://aigentyc.ai/",
270
+ target: "_blank",
271
+ rel: "noopener noreferrer",
272
+ className: "font-semibold tracking-tight hover:underline",
273
+ style: { color: "var(--ac-text, inherit)" },
274
+ children: "aiGentyc"
275
+ }
276
+ )
277
+ ]
278
+ }
279
+ );
280
+ }
281
+ var ICON_MAP = {
282
+ Shield,
283
+ MessageSquare,
284
+ Zap,
285
+ Search,
286
+ HelpCircle,
287
+ FileText,
288
+ Users,
289
+ Settings,
290
+ Utensils,
291
+ Coffee,
292
+ Hotel,
293
+ MapPin,
294
+ Calendar,
295
+ Star,
296
+ Heart,
297
+ Building,
298
+ Flag,
299
+ FerrisWheel,
300
+ Ticket
301
+ };
302
+ var DEFAULT_ACTIONS = [
303
+ { id: "about", label: "aboutUs", description: "aboutUsDesc", icon: Shield, query: "aboutUsQuery" },
304
+ { id: "support", label: "support", description: "supportDesc", icon: MessageSquare, query: "supportQuery" },
305
+ { id: "features", label: "features", description: "featuresDesc", icon: Zap, query: "featuresQuery" },
306
+ { id: "search", label: "search", description: "searchDesc", icon: Search, query: "searchQuery" }
307
+ ];
308
+ function WelcomePage({
309
+ onSelectCategory,
310
+ isProcessing = false,
311
+ isOpen = true,
312
+ clientName,
313
+ questions,
314
+ welcomeTitle,
315
+ welcomeSubtitle,
316
+ hideWelcomeHeader = false,
317
+ loading = false,
318
+ questionsLayout = "vertical",
319
+ questionsLayoutMobile
320
+ }) {
321
+ const isMobile = useIsMobile();
322
+ const { t } = useI18n();
323
+ const layout = isMobile && questionsLayoutMobile ? questionsLayoutMobile : questionsLayout;
324
+ const isHorizontal = layout === "horizontal";
325
+ const [shouldAnimate, setShouldAnimate] = useState(false);
326
+ const wasOpenRef = useRef(false);
327
+ const hasCustomQuestions = questions && questions.length > 0;
328
+ useEffect(() => {
329
+ if (isMobile && isOpen && !wasOpenRef.current) {
330
+ const timer = setTimeout(() => setShouldAnimate(true), 350);
331
+ wasOpenRef.current = true;
332
+ return () => clearTimeout(timer);
333
+ }
334
+ if (!isOpen) {
335
+ setShouldAnimate(false);
336
+ wasOpenRef.current = false;
337
+ }
338
+ }, [isMobile, isOpen]);
339
+ const handleActionClick = (action) => {
340
+ if (isProcessing) return;
341
+ onSelectCategory(t(action.query, { clientName }), true);
342
+ };
343
+ const handleCustomQuestionClick = (question) => {
344
+ if (isProcessing) return;
345
+ onSelectCategory(question.query, true);
346
+ };
347
+ return /* @__PURE__ */ jsx(
348
+ "div",
349
+ {
350
+ className: "flex flex-col items-center flex-1 min-h-0 overflow-y-auto px-5 sm:px-[40px] py-6 sm:py-12",
351
+ style: { backgroundColor: "var(--ac-background)" },
352
+ children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-4 sm:gap-8 w-full my-auto", children: [
353
+ !hideWelcomeHeader && /* @__PURE__ */ jsx("div", { className: "text-center max-w-md", children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [
354
+ /* @__PURE__ */ jsx("div", { className: "h-8 sm:h-9 bg-muted rounded-lg w-3/4 mx-auto mb-3 animate-pulse" }),
355
+ /* @__PURE__ */ jsx("div", { className: "h-5 bg-muted rounded w-full mx-auto animate-pulse" })
356
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
357
+ /* @__PURE__ */ jsx("h1", { className: "text-[26px] sm:text-[32px] font-semibold mb-2 sm:mb-3", style: { color: "var(--ac-text)" }, children: welcomeTitle || t("welcomeTitle", { clientName }) }),
358
+ /* @__PURE__ */ jsx("p", { className: "text-[15px] sm:text-lg text-muted-foreground", children: welcomeSubtitle || t("welcomeSubtitle", { clientName }) })
359
+ ] }) }),
360
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-3 w-full max-w-2xl", children: loading ? /* @__PURE__ */ jsx(Fragment, { children: [1, 2, 3, 4].map((i) => /* @__PURE__ */ jsxs(
361
+ "div",
362
+ {
363
+ className: cn(
364
+ "flex gap-3 p-4 border rounded-2xl animate-pulse",
365
+ isHorizontal ? "flex-row items-center" : "flex-col items-center"
366
+ ),
367
+ style: { backgroundColor: "var(--ac-background)", borderColor: "var(--ac-border)" },
368
+ children: [
369
+ /* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-lg bg-muted shrink-0" }),
370
+ /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-1.5 w-full", !isHorizontal && "items-center"), children: [
371
+ /* @__PURE__ */ jsx("div", { className: "h-4 bg-muted rounded w-3/4" }),
372
+ /* @__PURE__ */ jsx("div", { className: "h-3 bg-muted rounded w-1/2" })
373
+ ] })
374
+ ]
375
+ },
376
+ i
377
+ )) }) : hasCustomQuestions ? questions.map((question, index) => {
378
+ const Icon = question.icon ? ICON_MAP[question.icon] || HelpCircle : null;
379
+ return /* @__PURE__ */ jsxs(
380
+ "button",
381
+ {
382
+ type: "button",
383
+ onClick: () => handleCustomQuestionClick(question),
384
+ disabled: isProcessing,
385
+ className: cn(
386
+ "group relative w-full active:scale-[0.98] disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200",
387
+ "flex gap-3 p-4",
388
+ "border rounded-2xl shadow-sm hover:bg-accent",
389
+ isHorizontal ? "flex-row items-center text-start" : "flex-col items-center text-center"
390
+ ),
391
+ style: {
392
+ backgroundColor: question.bgColor || "var(--ac-background)",
393
+ borderColor: "var(--ac-border)",
394
+ ...isMobile ? {
395
+ opacity: shouldAnimate ? 1 : 0,
396
+ transform: shouldAnimate ? "translateY(0)" : "translateY(8px)",
397
+ transition: "opacity 300ms ease-out, transform 300ms ease-out, background-color 150ms",
398
+ transitionDelay: shouldAnimate ? `${index * 60}ms` : "0ms"
399
+ } : {}
400
+ },
401
+ children: [
402
+ Icon && /* @__PURE__ */ jsx(
403
+ "div",
404
+ {
405
+ className: "flex items-center justify-center shrink-0 w-10 h-10 rounded-lg transition-all duration-200",
406
+ style: {
407
+ backgroundColor: question.iconBgColor || "color-mix(in srgb, var(--ac-primary) 10%, transparent)"
408
+ },
409
+ children: /* @__PURE__ */ jsx(
410
+ Icon,
411
+ {
412
+ className: "w-5 h-5",
413
+ style: { color: question.iconColor || "var(--ac-primary)" },
414
+ strokeWidth: 2
415
+ }
416
+ )
417
+ }
418
+ ),
419
+ /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-0.5 min-w-0 w-full", !isHorizontal && "items-center"), children: [
420
+ /* @__PURE__ */ jsx(
421
+ "span",
422
+ {
423
+ className: "font-semibold text-[13px] sm:text-[14px] leading-snug",
424
+ style: { color: question.textColor || "var(--ac-text)" },
425
+ children: question.label
426
+ }
427
+ ),
428
+ question.description && /* @__PURE__ */ jsx("span", { className: "text-[11px] sm:text-[12px] leading-snug text-muted-foreground", children: question.description })
429
+ ] })
430
+ ]
431
+ },
432
+ question.id
433
+ );
434
+ }) : DEFAULT_ACTIONS.map((action, index) => {
435
+ const Icon = action.icon;
436
+ return /* @__PURE__ */ jsxs(
437
+ "button",
438
+ {
439
+ type: "button",
440
+ onClick: () => handleActionClick(action),
441
+ disabled: isProcessing,
442
+ className: cn(
443
+ "group relative w-full active:scale-[0.98] disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200",
444
+ "flex gap-3 p-4",
445
+ "border rounded-2xl shadow-sm hover:bg-accent hover:shadow-md",
446
+ isHorizontal ? "flex-row items-center text-start" : "flex-col items-center text-center"
447
+ ),
448
+ style: {
449
+ backgroundColor: "var(--ac-background)",
450
+ borderColor: "var(--ac-border)",
451
+ ...isMobile ? {
452
+ opacity: shouldAnimate ? 1 : 0,
453
+ transform: shouldAnimate ? "translateY(0)" : "translateY(8px)",
454
+ transition: "opacity 300ms ease-out, transform 300ms ease-out, background-color 150ms",
455
+ transitionDelay: shouldAnimate ? `${index * 60}ms` : "0ms"
456
+ } : {}
457
+ },
458
+ children: [
459
+ /* @__PURE__ */ jsx(
460
+ "div",
461
+ {
462
+ className: "flex items-center justify-center shrink-0 w-10 h-10 rounded-lg transition-all duration-200",
463
+ style: {
464
+ backgroundColor: "color-mix(in srgb, var(--ac-primary) 10%, transparent)"
465
+ },
466
+ children: /* @__PURE__ */ jsx(Icon, { className: "w-5 h-5", style: { color: "var(--ac-primary)" }, strokeWidth: 2 })
467
+ }
468
+ ),
469
+ /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-0.5 min-w-0 w-full", !isHorizontal && "items-center"), children: [
470
+ /* @__PURE__ */ jsx("span", { className: "font-semibold text-[13px] sm:text-[14px] leading-snug", style: { color: "var(--ac-text)" }, children: t(action.label, { clientName }) }),
471
+ /* @__PURE__ */ jsx("span", { className: "text-[11px] sm:text-[12px] text-muted-foreground leading-snug", children: t(action.description, { clientName }) })
472
+ ] })
473
+ ]
474
+ },
475
+ action.id
476
+ );
477
+ }) })
478
+ ] })
479
+ }
480
+ );
481
+ }
482
+ function QuickQuestions({ questions, onSelect, isProcessing = false, pageKey }) {
483
+ const [dismissed, setDismissed] = useState(false);
484
+ const prevPageKeyRef = useRef(pageKey);
485
+ const scrollRef = useRef(null);
486
+ const { direction } = useI18n();
487
+ useEffect(() => {
488
+ if (prevPageKeyRef.current !== pageKey) {
489
+ setDismissed(false);
490
+ prevPageKeyRef.current = pageKey;
491
+ }
492
+ }, [pageKey]);
493
+ if (dismissed || questions.length === 0) return null;
494
+ const isRtl = direction === "rtl";
495
+ return /* @__PURE__ */ jsxs("div", { className: "pb-2.5 pt-1", children: [
496
+ /* @__PURE__ */ jsx("div", { className: "relative", children: /* @__PURE__ */ jsxs(
497
+ "div",
498
+ {
499
+ ref: scrollRef,
500
+ className: cn("flex gap-2 overflow-x-auto pb-1 scrollbar-none", isRtl && "flex-row-reverse"),
501
+ style: { scrollbarWidth: "none", msOverflowStyle: "none" },
502
+ children: [
503
+ questions.map((q, index) => /* @__PURE__ */ jsxs(
504
+ "button",
505
+ {
506
+ type: "button",
507
+ onClick: () => onSelect(q.query),
508
+ disabled: isProcessing,
509
+ className: cn(
510
+ "group relative shrink-0",
511
+ "flex items-center gap-2 px-4 py-2.5",
512
+ "text-[13px] leading-tight",
513
+ "border rounded-2xl",
514
+ "hover:shadow-sm",
515
+ "active:scale-[0.98] transition-all duration-150",
516
+ "disabled:opacity-50 disabled:cursor-not-allowed"
517
+ ),
518
+ style: {
519
+ backgroundColor: "var(--ac-background)",
520
+ borderColor: "var(--ac-border)",
521
+ color: "var(--ac-text)",
522
+ animationDelay: `${index * 40}ms`,
523
+ animation: "quickq-in 0.25s ease-out both"
524
+ },
525
+ children: [
526
+ /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap", children: q.label }),
527
+ /* @__PURE__ */ jsxs(
528
+ "svg",
529
+ {
530
+ className: cn(
531
+ "w-3.5 h-3.5 shrink-0 opacity-50 group-hover:opacity-100 transition-all duration-150",
532
+ "group-hover:translate-x-0.5",
533
+ isRtl && "rotate-180 group-hover:-translate-x-0.5"
534
+ ),
535
+ style: { color: "var(--ac-primary)" },
536
+ viewBox: "0 0 24 24",
537
+ fill: "none",
538
+ stroke: "currentColor",
539
+ strokeWidth: "2.5",
540
+ strokeLinecap: "round",
541
+ strokeLinejoin: "round",
542
+ children: [
543
+ /* @__PURE__ */ jsx("path", { d: "M5 12h14" }),
544
+ /* @__PURE__ */ jsx("path", { d: "m12 5 7 7-7 7" })
545
+ ]
546
+ }
547
+ )
548
+ ]
549
+ },
550
+ q.id
551
+ )),
552
+ /* @__PURE__ */ jsx(
553
+ "button",
554
+ {
555
+ type: "button",
556
+ onClick: () => setDismissed(true),
557
+ className: "shrink-0 flex items-center justify-center w-8 h-8 my-auto rounded-full hover:bg-accent transition-colors duration-150",
558
+ title: isRtl ? "\u05E1\u05D2\u05D5\u05E8" : "Dismiss",
559
+ children: /* @__PURE__ */ jsx(X, { className: "w-3.5 h-3.5" })
560
+ }
561
+ )
562
+ ]
563
+ }
564
+ ) }),
565
+ /* @__PURE__ */ jsx("style", { children: `
566
+ @keyframes quickq-in {
567
+ from { opacity: 0; transform: translateY(6px); }
568
+ to { opacity: 1; transform: translateY(0); }
569
+ }
570
+ .scrollbar-none::-webkit-scrollbar { display: none; }
571
+ ` })
572
+ ] });
573
+ }
574
+ function formatPrice(minorUnits, currencyMinorUnit, currencySymbol) {
575
+ const value = parseInt(minorUnits, 10) / Math.pow(10, currencyMinorUnit);
576
+ const formatted = value % 1 === 0 ? value.toFixed(0) : value.toFixed(2);
577
+ return `${currencySymbol}${formatted}`;
578
+ }
579
+ function decodeHtmlEntities(text) {
580
+ return text.replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code))).replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&ndash;/g, "\u2013").replace(/&mdash;/g, "\u2014").replace(/&laquo;/g, "\xAB").replace(/&raquo;/g, "\xBB");
581
+ }
582
+ function CartDrawer({ storeOrigin, isOpen, onClose, onCartUpdate }) {
583
+ const { t } = useI18n();
584
+ const [cart, setCart] = useState(null);
585
+ const [loading, setLoading] = useState(false);
586
+ const [updatingKeys, setUpdatingKeys] = useState(/* @__PURE__ */ new Set());
587
+ const nonceRef = useRef("");
588
+ const fetchCart = useCallback(async () => {
589
+ setLoading(true);
590
+ try {
591
+ const res = await fetch(`${storeOrigin}/wp-json/wc/store/v1/cart`, { credentials: "include" });
592
+ const nonce = res.headers.get("Nonce") || res.headers.get("X-WC-Store-API-Nonce") || "";
593
+ if (nonce) nonceRef.current = nonce;
594
+ if (res.ok) {
595
+ const data = await res.json();
596
+ setCart(data);
597
+ onCartUpdate?.(data.items_count);
598
+ }
599
+ } catch (err) {
600
+ console.error("[CartDrawer] Failed to fetch cart:", err);
601
+ } finally {
602
+ setLoading(false);
603
+ }
604
+ }, [storeOrigin, onCartUpdate]);
605
+ useEffect(() => {
606
+ if (isOpen) fetchCart();
607
+ }, [isOpen, fetchCart]);
608
+ const updateItem = useCallback(
609
+ async (key, quantity) => {
610
+ setUpdatingKeys((prev) => new Set(prev).add(key));
611
+ try {
612
+ const res = await fetch(`${storeOrigin}/wp-json/wc/store/v1/cart/update-item`, {
613
+ method: "POST",
614
+ headers: {
615
+ "Content-Type": "application/json",
616
+ Nonce: nonceRef.current,
617
+ "X-WC-Store-API-Nonce": nonceRef.current
618
+ },
619
+ credentials: "include",
620
+ body: JSON.stringify({ key, quantity })
621
+ });
622
+ const nonce = res.headers.get("Nonce") || res.headers.get("X-WC-Store-API-Nonce") || "";
623
+ if (nonce) nonceRef.current = nonce;
624
+ if (res.ok) {
625
+ const data = await res.json();
626
+ setCart(data);
627
+ onCartUpdate?.(data.items_count);
628
+ }
629
+ } catch (err) {
630
+ console.error("[CartDrawer] Failed to update item:", err);
631
+ } finally {
632
+ setUpdatingKeys((prev) => {
633
+ const next = new Set(prev);
634
+ next.delete(key);
635
+ return next;
636
+ });
637
+ }
638
+ },
639
+ [storeOrigin, onCartUpdate]
640
+ );
641
+ const removeItem = useCallback(
642
+ async (key) => {
643
+ setUpdatingKeys((prev) => new Set(prev).add(key));
644
+ try {
645
+ const res = await fetch(`${storeOrigin}/wp-json/wc/store/v1/cart/remove-item`, {
646
+ method: "POST",
647
+ headers: {
648
+ "Content-Type": "application/json",
649
+ Nonce: nonceRef.current,
650
+ "X-WC-Store-API-Nonce": nonceRef.current
651
+ },
652
+ credentials: "include",
653
+ body: JSON.stringify({ key })
654
+ });
655
+ const nonce = res.headers.get("Nonce") || res.headers.get("X-WC-Store-API-Nonce") || "";
656
+ if (nonce) nonceRef.current = nonce;
657
+ if (res.ok) {
658
+ const data = await res.json();
659
+ setCart(data);
660
+ onCartUpdate?.(data.items_count);
661
+ }
662
+ } catch (err) {
663
+ console.error("[CartDrawer] Failed to remove item:", err);
664
+ } finally {
665
+ setUpdatingKeys((prev) => {
666
+ const next = new Set(prev);
667
+ next.delete(key);
668
+ return next;
669
+ });
670
+ }
671
+ },
672
+ [storeOrigin, onCartUpdate]
673
+ );
674
+ if (!isOpen) return null;
675
+ const items = cart?.items ?? [];
676
+ const totalPrice = cart ? formatPrice(cart.totals.total_price, cart.totals.currency_minor_unit, cart.totals.currency_symbol) : "";
677
+ return /* @__PURE__ */ jsx("div", { className: "absolute inset-x-0 top-[57px] z-50 px-3 pt-1", dir: "rtl", children: /* @__PURE__ */ jsxs("div", { className: "rounded-xl border shadow-lg overflow-hidden", style: { backgroundColor: "var(--ac-background)", borderColor: "var(--ac-border)" }, children: [
678
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-3 border-b bg-muted/30", style: { borderColor: "var(--ac-border)" }, children: [
679
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
680
+ /* @__PURE__ */ jsx(ShoppingCart, { className: "w-4 h-4", style: { color: "var(--ac-primary)" } }),
681
+ /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", style: { color: "var(--ac-text)" }, children: t("yourCart") }),
682
+ /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
683
+ "(",
684
+ t("cartItems", { count: String(cart?.items_count ?? 0) }),
685
+ ")"
686
+ ] })
687
+ ] }),
688
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: onClose, className: "p-1 hover:bg-secondary rounded transition-colors", children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4 text-muted-foreground" }) })
689
+ ] }),
690
+ /* @__PURE__ */ jsx("div", { className: "max-h-[60vh] overflow-y-auto", children: loading && !cart ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-8", children: /* @__PURE__ */ jsx("div", { className: "w-5 h-5 border-2 border-t-transparent rounded-full animate-spin", style: { borderColor: "var(--ac-primary)", borderTopColor: "transparent" } }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2 py-8 text-muted-foreground", children: [
691
+ /* @__PURE__ */ jsx(ShoppingCart, { className: "w-8 h-8 opacity-40" }),
692
+ /* @__PURE__ */ jsx("p", { className: "text-sm", children: t("cartEmpty") })
693
+ ] }) : /* @__PURE__ */ jsx("div", { className: "divide-y", style: { borderColor: "var(--ac-border)" }, children: items.map((item) => {
694
+ const isUpdating = updatingKeys.has(item.key);
695
+ const imgSrc = item.images?.[0]?.thumbnail || item.images?.[0]?.src || "";
696
+ const lineTotal = formatPrice(
697
+ item.totals.line_total,
698
+ item.totals.currency_minor_unit,
699
+ cart.totals.currency_symbol
700
+ );
701
+ return /* @__PURE__ */ jsxs("div", { className: `flex items-center gap-3 px-4 py-3 ${isUpdating ? "opacity-50" : ""}`, children: [
702
+ imgSrc ? /* @__PURE__ */ jsx("img", { src: imgSrc, alt: item.name, className: "w-10 h-10 rounded-lg object-cover shrink-0", loading: "lazy" }) : /* @__PURE__ */ jsx("div", { className: "w-10 h-10 rounded-lg bg-muted flex items-center justify-center shrink-0", children: /* @__PURE__ */ jsx(ShoppingCart, { className: "w-4 h-4 text-muted-foreground/40" }) }),
703
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 min-w-0", children: [
704
+ /* @__PURE__ */ jsx("p", { className: "text-[13px] font-medium line-clamp-1", style: { color: "var(--ac-text)" }, children: decodeHtmlEntities(item.name) }),
705
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold mt-0.5", style: { color: "var(--ac-primary)" }, children: lineTotal })
706
+ ] }),
707
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
708
+ /* @__PURE__ */ jsx(
709
+ "button",
710
+ {
711
+ type: "button",
712
+ onClick: () => updateItem(item.key, item.quantity - 1),
713
+ disabled: isUpdating || item.quantity <= 1,
714
+ className: "w-6 h-6 flex items-center justify-center rounded bg-secondary hover:bg-secondary/80 disabled:opacity-40 transition-colors",
715
+ children: /* @__PURE__ */ jsx(Minus, { className: "w-3 h-3" })
716
+ }
717
+ ),
718
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-medium w-5 text-center", children: item.quantity }),
719
+ /* @__PURE__ */ jsx(
720
+ "button",
721
+ {
722
+ type: "button",
723
+ onClick: () => updateItem(item.key, item.quantity + 1),
724
+ disabled: isUpdating,
725
+ className: "w-6 h-6 flex items-center justify-center rounded bg-secondary hover:bg-secondary/80 disabled:opacity-40 transition-colors",
726
+ children: /* @__PURE__ */ jsx(Plus, { className: "w-3 h-3" })
727
+ }
728
+ )
729
+ ] }),
730
+ /* @__PURE__ */ jsx(
731
+ "button",
732
+ {
733
+ type: "button",
734
+ onClick: () => removeItem(item.key),
735
+ disabled: isUpdating,
736
+ className: "p-1 hover:bg-red-50 rounded transition-colors text-muted-foreground hover:text-red-500",
737
+ title: t("removeItem"),
738
+ children: /* @__PURE__ */ jsx(Trash2, { className: "w-3.5 h-3.5" })
739
+ }
740
+ )
741
+ ] }, item.key);
742
+ }) }) }),
743
+ items.length > 0 && /* @__PURE__ */ jsxs("div", { className: "border-t px-4 py-3 space-y-2.5 bg-muted/20", style: { borderColor: "var(--ac-border)" }, children: [
744
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
745
+ /* @__PURE__ */ jsx("span", { className: "text-[13px] font-medium text-muted-foreground", children: t("cartTotal") }),
746
+ /* @__PURE__ */ jsx("span", { className: "text-base font-bold", style: { color: "var(--ac-text)" }, children: totalPrice })
747
+ ] }),
748
+ /* @__PURE__ */ jsx(
749
+ "a",
750
+ {
751
+ href: `${storeOrigin}/checkout`,
752
+ target: "_blank",
753
+ rel: "noopener noreferrer",
754
+ className: "flex items-center justify-center gap-2 w-full py-2.5 rounded-lg text-sm font-semibold hover:opacity-90 transition-opacity no-underline",
755
+ style: { backgroundColor: "var(--ac-primary)", color: "var(--ac-primary-foreground, #fff)" },
756
+ children: t("checkout")
757
+ }
758
+ )
759
+ ] })
760
+ ] }) });
761
+ }
762
+ function ChatInterface(props) {
763
+ const { messages, status, sendMessage, sessionId, config, clearMessages } = useChatContext();
764
+ const { t, direction } = useI18n();
765
+ useTheme();
766
+ const slots = useSlots();
767
+ let liveChat = null;
768
+ try {
769
+ liveChat = useLiveChat();
770
+ } catch {
771
+ liveChat = null;
772
+ }
773
+ const [showWelcome, setShowWelcome] = useState(true);
774
+ const [input, setInput] = useState("");
775
+ const [hideFirstUserMessage, setHideFirstUserMessage] = useState(false);
776
+ const [cartCount, setCartCount] = useState(void 0);
777
+ const [cartOpen, setCartOpen] = useState(false);
778
+ const [storeOrigin, _setStoreOrigin] = useState(null);
779
+ const isProcessing = status === "streaming";
780
+ useEffect(() => {
781
+ if (messages.length > 0 && showWelcome) setShowWelcome(false);
782
+ }, [messages.length, showWelcome]);
783
+ const handleSubmit = useCallback(
784
+ (text) => {
785
+ if (!text.trim() || isProcessing) return;
786
+ if (liveChat?.state === "live") return;
787
+ setShowWelcome(false);
788
+ setInput("");
789
+ sendMessage(text);
790
+ },
791
+ [isProcessing, sendMessage, liveChat]
792
+ );
793
+ const handleSelectCategory = useCallback(
794
+ (category, hideMessage = false) => {
795
+ if (hideMessage && !props.showFirstMessage) setHideFirstUserMessage(true);
796
+ handleSubmit(category);
797
+ },
798
+ [handleSubmit, props.showFirstMessage]
799
+ );
800
+ const handleNewConversation = useCallback(() => {
801
+ clearMessages();
802
+ setShowWelcome(true);
803
+ setInput("");
804
+ setHideFirstUserMessage(false);
805
+ props.onNewConversation?.();
806
+ }, [clearMessages, props]);
807
+ useEffect(() => {
808
+ if (props.pendingMessage && props.isOpen) {
809
+ const timer = setTimeout(() => {
810
+ handleSubmit(props.pendingMessage);
811
+ props.onPendingMessageConsumed?.();
812
+ }, 300);
813
+ return () => clearTimeout(timer);
814
+ }
815
+ }, [props.pendingMessage, props.isOpen, handleSubmit, props]);
816
+ useEffect(() => {
817
+ if (!liveChat) return;
818
+ liveChat.registerAiHistoryGetter(
819
+ () => messages.map((m) => ({
820
+ role: m.role,
821
+ content: typeof m.content === "string" ? m.content : (m.parts || []).filter((p) => p.type === "text").map((p) => p.text || "").join("") || ""
822
+ }))
823
+ );
824
+ }, [messages, liveChat]);
825
+ const headerProps = useMemo(
826
+ () => ({
827
+ isWelcome: showWelcome && messages.length === 0,
828
+ onNewConversation: handleNewConversation,
829
+ onClose: props.onClose,
830
+ clientName: config.clientName,
831
+ logoUrl: props.logoUrl,
832
+ cartCount,
833
+ onCartClick: () => setCartOpen(!cartOpen)
834
+ }),
835
+ [showWelcome, messages.length, handleNewConversation, props.onClose, props.logoUrl, config.clientName, cartCount, cartOpen]
836
+ );
837
+ if (showWelcome && messages.length === 0) {
838
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col", dir: direction, style: { backgroundColor: "var(--ac-background)" }, children: [
839
+ !props.hideHeader && renderSlot("header", headerProps, ChatHeader, slots),
840
+ renderSlot(
841
+ "welcomePage",
842
+ {
843
+ onSelectCategory: handleSelectCategory,
844
+ isProcessing,
845
+ clientName: config.clientName,
846
+ isOpen: props.isOpen,
847
+ questions: props.questions,
848
+ welcomeTitle: props.pageWelcomeTitle || props.welcomeTitle,
849
+ welcomeSubtitle: props.pageWelcomeSubtitle || props.welcomeSubtitle,
850
+ hideWelcomeHeader: props.hideWelcomeHeader,
851
+ loading: props.pageContextLoading,
852
+ questionsLayout: props.questionsLayout,
853
+ questionsLayoutMobile: props.questionsLayoutMobile
854
+ },
855
+ WelcomePage,
856
+ slots
857
+ ),
858
+ /* @__PURE__ */ jsxs("div", { className: "shrink-0 px-[15px] md:px-[40px]", style: { backgroundColor: "var(--ac-background)" }, children: [
859
+ /* @__PURE__ */ jsx("div", { className: "mx-auto z-40 w-full", children: renderSlot(
860
+ "input",
861
+ { value: input, onChange: setInput, onSubmit: handleSubmit, isProcessing },
862
+ ChatInput,
863
+ slots
864
+ ) }),
865
+ renderSlot("footer", { footerText: props.footerText }, ChatFooter, slots)
866
+ ] })
867
+ ] });
868
+ }
869
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col", dir: direction, style: { backgroundColor: "var(--ac-background)" }, children: [
870
+ !props.hideHeader && renderSlot("header", headerProps, ChatHeader, slots),
871
+ storeOrigin && /* @__PURE__ */ jsx(
872
+ CartDrawer,
873
+ {
874
+ storeOrigin,
875
+ isOpen: cartOpen,
876
+ onClose: () => setCartOpen(false),
877
+ onCartUpdate: (count) => setCartCount(count)
878
+ }
879
+ ),
880
+ /* @__PURE__ */ jsx(Conversation, { className: "flex-1", children: /* @__PURE__ */ jsxs(ConversationContent, { className: "px-[15px] md:px-[40px] py-6 sm:py-8 w-full space-y-6", children: [
881
+ messages.map((message, messageIndex) => {
882
+ if (hideFirstUserMessage && messageIndex === 0 && message.role === "user") return null;
883
+ return /* @__PURE__ */ jsx(
884
+ "div",
885
+ {
886
+ className: `group ${message.role === "assistant" ? "is-assistant" : "is-user"}`,
887
+ children: [...message.parts || []].sort((a, b) => {
888
+ if (a.type === "text" && b.type !== "text") return -1;
889
+ if (a.type !== "text" && b.type === "text") return 1;
890
+ return 0;
891
+ }).map((part, i) => {
892
+ if (part.type === "text") {
893
+ if (message.role === "assistant") {
894
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
895
+ "div",
896
+ {
897
+ className: "flex gap-[10px] items-start rounded-2xl",
898
+ style: {
899
+ backgroundColor: "var(--ac-assistant-bubble-bg, transparent)",
900
+ padding: "var(--ac-assistant-bubble-padding, 0)",
901
+ color: "var(--ac-assistant-bubble-text, var(--ac-text))"
902
+ },
903
+ children: [
904
+ /* @__PURE__ */ jsx(SparklesIcon, { className: "mt-[2px] w-4 h-4 shrink-0", style: { color: "var(--ac-primary)" } }),
905
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-w-0 whitespace-pre-wrap", children: part.text })
906
+ ]
907
+ }
908
+ ) }, `${message.id}-${i}`);
909
+ }
910
+ return /* @__PURE__ */ jsx(
911
+ "div",
912
+ {
913
+ className: "inline-block rounded-2xl px-3 py-2 max-w-[85%]",
914
+ style: {
915
+ backgroundColor: "var(--ac-user-bubble-bg, var(--ac-primary))",
916
+ color: "var(--ac-primary-foreground, #fff)"
917
+ },
918
+ children: part.text
919
+ },
920
+ `${message.id}-${i}`
921
+ );
922
+ }
923
+ if (part.type.startsWith("tool-")) {
924
+ const toolName = part.type.replace("tool-", "");
925
+ if (toolName === "requestHumanChat") return null;
926
+ let output = part.output;
927
+ if (typeof output === "string") {
928
+ try {
929
+ output = JSON.parse(output);
930
+ } catch {
931
+ }
932
+ }
933
+ const result = output && typeof output === "object" && !Array.isArray(output) && ("data" in output || "uiRenderMode" in output) ? output : { data: output };
934
+ return /* @__PURE__ */ jsx(
935
+ ToolRenderer,
936
+ {
937
+ toolName,
938
+ state: part.state ?? "output-available",
939
+ args: part.input ?? {},
940
+ result,
941
+ onSendMessage: handleSubmit,
942
+ isProcessing
943
+ },
944
+ `${message.id}-tool-${i}`
945
+ );
946
+ }
947
+ return null;
948
+ })
949
+ },
950
+ message.id
951
+ );
952
+ }),
953
+ status === "streaming" && (() => {
954
+ const lastMessage = messages[messages.length - 1];
955
+ if (!lastMessage || lastMessage.role !== "assistant") return true;
956
+ const hasText = (lastMessage.parts || []).some(
957
+ (p) => p.type === "text" && (p.text || "").trim()
958
+ );
959
+ const allToolsComplete = (lastMessage.parts || []).filter((p) => p.type.startsWith("tool-")).every((p) => p.state === "output-available");
960
+ return allToolsComplete && !hasText;
961
+ })() && /* @__PURE__ */ jsx(Loader, { text: t("thinking") })
962
+ ] }) }),
963
+ /* @__PURE__ */ jsxs("div", { className: "shrink-0 px-[15px] md:px-[40px] pb-2", style: { backgroundColor: "var(--ac-background)" }, children: [
964
+ props.pageQuestions && props.pageQuestions.length > 0 && /* @__PURE__ */ jsx(
965
+ QuickQuestions,
966
+ {
967
+ questions: props.pageQuestions,
968
+ onSelect: (query) => handleSelectCategory(query, true),
969
+ isProcessing,
970
+ pageKey: props.pageUrl
971
+ }
972
+ ),
973
+ /* @__PURE__ */ jsxs("div", { className: "mx-auto z-40 w-full flex items-end gap-2", children: [
974
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: renderSlot(
975
+ "input",
976
+ { value: input, onChange: setInput, onSubmit: () => handleSubmit(input), isProcessing },
977
+ ChatInput,
978
+ slots
979
+ ) }),
980
+ liveChat && liveChat.state === "ai" && !showWelcome && /* @__PURE__ */ jsx(
981
+ "button",
982
+ {
983
+ type: "button",
984
+ onClick: () => liveChat.requestManualHandoff(),
985
+ title: t("liveChatTalkToHuman"),
986
+ className: "shrink-0 mb-[7px] h-[36px] w-[36px] rounded-lg hover:bg-muted flex items-center justify-center transition-colors opacity-50 hover:opacity-100",
987
+ children: /* @__PURE__ */ jsx(Headset, { className: "h-4 w-4 text-muted-foreground" })
988
+ }
989
+ )
990
+ ] }),
991
+ renderSlot("footer", { footerText: props.footerText }, ChatFooter, slots)
992
+ ] }),
993
+ /* @__PURE__ */ jsx("span", { "data-session-id": sessionId, className: "hidden" })
994
+ ] });
995
+ }
996
+ function FloatingButton({
997
+ onClick,
998
+ position,
999
+ positionMobile,
1000
+ greeting,
1001
+ isOpen = false,
1002
+ greetingOffsetX = "-20px",
1003
+ greetingOffsetY = "-20px",
1004
+ buttonOffsetXMobile = "16px",
1005
+ buttonOffsetYMobile = "16px",
1006
+ buttonOffsetXDesktop = "24px",
1007
+ buttonOffsetYDesktop = "24px",
1008
+ buttonIconUrl,
1009
+ buttonImageUrl,
1010
+ buttonImageUrlMobile,
1011
+ buttonWidth,
1012
+ buttonHeight,
1013
+ buttonIconSize,
1014
+ buttonWidthMobile,
1015
+ buttonHeightMobile,
1016
+ buttonIconSizeMobile,
1017
+ buttonBgColor,
1018
+ buttonBorderRadius,
1019
+ greetingMaxWidth,
1020
+ zIndex = 999999,
1021
+ hideGreeting = false
1022
+ }) {
1023
+ const [showGreeting, setShowGreeting] = useState(false);
1024
+ const { t, direction } = useI18n();
1025
+ const isRtl = direction === "rtl";
1026
+ const effectiveGreeting = greeting || t("greeting");
1027
+ const [greetingDismissed, setGreetingDismissed] = useState(false);
1028
+ const isMobile = useIsMobile();
1029
+ const effectivePosition = isMobile && positionMobile ? positionMobile : position;
1030
+ const isRightSide = effectivePosition === "bottom-right" || effectivePosition === "top-right";
1031
+ const isBottom = effectivePosition === "bottom-right" || effectivePosition === "bottom-left";
1032
+ const buttonOffsetX = isMobile ? buttonOffsetXMobile : buttonOffsetXDesktop;
1033
+ const buttonOffsetY = isMobile ? buttonOffsetYMobile : buttonOffsetYDesktop;
1034
+ useEffect(() => {
1035
+ if (greetingDismissed || isOpen) return;
1036
+ const timer = setTimeout(() => setShowGreeting(true), 2e3);
1037
+ return () => clearTimeout(timer);
1038
+ }, [greetingDismissed, isOpen]);
1039
+ const getPositionStyles = () => {
1040
+ const styles = {};
1041
+ if (isBottom) styles.bottom = buttonOffsetY;
1042
+ else styles.top = buttonOffsetY;
1043
+ if (isRightSide) styles.right = buttonOffsetX;
1044
+ else styles.left = buttonOffsetX;
1045
+ return styles;
1046
+ };
1047
+ return /* @__PURE__ */ jsxs(
1048
+ "div",
1049
+ {
1050
+ className: `fixed flex items-end gap-3 ${isRightSide ? "flex-row" : "flex-row-reverse"}`,
1051
+ dir: "ltr",
1052
+ style: { ...getPositionStyles(), zIndex },
1053
+ children: [
1054
+ showGreeting && !isOpen && !hideGreeting && /* @__PURE__ */ jsxs(
1055
+ "div",
1056
+ {
1057
+ dir: isRtl ? "rtl" : "ltr",
1058
+ className: `relative bg-white rounded-sm animate-fadeIn ${isBottom ? "mb-1" : "mt-1"}`,
1059
+ style: {
1060
+ animation: "fadeIn 0.3s ease-out",
1061
+ boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)",
1062
+ padding: "12px",
1063
+ maxWidth: greetingMaxWidth || "240px",
1064
+ color: "#000",
1065
+ textAlign: "center",
1066
+ fontSize: "16px",
1067
+ fontWeight: 400,
1068
+ lineHeight: "16px",
1069
+ right: greetingOffsetX,
1070
+ top: greetingOffsetY
1071
+ },
1072
+ children: [
1073
+ effectiveGreeting,
1074
+ /* @__PURE__ */ jsx(
1075
+ "div",
1076
+ {
1077
+ className: "absolute top-1/2 -translate-y-1/2",
1078
+ style: {
1079
+ width: "14px",
1080
+ height: "14px",
1081
+ background: "white",
1082
+ transform: "translateY(-50%) rotate(45deg)",
1083
+ boxShadow: "2px -2px 4px rgba(0, 0, 0, 0.06)",
1084
+ ...isRightSide ? { right: "-7px" } : { left: "-7px" }
1085
+ }
1086
+ }
1087
+ )
1088
+ ]
1089
+ }
1090
+ ),
1091
+ (buttonImageUrl || buttonImageUrlMobile) && !isOpen ? /* @__PURE__ */ jsx(
1092
+ "button",
1093
+ {
1094
+ type: "button",
1095
+ onClick,
1096
+ className: "bg-transparent border-none p-0 cursor-pointer hover:scale-105 transition-all duration-200 flex-shrink-0 z-[2]",
1097
+ style: {
1098
+ ...(buttonWidth || buttonWidthMobile) && { width: isMobile ? buttonWidthMobile || buttonWidth : buttonWidth },
1099
+ ...(buttonHeight || buttonHeightMobile) && { height: isMobile ? buttonHeightMobile || buttonHeight : buttonHeight }
1100
+ },
1101
+ "aria-label": "Open chat",
1102
+ children: /* @__PURE__ */ jsx(
1103
+ "img",
1104
+ {
1105
+ src: isMobile && buttonImageUrlMobile ? buttonImageUrlMobile : buttonImageUrl || buttonImageUrlMobile,
1106
+ alt: "Chat",
1107
+ className: "w-full h-full object-contain",
1108
+ style: {
1109
+ ...!buttonWidth && !buttonWidthMobile && { width: isMobile ? "48px" : "56px" },
1110
+ ...!buttonHeight && !buttonHeightMobile && { height: isMobile ? "48px" : "56px" },
1111
+ ...buttonBorderRadius != null && { borderRadius: buttonBorderRadius }
1112
+ }
1113
+ }
1114
+ )
1115
+ }
1116
+ ) : /* @__PURE__ */ jsx(
1117
+ "button",
1118
+ {
1119
+ type: "button",
1120
+ onClick,
1121
+ className: cn(
1122
+ "shadow-lg hover:shadow-xl hover:scale-105 transition-all duration-200 flex items-center justify-center flex-shrink-0 z-[2]",
1123
+ !buttonBorderRadius && "rounded-full",
1124
+ !buttonWidth && !buttonWidthMobile && !buttonHeight && !buttonHeightMobile && "w-12 h-12 md:w-14 md:h-14"
1125
+ ),
1126
+ style: {
1127
+ backgroundColor: buttonBgColor || "var(--ac-primary)",
1128
+ color: "var(--ac-primary-foreground, #fff)",
1129
+ ...(buttonWidth || buttonWidthMobile) && { width: isMobile ? buttonWidthMobile || buttonWidth : buttonWidth },
1130
+ ...(buttonHeight || buttonHeightMobile) && { height: isMobile ? buttonHeightMobile || buttonHeight : buttonHeight },
1131
+ ...buttonBorderRadius != null && { borderRadius: buttonBorderRadius }
1132
+ },
1133
+ "aria-label": isOpen ? "Close chat" : "Open chat",
1134
+ children: (() => {
1135
+ const effectiveIconSize = isMobile ? buttonIconSizeMobile || buttonIconSize : buttonIconSize;
1136
+ const iconStyle = effectiveIconSize ? { width: effectiveIconSize, height: effectiveIconSize } : void 0;
1137
+ const iconClass = !effectiveIconSize ? "w-6 h-6 md:w-7 md:h-7" : void 0;
1138
+ if (isOpen) return /* @__PURE__ */ jsx(X, { className: iconClass, style: iconStyle, strokeWidth: 2.5 });
1139
+ if (buttonIconUrl) return /* @__PURE__ */ jsx("img", { src: buttonIconUrl, alt: "Chat", className: cn("object-contain", iconClass), style: iconStyle });
1140
+ return /* @__PURE__ */ jsx(MessageSquare, { className: iconClass, style: iconStyle, strokeWidth: 2.5 });
1141
+ })()
1142
+ }
1143
+ ),
1144
+ /* @__PURE__ */ jsx("style", { children: `
1145
+ @keyframes fadeIn {
1146
+ from { opacity: 0; transform: scale(0.95); }
1147
+ to { opacity: 1; transform: scale(1); }
1148
+ }
1149
+ ` })
1150
+ ]
1151
+ }
1152
+ );
1153
+ }
1154
+ function useLiveChatOrThrow() {
1155
+ const ctx = useLiveChat();
1156
+ if (!ctx) throw new Error("LiveChat sub-view rendered outside LiveChatProvider \u2014 this should never happen");
1157
+ return ctx;
1158
+ }
1159
+ function LiveChatPanel({ isWidgetOpen, isRightSide, zIndex }) {
1160
+ const lc = useLiveChat();
1161
+ if (!lc) return null;
1162
+ const isActive = lc.state !== "ai" || lc.showIdentityForm;
1163
+ const showPanel = isWidgetOpen && isActive;
1164
+ const [isWide, setIsWide] = useState(
1165
+ () => typeof window !== "undefined" ? window.innerWidth >= 1200 : true
1166
+ );
1167
+ useEffect(() => {
1168
+ if (typeof window === "undefined") return;
1169
+ const mq = window.matchMedia("(min-width: 1200px)");
1170
+ const handler = (e) => setIsWide(e.matches);
1171
+ mq.addEventListener("change", handler);
1172
+ return () => mq.removeEventListener("change", handler);
1173
+ }, []);
1174
+ if (!isWide) return null;
1175
+ return /* @__PURE__ */ jsx(
1176
+ "div",
1177
+ {
1178
+ className: "fixed top-1/2 flex flex-col rounded-2xl border shadow-lg overflow-hidden",
1179
+ style: {
1180
+ backgroundColor: "var(--ac-background)",
1181
+ borderColor: "var(--ac-border)",
1182
+ zIndex,
1183
+ width: "min(420px, calc(100vw - 800px))",
1184
+ height: "75vh",
1185
+ ...isRightSide ? { right: "790px" } : { left: "790px" },
1186
+ transform: showPanel ? "translateY(-50%) translateX(0)" : `translateY(-50%) ${isRightSide ? "translateX(20px)" : "translateX(-20px)"}`,
1187
+ opacity: showPanel ? 1 : 0,
1188
+ pointerEvents: showPanel ? "auto" : "none",
1189
+ transition: "transform 300ms ease-in-out, opacity 300ms ease-in-out"
1190
+ },
1191
+ children: lc.showIdentityForm ? /* @__PURE__ */ jsx(IdentityView, {}) : lc.state === "requesting" || lc.state === "queued" ? /* @__PURE__ */ jsx(QueueView, {}) : lc.state === "live" ? /* @__PURE__ */ jsx(ChatView, {}) : lc.state === "ended" ? /* @__PURE__ */ jsx(EndedView, {}) : null
1192
+ }
1193
+ );
1194
+ }
1195
+ function MobileLiveChatDrawer() {
1196
+ const lc = useLiveChat();
1197
+ const { t } = useI18n();
1198
+ if (!lc) return null;
1199
+ const isActive = lc.state !== "ai" || lc.showIdentityForm;
1200
+ const [minimized, setMinimized] = useState(false);
1201
+ const [isNarrow, setIsNarrow] = useState(
1202
+ () => typeof window !== "undefined" ? window.innerWidth < 1200 : false
1203
+ );
1204
+ useEffect(() => {
1205
+ if (typeof window === "undefined") return;
1206
+ const mq = window.matchMedia("(max-width: 1199px)");
1207
+ const handler = (e) => setIsNarrow(e.matches);
1208
+ mq.addEventListener("change", handler);
1209
+ return () => mq.removeEventListener("change", handler);
1210
+ }, []);
1211
+ useEffect(() => {
1212
+ if (!isActive) setMinimized(false);
1213
+ }, [isActive]);
1214
+ if (!isNarrow) return null;
1215
+ if (isActive && minimized) {
1216
+ return /* @__PURE__ */ jsx("div", { className: "absolute bottom-[100px] inset-x-0 z-50 flex justify-center px-4", children: /* @__PURE__ */ jsxs(
1217
+ "button",
1218
+ {
1219
+ type: "button",
1220
+ onClick: () => setMinimized(false),
1221
+ className: "flex items-center gap-2 px-4 py-2 rounded-full border shadow-md bg-green-50 hover:bg-green-100 transition-colors",
1222
+ children: [
1223
+ /* @__PURE__ */ jsx("div", { className: "h-2 w-2 rounded-full bg-green-500 animate-pulse" }),
1224
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-green-800", children: t("liveChatChattingWith", { name: lc.operatorName || "..." }) })
1225
+ ]
1226
+ }
1227
+ ) });
1228
+ }
1229
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1230
+ /* @__PURE__ */ jsx(
1231
+ "div",
1232
+ {
1233
+ className: "absolute inset-0 z-40 bg-black/50",
1234
+ style: {
1235
+ opacity: isActive ? 1 : 0,
1236
+ pointerEvents: isActive ? "auto" : "none",
1237
+ transition: "opacity 200ms ease-out"
1238
+ },
1239
+ onClick: () => lc.state === "live" ? setMinimized(true) : void 0
1240
+ }
1241
+ ),
1242
+ /* @__PURE__ */ jsxs(
1243
+ "div",
1244
+ {
1245
+ className: "absolute inset-x-0 bottom-0 z-50 rounded-t-2xl border-t shadow-2xl flex flex-col",
1246
+ style: {
1247
+ backgroundColor: "var(--ac-background)",
1248
+ borderColor: "var(--ac-border)",
1249
+ height: "calc(100dvh - 150px)",
1250
+ transform: isActive ? "translateY(0)" : "translateY(100%)",
1251
+ transition: "transform 300ms cubic-bezier(0.32, 0.72, 0, 1)"
1252
+ },
1253
+ children: [
1254
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 pt-2 pb-1 shrink-0", children: [
1255
+ /* @__PURE__ */ jsx("div", { className: "flex-1" }),
1256
+ /* @__PURE__ */ jsx("div", { className: "w-[80px] h-1.5 rounded-full bg-muted" }),
1257
+ /* @__PURE__ */ jsx("div", { className: "flex-1 flex justify-end", children: lc.state === "live" && /* @__PURE__ */ jsx(
1258
+ "button",
1259
+ {
1260
+ type: "button",
1261
+ onClick: () => setMinimized(true),
1262
+ className: "text-[11px] text-muted-foreground hover:text-foreground px-2 py-1 rounded-lg hover:bg-muted transition-colors whitespace-nowrap",
1263
+ children: t("liveChatBackToAI")
1264
+ }
1265
+ ) })
1266
+ ] }),
1267
+ lc.showIdentityForm ? /* @__PURE__ */ jsx(IdentityView, {}) : lc.state === "requesting" || lc.state === "queued" ? /* @__PURE__ */ jsx(QueueView, {}) : lc.state === "live" ? /* @__PURE__ */ jsx(ChatView, {}) : lc.state === "ended" ? /* @__PURE__ */ jsx(EndedView, {}) : null
1268
+ ]
1269
+ }
1270
+ )
1271
+ ] });
1272
+ }
1273
+ function isValidEmail(email) {
1274
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
1275
+ }
1276
+ function IdentityView() {
1277
+ const lc = useLiveChatOrThrow();
1278
+ const { t, direction } = useI18n();
1279
+ const userInfo = lc.userInfo;
1280
+ const [name, setName] = useState(userInfo?.name || "");
1281
+ const [email, setEmail] = useState(userInfo?.email || "");
1282
+ const [emailError, setEmailError] = useState(false);
1283
+ const isRTL = direction === "rtl";
1284
+ useEffect(() => {
1285
+ if (userInfo?.name && userInfo?.email && isValidEmail(userInfo.email)) {
1286
+ lc.setShowIdentityForm(false);
1287
+ lc.initiate(userInfo.name, userInfo.email);
1288
+ }
1289
+ }, []);
1290
+ const handleConnect = () => {
1291
+ if (!isValidEmail(email)) {
1292
+ setEmailError(true);
1293
+ return;
1294
+ }
1295
+ lc.setShowIdentityForm(false);
1296
+ lc.initiate(name, email);
1297
+ };
1298
+ return /* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col items-center justify-center p-8", dir: isRTL ? "rtl" : "ltr", children: [
1299
+ /* @__PURE__ */ jsx("div", { className: "h-14 w-14 rounded-2xl bg-blue-50 flex items-center justify-center mb-5", children: /* @__PURE__ */ jsx(Headset, { className: "h-7 w-7 text-blue-500" }) }),
1300
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium mb-5", style: { color: "var(--ac-text)" }, children: t("liveChatIdentityTitle") }),
1301
+ /* @__PURE__ */ jsxs("div", { className: "w-full max-w-xs space-y-3", children: [
1302
+ /* @__PURE__ */ jsx(
1303
+ "input",
1304
+ {
1305
+ type: "text",
1306
+ value: name,
1307
+ onChange: (e) => setName(e.target.value),
1308
+ placeholder: t("liveChatIdentityName"),
1309
+ className: "w-full text-sm p-3 border rounded-xl bg-background focus:outline-none focus:ring-2",
1310
+ autoFocus: true
1311
+ }
1312
+ ),
1313
+ /* @__PURE__ */ jsxs("div", { children: [
1314
+ /* @__PURE__ */ jsx(
1315
+ "input",
1316
+ {
1317
+ type: "email",
1318
+ value: email,
1319
+ onChange: (e) => {
1320
+ setEmail(e.target.value);
1321
+ setEmailError(false);
1322
+ },
1323
+ placeholder: t("liveChatIdentityEmail"),
1324
+ className: `w-full text-sm p-3 border rounded-xl bg-background focus:outline-none focus:ring-2 ${emailError ? "border-red-400 focus:ring-red-300" : ""}`
1325
+ }
1326
+ ),
1327
+ emailError && /* @__PURE__ */ jsx("p", { className: "text-xs text-red-500 mt-1 px-1", children: isRTL ? "\u05DB\u05EA\u05D5\u05D1\u05EA \u05D0\u05D9\u05DE\u05D9\u05D9\u05DC \u05DC\u05D0 \u05EA\u05E7\u05D9\u05E0\u05D4" : "Invalid email address" })
1328
+ ] }),
1329
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2 justify-end pt-1", children: [
1330
+ /* @__PURE__ */ jsx(
1331
+ "button",
1332
+ {
1333
+ type: "button",
1334
+ onClick: () => lc.setShowIdentityForm(false),
1335
+ className: "text-sm text-muted-foreground hover:text-foreground px-4 py-2 rounded-xl",
1336
+ children: t("liveChatCancel")
1337
+ }
1338
+ ),
1339
+ /* @__PURE__ */ jsx(
1340
+ "button",
1341
+ {
1342
+ type: "button",
1343
+ onClick: handleConnect,
1344
+ disabled: !name.trim() || !email.trim(),
1345
+ className: "text-sm text-white px-5 py-2.5 rounded-xl disabled:opacity-40 transition-opacity",
1346
+ style: { backgroundColor: "var(--ac-primary, #2f80ed)" },
1347
+ children: t("liveChatIdentityConnect")
1348
+ }
1349
+ )
1350
+ ] })
1351
+ ] })
1352
+ ] });
1353
+ }
1354
+ function QueueView() {
1355
+ const lc = useLiveChatOrThrow();
1356
+ const { t, direction } = useI18n();
1357
+ return /* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col items-center justify-center p-8 text-center", dir: direction, children: [
1358
+ /* @__PURE__ */ jsx("div", { className: "h-16 w-16 rounded-2xl bg-blue-50 flex items-center justify-center mb-4", children: /* @__PURE__ */ jsx(Headset, { className: "h-8 w-8 text-blue-500" }) }),
1359
+ /* @__PURE__ */ jsx("div", { className: "h-2 w-2 rounded-full bg-blue-500 animate-pulse mb-4" }),
1360
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium mb-1", style: { color: "var(--ac-text)" }, children: t("liveChatConnecting") }),
1361
+ lc.queuePosition > 0 && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mb-4", children: t("liveChatPosition", { position: String(lc.queuePosition) }) }),
1362
+ /* @__PURE__ */ jsx(
1363
+ "button",
1364
+ {
1365
+ type: "button",
1366
+ onClick: lc.cancel,
1367
+ className: "text-xs text-muted-foreground hover:text-foreground underline mt-2",
1368
+ children: t("liveChatCancel")
1369
+ }
1370
+ )
1371
+ ] });
1372
+ }
1373
+ function ChatView() {
1374
+ const lc = useLiveChatOrThrow();
1375
+ const { t, language, direction } = useI18n();
1376
+ const [input, setInput] = useState("");
1377
+ const messagesEndRef = useRef(null);
1378
+ const isRTL = direction === "rtl";
1379
+ useEffect(() => {
1380
+ messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
1381
+ }, [lc.messages]);
1382
+ const handleSend = () => {
1383
+ if (!input.trim()) return;
1384
+ lc.send(input.trim());
1385
+ setInput("");
1386
+ };
1387
+ return /* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col min-h-0", dir: isRTL ? "rtl" : "ltr", children: [
1388
+ /* @__PURE__ */ jsxs("div", { className: "shrink-0 bg-green-50 border-b border-green-200 px-4 py-3 flex items-center justify-between", children: [
1389
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2.5", children: [
1390
+ /* @__PURE__ */ jsx("div", { className: "h-8 w-8 rounded-full bg-green-500 flex items-center justify-center", children: /* @__PURE__ */ jsx("span", { className: "text-xs text-white font-bold", children: lc.operatorName.charAt(0).toUpperCase() || "O" }) }),
1391
+ /* @__PURE__ */ jsxs("div", { children: [
1392
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-green-900", children: t("liveChatChattingWith", { name: lc.operatorName }) }),
1393
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
1394
+ /* @__PURE__ */ jsx("div", { className: "h-1.5 w-1.5 rounded-full bg-green-500" }),
1395
+ /* @__PURE__ */ jsx("span", { className: "text-[10px] text-green-600", children: "Online" })
1396
+ ] })
1397
+ ] })
1398
+ ] }),
1399
+ /* @__PURE__ */ jsx(
1400
+ "button",
1401
+ {
1402
+ type: "button",
1403
+ onClick: lc.end,
1404
+ className: "text-xs text-red-600 hover:text-red-800 bg-red-50 hover:bg-red-100 px-3 py-1.5 rounded-lg transition-colors",
1405
+ children: t("liveChatEndChat")
1406
+ }
1407
+ )
1408
+ ] }),
1409
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-y-auto px-4 py-3 space-y-1", children: [
1410
+ lc.messages.map((msg, idx) => {
1411
+ if (msg.senderType === "system") {
1412
+ return /* @__PURE__ */ jsx("div", { className: "flex justify-center my-3", children: /* @__PURE__ */ jsx("span", { className: "text-[11px] text-muted-foreground bg-muted/70 px-3 py-1 rounded-full", children: msg.content }) }, msg.id);
1413
+ }
1414
+ const isOperator = msg.senderType === "operator";
1415
+ const prevMsg = idx > 0 ? lc.messages[idx - 1] : null;
1416
+ const isFirstInGroup = !prevMsg || prevMsg.senderType !== msg.senderType || prevMsg.senderType === "system";
1417
+ const locale = language === "he" ? "he-IL" : "en-US";
1418
+ const timeStr = new Date(msg.timestamp).toLocaleTimeString(locale, {
1419
+ hour: "2-digit",
1420
+ minute: "2-digit",
1421
+ hour12: false
1422
+ });
1423
+ return /* @__PURE__ */ jsxs(
1424
+ "div",
1425
+ {
1426
+ className: `flex items-end gap-2 ${isOperator ? "justify-start" : "flex-row-reverse"} ${isFirstInGroup ? "mt-3" : "mt-0.5"}`,
1427
+ children: [
1428
+ /* @__PURE__ */ jsx("div", { className: "w-7 shrink-0", children: isOperator && isFirstInGroup && /* @__PURE__ */ jsx("div", { className: "h-7 w-7 rounded-full bg-green-500 flex items-center justify-center", children: /* @__PURE__ */ jsx("span", { className: "text-[11px] text-white font-bold", children: lc.operatorName.charAt(0).toUpperCase() || "O" }) }) }),
1429
+ /* @__PURE__ */ jsxs("div", { className: "max-w-[75%]", children: [
1430
+ isOperator && isFirstInGroup && /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mb-0.5 font-medium", children: lc.operatorName }),
1431
+ /* @__PURE__ */ jsx(
1432
+ "div",
1433
+ {
1434
+ className: `rounded-2xl px-3.5 py-2.5 text-[14px] leading-relaxed ${isOperator ? "bg-white border border-gray-200 text-gray-900 rounded-bl-md" : "text-white rounded-br-md"}`,
1435
+ style: !isOperator ? { backgroundColor: "var(--ac-primary, #2f80ed)" } : void 0,
1436
+ children: msg.content
1437
+ }
1438
+ ),
1439
+ /* @__PURE__ */ jsx("p", { className: `text-[10px] text-gray-400 mt-0.5 px-1 ${isOperator ? "" : "text-end"}`, children: timeStr })
1440
+ ] })
1441
+ ]
1442
+ },
1443
+ msg.id
1444
+ );
1445
+ }),
1446
+ /* @__PURE__ */ jsx("div", { ref: messagesEndRef })
1447
+ ] }),
1448
+ /* @__PURE__ */ jsx("div", { className: "shrink-0 border-t bg-white p-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
1449
+ /* @__PURE__ */ jsx(
1450
+ "input",
1451
+ {
1452
+ type: "text",
1453
+ value: input,
1454
+ onChange: (e) => setInput(e.target.value),
1455
+ onKeyDown: (e) => {
1456
+ if (e.key === "Enter" && !e.shiftKey) {
1457
+ e.preventDefault();
1458
+ handleSend();
1459
+ }
1460
+ },
1461
+ placeholder: t("typeMessage"),
1462
+ className: "flex-1 text-sm px-3.5 py-2.5 border rounded-xl bg-background focus:outline-none focus:ring-2",
1463
+ autoFocus: true
1464
+ }
1465
+ ),
1466
+ /* @__PURE__ */ jsx(
1467
+ "button",
1468
+ {
1469
+ type: "button",
1470
+ onClick: handleSend,
1471
+ disabled: !input.trim(),
1472
+ className: "shrink-0 h-10 w-10 rounded-xl flex items-center justify-center text-white disabled:opacity-40 transition-opacity",
1473
+ style: { backgroundColor: "var(--ac-primary, #2f80ed)" },
1474
+ children: /* @__PURE__ */ jsx(Send, { className: "h-4 w-4" })
1475
+ }
1476
+ )
1477
+ ] }) })
1478
+ ] });
1479
+ }
1480
+ function EndedView() {
1481
+ const lc = useLiveChatOrThrow();
1482
+ const { t, direction } = useI18n();
1483
+ const [selected, setSelected] = useState(null);
1484
+ const [comment, setComment] = useState("");
1485
+ const [submitted, setSubmitted] = useState(false);
1486
+ const isRTL = direction === "rtl";
1487
+ if (submitted) {
1488
+ return /* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col items-center justify-center p-8 text-center", dir: isRTL ? "rtl" : "ltr", children: [
1489
+ /* @__PURE__ */ jsx("div", { className: "h-14 w-14 rounded-2xl bg-green-50 flex items-center justify-center mb-4", children: /* @__PURE__ */ jsx(ThumbsUp, { className: "h-7 w-7 text-green-500" }) }),
1490
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium mb-1", style: { color: "var(--ac-text)" }, children: t("liveChatRateThank") }),
1491
+ /* @__PURE__ */ jsx(
1492
+ "button",
1493
+ {
1494
+ type: "button",
1495
+ onClick: lc.returnToAI,
1496
+ className: "text-sm font-medium mt-4 px-5 py-2 rounded-xl transition-colors",
1497
+ style: { backgroundColor: "var(--ac-primary, #2f80ed)", color: "white" },
1498
+ children: t("liveChatBackToAI")
1499
+ }
1500
+ )
1501
+ ] });
1502
+ }
1503
+ return /* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col items-center justify-center p-8", dir: isRTL ? "rtl" : "ltr", children: [
1504
+ /* @__PURE__ */ jsx("div", { className: "h-14 w-14 rounded-2xl bg-muted/50 flex items-center justify-center mb-4", children: /* @__PURE__ */ jsx(Headset, { className: "h-7 w-7 text-muted-foreground/50" }) }),
1505
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium mb-1", style: { color: "var(--ac-text)" }, children: t("liveChatEnded") }),
1506
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mb-5", children: t("liveChatRateTitle") }),
1507
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-4 mb-4", children: [
1508
+ /* @__PURE__ */ jsx(
1509
+ "button",
1510
+ {
1511
+ type: "button",
1512
+ onClick: () => setSelected("positive"),
1513
+ className: `p-3 rounded-full transition-colors ${selected === "positive" ? "bg-green-100 text-green-600" : "hover:bg-gray-100 text-gray-400"}`,
1514
+ children: /* @__PURE__ */ jsx(ThumbsUp, { className: "h-6 w-6" })
1515
+ }
1516
+ ),
1517
+ /* @__PURE__ */ jsx(
1518
+ "button",
1519
+ {
1520
+ type: "button",
1521
+ onClick: () => setSelected("negative"),
1522
+ className: `p-3 rounded-full transition-colors ${selected === "negative" ? "bg-red-100 text-red-600" : "hover:bg-gray-100 text-gray-400"}`,
1523
+ children: /* @__PURE__ */ jsx(ThumbsDown, { className: "h-6 w-6" })
1524
+ }
1525
+ )
1526
+ ] }),
1527
+ selected && /* @__PURE__ */ jsxs("div", { className: "w-full max-w-xs space-y-3", children: [
1528
+ /* @__PURE__ */ jsx(
1529
+ "textarea",
1530
+ {
1531
+ value: comment,
1532
+ onChange: (e) => setComment(e.target.value),
1533
+ placeholder: t("liveChatFeedbackPlaceholder"),
1534
+ className: "w-full text-sm p-3 border rounded-xl resize-none h-20 focus:outline-none focus:ring-2"
1535
+ }
1536
+ ),
1537
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-center gap-2", children: [
1538
+ /* @__PURE__ */ jsx(
1539
+ "button",
1540
+ {
1541
+ type: "button",
1542
+ onClick: () => {
1543
+ lc.submitRating(selected, comment || void 0);
1544
+ setSubmitted(true);
1545
+ },
1546
+ className: "text-sm text-white px-4 py-2 rounded-xl",
1547
+ style: { backgroundColor: "var(--ac-primary, #2f80ed)" },
1548
+ children: t("liveChatSubmit")
1549
+ }
1550
+ ),
1551
+ /* @__PURE__ */ jsx(
1552
+ "button",
1553
+ {
1554
+ type: "button",
1555
+ onClick: lc.returnToAI,
1556
+ className: "text-sm text-muted-foreground hover:text-foreground px-4 py-2",
1557
+ children: t("liveChatSkip")
1558
+ }
1559
+ )
1560
+ ] })
1561
+ ] }),
1562
+ !selected && /* @__PURE__ */ jsx(
1563
+ "button",
1564
+ {
1565
+ type: "button",
1566
+ onClick: lc.returnToAI,
1567
+ className: "text-xs text-muted-foreground hover:text-foreground underline mt-2",
1568
+ children: t("liveChatSkip")
1569
+ }
1570
+ )
1571
+ ] });
1572
+ }
1573
+ function PreviewEmbedPanel({ isOpen, isRightSide, zIndex }) {
1574
+ const previewEmbed = usePreviewEmbed();
1575
+ if (!previewEmbed) return null;
1576
+ const { preview, closePreview } = previewEmbed;
1577
+ const showPanel = isOpen && !!preview;
1578
+ return /* @__PURE__ */ jsxs(
1579
+ "div",
1580
+ {
1581
+ className: "fixed top-1/2 flex flex-col rounded-2xl border shadow-sm overflow-hidden",
1582
+ style: {
1583
+ backgroundColor: "var(--ac-background)",
1584
+ borderColor: "var(--ac-border)",
1585
+ zIndex,
1586
+ width: "min(560px, calc(100vw - 800px))",
1587
+ height: "70vh",
1588
+ ...isRightSide ? { right: "790px" } : { left: "790px" },
1589
+ transform: showPanel ? "translateY(-50%) translateX(0)" : `translateY(-50%) ${isRightSide ? "translateX(20px)" : "translateX(-20px)"}`,
1590
+ opacity: showPanel ? 1 : 0,
1591
+ pointerEvents: showPanel ? "auto" : "none",
1592
+ transition: "transform 300ms ease-in-out, opacity 300ms ease-in-out"
1593
+ },
1594
+ children: [
1595
+ /* @__PURE__ */ jsxs("div", { className: "bg-muted/30 px-5 py-4 border-b flex items-center justify-between shrink-0", style: { borderColor: "var(--ac-border)" }, children: [
1596
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 min-w-0", children: [
1597
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 w-10 h-10 rounded-xl bg-muted flex items-center justify-center", children: /* @__PURE__ */ jsx(ExternalLink, { className: "w-5 h-5 text-muted-foreground" }) }),
1598
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
1599
+ /* @__PURE__ */ jsx("h3", { className: "font-medium text-sm truncate", style: { color: "var(--ac-text)" }, children: preview?.title || "Preview" }),
1600
+ preview?.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-0.5 truncate", children: preview.description })
1601
+ ] })
1602
+ ] }),
1603
+ /* @__PURE__ */ jsx(
1604
+ "button",
1605
+ {
1606
+ type: "button",
1607
+ onClick: closePreview,
1608
+ className: "shrink-0 w-8 h-8 rounded-full border flex items-center justify-center hover:bg-muted transition-colors ml-3",
1609
+ style: { backgroundColor: "var(--ac-background)", borderColor: "var(--ac-border)" },
1610
+ children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4" })
1611
+ }
1612
+ )
1613
+ ] }),
1614
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-h-0", children: preview && /* @__PURE__ */ jsx(
1615
+ "iframe",
1616
+ {
1617
+ src: preview.url,
1618
+ className: "w-full h-full border-none",
1619
+ sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-presentation",
1620
+ title: preview.title || "Preview"
1621
+ },
1622
+ preview.url
1623
+ ) })
1624
+ ]
1625
+ }
1626
+ );
1627
+ }
1628
+
1629
+ export { CartDrawer, ChatFooter, ChatHeader, ChatInput, ChatInterface, FloatingButton, LiveChatPanel, MobileLiveChatDrawer, PreviewEmbedPanel, QuickQuestions, WelcomePage };
1630
+ //# sourceMappingURL=chunk-NWF735F5.js.map
1631
+ //# sourceMappingURL=chunk-NWF735F5.js.map