@gengage/assistant-fe 0.1.7 → 0.1.9

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 (134) hide show
  1. package/README.md +80 -282
  2. package/dist/assistant-fe.css +1 -1
  3. package/dist/chat/api.d.ts +1 -12
  4. package/dist/chat/api.d.ts.map +1 -1
  5. package/dist/chat/components/ChatDrawer.d.ts +15 -1
  6. package/dist/chat/components/ChatDrawer.d.ts.map +1 -1
  7. package/dist/chat/components/ChoicePrompter.d.ts +1 -0
  8. package/dist/chat/components/ChoicePrompter.d.ts.map +1 -1
  9. package/dist/chat/components/ComparisonTable.d.ts +5 -3
  10. package/dist/chat/components/ComparisonTable.d.ts.map +1 -1
  11. package/dist/chat/components/PanelTopBar.d.ts +2 -0
  12. package/dist/chat/components/PanelTopBar.d.ts.map +1 -1
  13. package/dist/chat/components/ProductSummaryCard.d.ts.map +1 -1
  14. package/dist/chat/components/ReviewHighlights.d.ts +3 -0
  15. package/dist/chat/components/ReviewHighlights.d.ts.map +1 -1
  16. package/dist/chat/components/renderUISpec.d.ts +0 -5
  17. package/dist/chat/components/renderUISpec.d.ts.map +1 -1
  18. package/dist/chat/index.d.ts +18 -9
  19. package/dist/chat/index.d.ts.map +1 -1
  20. package/dist/chat/locales/en.d.ts.map +1 -1
  21. package/dist/chat/locales/tr.d.ts.map +1 -1
  22. package/dist/chat/session-persistence.d.ts +3 -0
  23. package/dist/chat/session-persistence.d.ts.map +1 -1
  24. package/dist/chat/types.d.ts +23 -25
  25. package/dist/chat/types.d.ts.map +1 -1
  26. package/dist/chat.cjs +1 -1
  27. package/dist/chat.iife.js +24 -24
  28. package/dist/chat.iife.js.map +1 -1
  29. package/dist/chat.js +8 -9
  30. package/dist/chat.js.map +1 -1
  31. package/dist/common/action-router.d.ts.map +1 -1
  32. package/dist/common/activity-tracker.d.ts +1 -1
  33. package/dist/common/analytics.d.ts +12 -8
  34. package/dist/common/analytics.d.ts.map +1 -1
  35. package/dist/common/api-paths.d.ts +2 -5
  36. package/dist/common/api-paths.d.ts.map +1 -1
  37. package/dist/common/config-schema.d.ts.map +1 -1
  38. package/dist/common/debug.d.ts +14 -0
  39. package/dist/common/debug.d.ts.map +1 -0
  40. package/dist/common/events.d.ts.map +1 -1
  41. package/dist/common/index.d.ts +2 -2
  42. package/dist/common/index.d.ts.map +1 -1
  43. package/dist/common/overlay.d.ts +19 -0
  44. package/dist/common/overlay.d.ts.map +1 -1
  45. package/dist/common/{v1-protocol-adapter.d.ts → protocol-adapter.d.ts} +2 -2
  46. package/dist/common/protocol-adapter.d.ts.map +1 -0
  47. package/dist/common/quantity-stepper.d.ts +10 -10
  48. package/dist/common/quantity-stepper.d.ts.map +1 -1
  49. package/dist/common/safe-html.d.ts.map +1 -1
  50. package/dist/common/streaming.d.ts.map +1 -1
  51. package/dist/common/tts-player.d.ts +2 -0
  52. package/dist/common/tts-player.d.ts.map +1 -1
  53. package/dist/common/types.d.ts +1 -1
  54. package/dist/common/voice-input.d.ts +1 -0
  55. package/dist/common/voice-input.d.ts.map +1 -1
  56. package/dist/common/widget-base.d.ts.map +1 -1
  57. package/dist/common.cjs +1 -1
  58. package/dist/common.cjs.map +1 -1
  59. package/dist/common.js +173 -172
  60. package/dist/common.js.map +1 -1
  61. package/dist/index-BWPx4pM7.cjs +13 -0
  62. package/dist/index-BWPx4pM7.cjs.map +1 -0
  63. package/dist/index-CEt87kCd.js +4463 -0
  64. package/dist/index-CEt87kCd.js.map +1 -0
  65. package/dist/index-DL4CAkyL.cjs +2 -0
  66. package/dist/index-DL4CAkyL.cjs.map +1 -0
  67. package/dist/{index-BH-V2lWn.js → index-DR2uepzb.js} +108 -106
  68. package/dist/index-DR2uepzb.js.map +1 -0
  69. package/dist/index.cjs +1 -1
  70. package/dist/index.js +16 -16
  71. package/dist/native.cjs +1 -1
  72. package/dist/native.iife.js +18 -18
  73. package/dist/native.iife.js.map +1 -1
  74. package/dist/native.js +1 -1
  75. package/dist/qna/index.d.ts +19 -0
  76. package/dist/qna/index.d.ts.map +1 -1
  77. package/dist/qna/types.d.ts +2 -2
  78. package/dist/qna/types.d.ts.map +1 -1
  79. package/dist/qna.cjs +1 -1
  80. package/dist/qna.cjs.map +1 -1
  81. package/dist/qna.css +1 -1
  82. package/dist/qna.iife.js +7 -7
  83. package/dist/qna.iife.js.map +1 -1
  84. package/dist/qna.js +14 -14
  85. package/dist/qna.js.map +1 -1
  86. package/dist/quantity-stepper-C-nV4lwi.js +77 -0
  87. package/dist/quantity-stepper-C-nV4lwi.js.map +1 -0
  88. package/dist/quantity-stepper-CURMkwRF.cjs +2 -0
  89. package/dist/quantity-stepper-CURMkwRF.cjs.map +1 -0
  90. package/dist/{schemas-yF4IOEUi.js → schemas-DIhL3DkL.js} +1166 -947
  91. package/dist/schemas-DIhL3DkL.js.map +1 -0
  92. package/dist/schemas-Dsr0bbO_.cjs +86 -0
  93. package/dist/schemas-Dsr0bbO_.cjs.map +1 -0
  94. package/dist/simrel/api.d.ts +1 -1
  95. package/dist/simrel/api.d.ts.map +1 -1
  96. package/dist/simrel/components/GroupTabs.d.ts +1 -1
  97. package/dist/simrel/components/GroupTabs.d.ts.map +1 -1
  98. package/dist/simrel/components/ProductCard.d.ts +1 -1
  99. package/dist/simrel/components/ProductCard.d.ts.map +1 -1
  100. package/dist/simrel/components/ProductGrid.d.ts +1 -1
  101. package/dist/simrel/components/ProductGrid.d.ts.map +1 -1
  102. package/dist/simrel/index.d.ts +20 -1
  103. package/dist/simrel/index.d.ts.map +1 -1
  104. package/dist/simrel/locales/en.d.ts.map +1 -1
  105. package/dist/simrel/locales/tr.d.ts.map +1 -1
  106. package/dist/simrel/types.d.ts +1 -0
  107. package/dist/simrel/types.d.ts.map +1 -1
  108. package/dist/simrel.cjs +1 -1
  109. package/dist/simrel.cjs.map +1 -1
  110. package/dist/simrel.css +1 -1
  111. package/dist/simrel.iife.js +11 -11
  112. package/dist/simrel.iife.js.map +1 -1
  113. package/dist/simrel.js +123 -111
  114. package/dist/simrel.js.map +1 -1
  115. package/package.json +1 -1
  116. package/dist/chat/components/ProactivePopup.d.ts +0 -20
  117. package/dist/chat/components/ProactivePopup.d.ts.map +0 -1
  118. package/dist/chat/heartbeat.d.ts +0 -71
  119. package/dist/chat/heartbeat.d.ts.map +0 -1
  120. package/dist/common/v1-protocol-adapter.d.ts.map +0 -1
  121. package/dist/index-1yPxOqAw.cjs +0 -13
  122. package/dist/index-1yPxOqAw.cjs.map +0 -1
  123. package/dist/index-BH-V2lWn.js.map +0 -1
  124. package/dist/index-BelS6Vnv.cjs +0 -2
  125. package/dist/index-BelS6Vnv.cjs.map +0 -1
  126. package/dist/index-CERWfDdF.js +0 -4571
  127. package/dist/index-CERWfDdF.js.map +0 -1
  128. package/dist/quantity-stepper-B8kX8GbN.js +0 -209
  129. package/dist/quantity-stepper-B8kX8GbN.js.map +0 -1
  130. package/dist/quantity-stepper-UbAp53Ow.cjs +0 -2
  131. package/dist/quantity-stepper-UbAp53Ow.cjs.map +0 -1
  132. package/dist/schemas-DHzfUzwA.cjs +0 -86
  133. package/dist/schemas-DHzfUzwA.cjs.map +0 -1
  134. package/dist/schemas-yF4IOEUi.js.map +0 -1
@@ -1,4571 +0,0 @@
1
- import { b as ve, c as ze, a as De, A as Re, r as Ue, o as M, s as v, f as D, C as ae, d as oe, u as re, v as Q, e as K, _ as we, B as qe, D as He, j, t as Fe, i as Oe, E as je, F as Ve, g as $e, G as Ge, H as Ke, I as ge, m as We, J as Ye, y as Qe, x as Xe, n as Je, K as Ze, L as de, h as et, M as tt, N as at, l as nt, O as it, P as ot, Q as rt, R as st, S as ct, T as lt } from "./schemas-yF4IOEUi.js";
2
- import { s as $, i as W, f as q, c as se, d as R, a as X, e as G, r as _e, g as ye, b as ke } from "./quantity-stepper-B8kX8GbN.js";
3
- function gt() {
4
- const o = Date.now(), e = new Uint8Array(16);
5
- crypto.getRandomValues(e), e[0] = o / 2 ** 40 & 255, e[1] = o / 2 ** 32 & 255, e[2] = o / 2 ** 24 & 255, e[3] = o / 2 ** 16 & 255, e[4] = o / 2 ** 8 & 255, e[5] = o & 255, e[6] = e[6] & 15 | 112, e[8] = e[8] & 63 | 128;
6
- const t = Array.from(e, (a) => a.toString(16).padStart(2, "0")).join("");
7
- return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
8
- }
9
- class dt {
10
- constructor(e) {
11
- this._handlers = /* @__PURE__ */ new Map(), this._destroyed = !1, this._namespace = e.namespace, this._allowedOrigins = e.allowedOrigins ?? ["*"], this._onMessage = e.onMessage, this._allowedOrigins.includes("*"), this._messageListener = (t) => this._handlePostMessage(t), window.addEventListener("message", this._messageListener);
12
- }
13
- /** Send a message to the host page via CustomEvent on window. */
14
- send(e, t) {
15
- if (this._destroyed) return;
16
- const a = {
17
- namespace: this._namespace,
18
- type: e
19
- };
20
- t !== void 0 && (a.payload = t), window.dispatchEvent(
21
- new CustomEvent("gengage:bridge:message", {
22
- detail: a,
23
- bubbles: !1
24
- })
25
- );
26
- }
27
- /**
28
- * Register a handler for a specific message type.
29
- * Returns an unsubscribe function.
30
- */
31
- on(e, t) {
32
- this._handlers.has(e) || this._handlers.set(e, /* @__PURE__ */ new Set());
33
- const a = this._handlers.get(e);
34
- return a.add(t), () => {
35
- a.delete(t), a.size === 0 && this._handlers.delete(e);
36
- };
37
- }
38
- /** Clean up all event listeners and handlers. */
39
- destroy() {
40
- this._destroyed || (this._destroyed = !0, window.removeEventListener("message", this._messageListener), this._handlers.clear());
41
- }
42
- // ---------------------------------------------------------------------------
43
- // Private
44
- // ---------------------------------------------------------------------------
45
- _handlePostMessage(e) {
46
- if (this._destroyed || !this._isOriginAllowed(e.origin)) return;
47
- const t = e.data;
48
- if (!pt(t) || t.gengage !== this._namespace) return;
49
- const a = { type: t.type };
50
- t.payload !== void 0 && (a.payload = t.payload), this._onMessage?.(a);
51
- const n = this._handlers.get(a.type);
52
- if (n)
53
- for (const i of n)
54
- i(a.payload);
55
- }
56
- _isOriginAllowed(e) {
57
- return this._allowedOrigins.includes("*") ? !0 : this._allowedOrigins.includes(e);
58
- }
59
- }
60
- function pt(o) {
61
- if (typeof o != "object" || o === null) return !1;
62
- const e = o;
63
- return typeof e.gengage == "string" && typeof e.type == "string";
64
- }
65
- const ht = console;
66
- function ut(o, e, t = {}) {
67
- const a = o.action, n = t.logger ?? ht;
68
- switch (a.kind) {
69
- case "open_chat": {
70
- e.openChat?.(a.payload);
71
- return;
72
- }
73
- case "navigate": {
74
- if (typeof a.url != "string") {
75
- J(a, e, t, n);
76
- return;
77
- }
78
- const i = typeof a.newTab == "boolean" ? a.newTab : void 0;
79
- if (e.navigate) {
80
- i !== void 0 ? e.navigate({ url: a.url, newTab: i }) : e.navigate({ url: a.url });
81
- return;
82
- }
83
- mt(a.url, i);
84
- return;
85
- }
86
- case "save_session": {
87
- if (typeof a.sessionId != "string" || typeof a.sku != "string") {
88
- J(a, e, t, n);
89
- return;
90
- }
91
- e.saveSession?.({ sessionId: a.sessionId, sku: a.sku });
92
- return;
93
- }
94
- case "add_to_cart": {
95
- if (typeof a.sku != "string" || typeof a.quantity != "number" || typeof a.cartCode != "string") {
96
- J(a, e, t, n);
97
- return;
98
- }
99
- e.addToCart?.({
100
- sku: a.sku,
101
- quantity: a.quantity,
102
- cartCode: a.cartCode
103
- });
104
- return;
105
- }
106
- case "script_call": {
107
- if (t.allowScriptCall === !1) {
108
- J(a, e, t, n);
109
- return;
110
- }
111
- if (typeof a.name != "string") {
112
- J(a, e, t, n);
113
- return;
114
- }
115
- const i = ft(a.payload) ? a.payload : void 0;
116
- i !== void 0 ? e.scriptCall?.({ name: a.name, payload: i }) : e.scriptCall?.({ name: a.name });
117
- return;
118
- }
119
- default:
120
- J(a, e, t, n);
121
- }
122
- }
123
- function J(o, e, t, a) {
124
- const n = t.unknownActionPolicy ?? "log-and-ignore";
125
- if (n === "delegate") {
126
- e.unknown?.(o), e.unknown || a.warn("[gengage] Unknown action received without delegate handler", o);
127
- return;
128
- }
129
- if (n === "throw")
130
- throw new Error(`[gengage] Unknown action kind: ${o.kind}`);
131
- a.warn("[gengage] Unknown action ignored", o);
132
- }
133
- function mt(o, e) {
134
- if (!(typeof window > "u")) {
135
- if (e) {
136
- window.open(o, "_blank", "noopener,noreferrer");
137
- return;
138
- }
139
- window.location.href = o;
140
- }
141
- }
142
- function ft(o) {
143
- return typeof o == "object" && o !== null && !Array.isArray(o);
144
- }
145
- const bt = ["image/jpeg", "image/png", "image/webp"], xt = 5 * 1024 * 1024;
146
- function vt(o) {
147
- return bt.includes(o.type) ? o.size > xt ? { ok: !1, reason: "too_large" } : { ok: !0 } : { ok: !1, reason: "invalid_type" };
148
- }
149
- function wt(o, e) {
150
- const t = o.type, a = o.payload != null && typeof o.payload == "object" && !Array.isArray(o.payload) ? o.payload : {}, n = (i) => {
151
- const s = { ...a };
152
- for (const [l, r] of Object.entries(i))
153
- l in s || (s[l] = r);
154
- return s;
155
- };
156
- switch (t) {
157
- case "inputText": {
158
- const i = {
159
- is_launcher: 0
160
- };
161
- return e.pageContext?.extra && (i.page_details = e.pageContext.extra), "is_suggested_text" in a || (i.is_suggested_text = 0), { ...o, payload: n(i) };
162
- }
163
- case "findSimilar": {
164
- const i = {
165
- is_launcher: 0
166
- };
167
- return o.title && (i.text = o.title), o.title && (i.input = o.title), { ...o, payload: n(i) };
168
- }
169
- case "getComparisonTable":
170
- return o;
171
- case "addToCart": {
172
- const i = {};
173
- return "error_message" in a || (i.error_message = ""), { ...o, payload: n(i) };
174
- }
175
- case "reviewSummary": {
176
- const i = {};
177
- return e.pageContext?.sku && !("sku" in a) && (i.sku = e.pageContext.sku), Object.keys(i).length === 0 ? o : { ...o, payload: n(i) };
178
- }
179
- default:
180
- return o;
181
- }
182
- }
183
- const _t = {
184
- user_message: "inputText"
185
- };
186
- function yt(o) {
187
- const { action: e, type: t, payload: a, ...n } = o, i = t ?? e?.type ?? "inputText", s = a ?? e?.payload, l = _t[i] ?? i, r = {
188
- ...n,
189
- type: l
190
- };
191
- return s !== void 0 && (r.payload = typeof s == "string" ? { text: s } : s), JSON.stringify(r);
192
- }
193
- function kt(o) {
194
- const e = o.type ?? o.action?.type ?? "inputText", t = o.payload ?? o.action?.payload;
195
- let a = o.action?.title ?? "";
196
- (e === "inputText" || e === "user_message") && (typeof t == "string" ? a = t : t && typeof t == "object" && "text" in t && (a = String(t.text)));
197
- const n = {
198
- message: a,
199
- session_id: o.session_id
200
- };
201
- if (o.user_id && (n.user_id = o.user_id), o.locale && (n.output_language = o.locale), o.meta?.outputLanguage && (n.output_language = o.meta.outputLanguage), o.sku || o.page_type) {
202
- const i = {};
203
- o.page_type && (i.screen_type = o.page_type), o.sku && (i.sku_list = [o.sku]), n.screen_context = i;
204
- }
205
- return e !== "inputText" && e !== "user_message" && (n.action_type = e, t !== void 0 && (n.action_payload = typeof t == "string" ? { text: t } : t)), JSON.stringify(n);
206
- }
207
- function Ct(o, e, t) {
208
- const a = ve("process_action", t), n = new AbortController();
209
- return (async () => {
210
- try {
211
- const s = t.backendType === "acap" ? kt(o) : yt(o), l = t.attachment !== void 0;
212
- let r;
213
- if (l) {
214
- const p = new FormData();
215
- p.append("request", s), t.attachment !== void 0 && p.append("attachment", t.attachment), r = {
216
- method: "POST",
217
- body: p,
218
- signal: n.signal
219
- };
220
- } else
221
- r = {
222
- method: "POST",
223
- headers: { "Content-Type": "application/json" },
224
- body: s,
225
- signal: n.signal
226
- };
227
- const c = await fetch(a, r);
228
- if (!c.ok) {
229
- let p = c.statusText;
230
- try {
231
- const d = await c.json(), f = d.detail ?? d.message ?? d.error;
232
- typeof f == "string" && (p = f);
233
- } catch {
234
- }
235
- e.onError(new Error(`HTTP ${c.status}: ${p}`));
236
- return;
237
- }
238
- let g = !1;
239
- const h = () => {
240
- g || (g = !0, e.onDone());
241
- };
242
- await ze(c, {
243
- onEvent: (p) => {
244
- const d = De(p);
245
- if (d)
246
- switch (d.type) {
247
- case "text_chunk":
248
- e.onTextChunk(d.content, d.final === !0, {
249
- productMentions: d.productMentions,
250
- skuToProductItem: d.skuToProductItem,
251
- conversationMode: d.conversationMode
252
- });
253
- break;
254
- case "ui_spec":
255
- e.onUISpec(d.spec, d.widget, d.panelHint);
256
- break;
257
- case "action":
258
- e.onAction(d);
259
- break;
260
- case "metadata":
261
- e.onMetadata(d);
262
- break;
263
- case "error":
264
- e.onError(new Error(d.message));
265
- break;
266
- case "done":
267
- h();
268
- break;
269
- }
270
- },
271
- onError: e.onError,
272
- signal: n.signal
273
- }), h();
274
- } catch (s) {
275
- if (s instanceof DOMException && s.name === "AbortError") return;
276
- e.onError(s instanceof Error ? s : new Error(String(s)));
277
- }
278
- })(), n;
279
- }
280
- async function Et(o, e) {
281
- const t = ve("proactive_action", e);
282
- try {
283
- const a = await fetch(t, {
284
- method: "POST",
285
- headers: { "Content-Type": "application/json" },
286
- body: JSON.stringify(o)
287
- });
288
- return a.ok ? await a.json() : null;
289
- } catch {
290
- return null;
291
- }
292
- }
293
- const ce = {
294
- headerTitle: "Ürün Uzmanı",
295
- inputPlaceholder: "Ürün ara, soru sor",
296
- sendButton: "Gönder",
297
- closeButton: "Kapat",
298
- openButton: "Sohbeti aç",
299
- newChatButton: "Yeni sohbet",
300
- poweredBy: "Powered by Gengage",
301
- errorMessage: "Bir hata oluştu. Lütfen tekrar deneyin.",
302
- retryButton: "Tekrar Dene",
303
- loadingMessage: "Düşünüyorum...",
304
- productCtaLabel: "İncele",
305
- attachImageButton: "Resim ekle",
306
- removeAttachmentButton: "Resmi kaldır",
307
- invalidFileType: "Sadece JPEG, PNG ve WebP dosyaları destekleniyor.",
308
- fileTooLarge: "Dosya boyutu 5 MB'dan küçük olmalıdır.",
309
- aiTopPicksTitle: "Sizin İçin En İyiler",
310
- roleWinner: "En Beğendiğim",
311
- roleBestValue: "En Uygun Fiyatlı",
312
- roleBestAlternative: "En İyi Alternatif",
313
- viewDetails: "Detayları Gör",
314
- groundingReviewCta: "Yorumları Oku",
315
- groundingReviewSubtitle: "{count} yorum mevcut",
316
- variantsLabel: "Varyantlar",
317
- sortRelated: "Önerilen",
318
- sortPriceAsc: "Fiyat ↑",
319
- sortPriceDesc: "Fiyat ↓",
320
- compareSelected: "Karşılaştır",
321
- panelTitleProductDetails: "Ürün Detayı",
322
- panelTitleSimilarProducts: "Benzer Ürünler",
323
- panelTitleComparisonResults: "Karşılaştırma Sonuçları",
324
- panelTitleCategories: "Kategoriler",
325
- panelTitleSearchResults: "Arama Sonuçları",
326
- inStockLabel: "Stokta",
327
- outOfStockLabel: "Tükendi",
328
- findSimilarLabel: "Benzerlerini Bul",
329
- choicePrompterHeading: "Kararsız mı kaldın?",
330
- choicePrompterSuggestion: "Ürünleri seçip karşılaştırabilirsin",
331
- choicePrompterCta: "Seç ve Karşılaştır",
332
- viewMoreLabel: "Daha Fazla Göster",
333
- similarProductsLabel: "Benzer Ürünler",
334
- addToCartButton: "Sepete Ekle",
335
- shareButton: "Paylaş",
336
- productInfoTab: "Ürün Bilgileri",
337
- specificationsTab: "Teknik Özellikler",
338
- recommendedChoiceLabel: "Önerilen Seçim",
339
- highlightsLabel: "Öne Çıkan Özellikler",
340
- keyDifferencesLabel: "Temel Farklar",
341
- specialCasesLabel: "Özel Durumlar İçin",
342
- emptyReviewsMessage: "Yorum özeti bulunamadı.",
343
- closeAriaLabel: "Kapat",
344
- startChatLabel: "Sohbete Başla",
345
- voiceButton: "Sesli giriş",
346
- voiceListening: "Dinleniyor...",
347
- voiceNotSupported: "Sesli giriş bu tarayıcıda desteklenmiyor.",
348
- voicePermissionDenied: "Mikrofon erişimi reddedildi.",
349
- voiceError: "Sesli giriş hatası.",
350
- handoffHeading: "Destek temsilcisine aktarılıyor",
351
- productNotFoundMessage: "Bu ürün bilgisi şu an kullanılamıyor. Başka bir konuda yardımcı olabilirim."
352
- }, St = {
353
- headerTitle: "Product Expert",
354
- inputPlaceholder: "Search products, ask questions",
355
- sendButton: "Send",
356
- closeButton: "Close",
357
- openButton: "Open chat",
358
- newChatButton: "New chat",
359
- poweredBy: "Powered by Gengage",
360
- errorMessage: "Something went wrong. Please try again.",
361
- retryButton: "Retry",
362
- loadingMessage: "Thinking...",
363
- productCtaLabel: "View",
364
- attachImageButton: "Attach image",
365
- removeAttachmentButton: "Remove image",
366
- invalidFileType: "Only JPEG, PNG and WebP files are supported.",
367
- fileTooLarge: "File must be smaller than 5 MB.",
368
- aiTopPicksTitle: "Top Picks for You",
369
- roleWinner: "Top Pick",
370
- roleBestValue: "Best Value",
371
- roleBestAlternative: "Best Alternative",
372
- viewDetails: "View Details",
373
- groundingReviewCta: "Read Reviews",
374
- groundingReviewSubtitle: "{count} reviews available",
375
- variantsLabel: "Variants",
376
- sortRelated: "Related",
377
- sortPriceAsc: "Price ↑",
378
- sortPriceDesc: "Price ↓",
379
- compareSelected: "Compare",
380
- panelTitleProductDetails: "Product Details",
381
- panelTitleSimilarProducts: "Similar Products",
382
- panelTitleComparisonResults: "Comparison Results",
383
- panelTitleCategories: "Categories",
384
- panelTitleSearchResults: "Search Results",
385
- inStockLabel: "In Stock",
386
- outOfStockLabel: "Out of Stock",
387
- findSimilarLabel: "Find Similar",
388
- choicePrompterHeading: "Can't decide?",
389
- choicePrompterSuggestion: "Select products to compare them",
390
- choicePrompterCta: "Select & Compare",
391
- viewMoreLabel: "Show More",
392
- similarProductsLabel: "Similar Products",
393
- addToCartButton: "Add to Cart",
394
- shareButton: "Share",
395
- productInfoTab: "Product Info",
396
- specificationsTab: "Specifications",
397
- recommendedChoiceLabel: "Recommended Choice",
398
- highlightsLabel: "Key Highlights",
399
- keyDifferencesLabel: "Key Differences",
400
- specialCasesLabel: "For Special Cases",
401
- emptyReviewsMessage: "No review summary found.",
402
- closeAriaLabel: "Close",
403
- startChatLabel: "Start Chat",
404
- voiceButton: "Voice input",
405
- voiceListening: "Listening...",
406
- voiceNotSupported: "Voice input is not supported in this browser.",
407
- voicePermissionDenied: "Microphone access denied.",
408
- voiceError: "Voice input error.",
409
- handoffHeading: "Transferring to a support agent",
410
- productNotFoundMessage: "Product information is currently unavailable. I can help with something else."
411
- };
412
- function Tt(o) {
413
- return o ? o.toLowerCase().split("-")[0] ?? "tr" : "tr";
414
- }
415
- function It(o) {
416
- return Tt(o) === "en" ? St : ce;
417
- }
418
- function Lt() {
419
- return Ce() !== null;
420
- }
421
- function Ce() {
422
- const o = globalThis;
423
- return o.SpeechRecognition ?? o.webkitSpeechRecognition ?? null;
424
- }
425
- class Nt {
426
- constructor(e, t) {
427
- this.recognition = null, this._state = "idle", this.silenceTimer = null, this.accumulatedTranscript = "", this.intentionalStop = !1, this.callbacks = e, this.lang = t?.lang ?? "tr-TR", this.silenceTimeoutMs = t?.silenceTimeoutMs ?? 1500, this.autoSubmit = t?.autoSubmit ?? !0;
428
- }
429
- get state() {
430
- return this._state;
431
- }
432
- /**
433
- * Start listening. Requests microphone permission on first call.
434
- */
435
- start() {
436
- if (this._state === "listening") return;
437
- const e = Ce();
438
- if (!e) {
439
- this.setState("error"), this.callbacks.onError?.("not-supported", "Web Speech API is not supported in this browser.");
440
- return;
441
- }
442
- if (typeof globalThis.isSecureContext < "u" && !globalThis.isSecureContext) {
443
- this.setState("error"), this.callbacks.onError?.("not-allowed", "Voice input requires HTTPS.");
444
- return;
445
- }
446
- this.accumulatedTranscript = "", this.intentionalStop = !1;
447
- const t = new e();
448
- t.continuous = !0, t.interimResults = !0, t.lang = this.lang, t.maxAlternatives = 1, t.onstart = () => {
449
- this.setState("listening");
450
- }, t.onresult = (a) => {
451
- this.clearSilenceTimer();
452
- let n = "", i = "";
453
- for (let s = a.resultIndex; s < a.results.length; s++) {
454
- const l = a.results[s];
455
- if (!l) continue;
456
- const r = l[0];
457
- r && (l.isFinal ? i += r.transcript : n += r.transcript);
458
- }
459
- i && (this.accumulatedTranscript += i, this.callbacks.onFinal?.(this.accumulatedTranscript)), n && this.callbacks.onInterim?.(this.accumulatedTranscript + n), this.autoSubmit && this.accumulatedTranscript && this.startSilenceTimer();
460
- }, t.onerror = (a) => {
461
- const n = Pt(a.error);
462
- this.intentionalStop && (a.error === "no-speech" || a.error === "aborted") || (this.setState("error"), this.callbacks.onError?.(n, a.message || a.error));
463
- }, t.onend = () => {
464
- if (this.clearSilenceTimer(), this._state === "listening" && !this.intentionalStop) {
465
- try {
466
- t.start();
467
- } catch {
468
- this.setState("idle");
469
- }
470
- return;
471
- }
472
- this.setState("idle");
473
- }, this.recognition = t;
474
- try {
475
- t.start();
476
- } catch {
477
- this.setState("error"), this.callbacks.onError?.("unknown", "Failed to start speech recognition.");
478
- }
479
- }
480
- /**
481
- * Stop listening. Returns the accumulated transcript.
482
- */
483
- stop() {
484
- if (this.intentionalStop = !0, this.clearSilenceTimer(), this.recognition) {
485
- try {
486
- this.recognition.stop();
487
- } catch {
488
- }
489
- this.recognition = null;
490
- }
491
- return this.setState("idle"), this.accumulatedTranscript;
492
- }
493
- /**
494
- * Abort listening. Discards any accumulated transcript.
495
- */
496
- abort() {
497
- if (this.intentionalStop = !0, this.clearSilenceTimer(), this.accumulatedTranscript = "", this.recognition) {
498
- try {
499
- this.recognition.abort();
500
- } catch {
501
- }
502
- this.recognition = null;
503
- }
504
- this.setState("idle");
505
- }
506
- /** Destroy the instance and release resources. */
507
- destroy() {
508
- this.abort();
509
- }
510
- setState(e) {
511
- this._state !== e && (this._state = e, this.callbacks.onStateChange?.(e));
512
- }
513
- startSilenceTimer() {
514
- this.clearSilenceTimer(), this.silenceTimer = setTimeout(() => {
515
- const e = this.stop();
516
- e.trim() && this.callbacks.onAutoSubmit?.(e.trim());
517
- }, this.silenceTimeoutMs);
518
- }
519
- clearSilenceTimer() {
520
- this.silenceTimer !== null && (clearTimeout(this.silenceTimer), this.silenceTimer = null);
521
- }
522
- }
523
- function Pt(o) {
524
- switch (o) {
525
- case "not-allowed":
526
- return "not-allowed";
527
- case "no-speech":
528
- return "no-speech";
529
- case "audio-capture":
530
- return "no-microphone";
531
- case "network":
532
- return "network";
533
- case "aborted":
534
- return "aborted";
535
- default:
536
- return "unknown";
537
- }
538
- }
539
- function At(o) {
540
- const e = document.createElement("div");
541
- e.className = "gengage-chat-kvkk-banner", e.setAttribute("role", "alert");
542
- const t = document.createElement("div");
543
- t.className = "gengage-chat-kvkk-content", t.innerHTML = $(o.htmlContent), e.appendChild(t);
544
- const a = document.createElement("button");
545
- return a.className = "gengage-chat-kvkk-dismiss", a.type = "button", a.setAttribute("aria-label", o.closeAriaLabel ?? "KVKK bildirimini kapat"), a.textContent = "×", a.addEventListener("click", o.onDismiss), e.appendChild(a), e;
546
- }
547
- class Mt {
548
- constructor(e) {
549
- this._el = document.createElement("div"), this._el.className = "gengage-chat-panel-topbar", this._backBtn = document.createElement("button"), this._backBtn.className = "gengage-chat-panel-topbar-back", this._backBtn.type = "button", this._backBtn.disabled = !0, this._backBtn.setAttribute("aria-label", "Back"), this._backBtn.textContent = "←", this._backBtn.addEventListener("click", () => e.onBack()), this._titleEl = document.createElement("span"), this._titleEl.className = "gengage-chat-panel-topbar-title", this._forwardBtn = document.createElement("button"), this._forwardBtn.className = "gengage-chat-panel-topbar-forward", this._forwardBtn.type = "button", this._forwardBtn.disabled = !0, this._forwardBtn.setAttribute("aria-label", "Forward"), this._forwardBtn.textContent = "→", this._forwardBtn.addEventListener("click", () => e.onForward()), this._el.appendChild(this._backBtn), this._el.appendChild(this._titleEl), this._el.appendChild(this._forwardBtn);
550
- }
551
- update(e, t, a) {
552
- this._backBtn.disabled = !e, this._forwardBtn.disabled = !t, this._titleEl.textContent = a;
553
- }
554
- getElement() {
555
- return this._el;
556
- }
557
- }
558
- class Bt {
559
- constructor(e) {
560
- this._onThumbnailClick = e.onThumbnailClick, this._el = document.createElement("div"), this._el.className = "gengage-chat-thumbnails-column", this._el.style.display = "none";
561
- }
562
- getElement() {
563
- return this._el;
564
- }
565
- setEntries(e) {
566
- const t = /* @__PURE__ */ new Set(), a = [];
567
- for (const n of e)
568
- t.has(n.sku) || (t.add(n.sku), a.push(n));
569
- this._el.innerHTML = "";
570
- for (const n of a) {
571
- const i = document.createElement("button");
572
- if (i.type = "button", i.className = "gengage-chat-thumbnail-btn", i.title = n.sku, W(n.imageUrl)) {
573
- const s = document.createElement("img");
574
- s.className = "gengage-chat-thumbnail-img", s.src = n.imageUrl, s.alt = n.sku, s.width = 40, s.height = 40, i.appendChild(s);
575
- }
576
- i.addEventListener("click", () => {
577
- this._onThumbnailClick(n.threadId);
578
- }), this._el.appendChild(i);
579
- }
580
- }
581
- show() {
582
- this._el.style.display = "";
583
- }
584
- hide() {
585
- this._el.style.display = "none";
586
- }
587
- }
588
- const pe = {
589
- search: '<svg viewBox="0 0 16 16" class="gengage-chat-icon"><circle cx="6.5" cy="6.5" r="5" fill="none" stroke="currentColor" stroke-width="1.5"/><line x1="10" y1="10" x2="15" y2="15" stroke="currentColor" stroke-width="1.5"/></svg>',
590
- review: '<svg viewBox="0 0 16 16" class="gengage-chat-icon"><polygon points="8,1 10,6 15,6 11,9 12.5,14 8,11 3.5,14 5,9 1,6 6,6" fill="none" stroke="currentColor" stroke-width="1.5"/></svg>',
591
- info: '<svg viewBox="0 0 16 16" class="gengage-chat-icon"><circle cx="8" cy="8" r="7" fill="none" stroke="currentColor" stroke-width="1.5"/><line x1="8" y1="7" x2="8" y2="12" stroke="currentColor" stroke-width="1.5"/><circle cx="8" cy="4.5" r="0.8" fill="currentColor"/></svg>',
592
- similar: '<svg viewBox="0 0 16 16" class="gengage-chat-icon"><rect x="1" y="3" width="6" height="6" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/><rect x="9" y="3" width="6" height="6" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/></svg>'
593
- }, zt = ce;
594
- class Dt {
595
- constructor(e, t) {
596
- this._panelVisible = !1, this._panelCollapsed = !1, this._onPanelToggle = void 0, this._pendingAttachment = null, this._onAttachment = void 0, this._onRollback = void 0, this._onLinkClick = void 0, this._userScrolledUp = !1, this._scrollLockedUntil = 0, this._thinkingSteps = [], this._firstBotMessageIds = /* @__PURE__ */ new Set(), this._voiceInput = null, this._micBtn = null, this._voiceEnabled = !1, this._voiceLang = "tr-TR", this._ignoreNextDividerClick = !1, this.i18n = { ...zt, ...t.i18n }, this.onSend = t.onSend, t.onPanelToggle !== void 0 && (this._onPanelToggle = t.onPanelToggle), t.onAttachment !== void 0 && (this._onAttachment = t.onAttachment), t.onRollback !== void 0 && (this._onRollback = t.onRollback), t.onLinkClick !== void 0 && (this._onLinkClick = t.onLinkClick), t.voiceEnabled && (this._voiceEnabled = !0), t.voiceLang !== void 0 && (this._voiceLang = t.voiceLang), this.root = document.createElement("div"), this.root.className = "gengage-chat-drawer", this.root.setAttribute("role", "dialog"), this.root.setAttribute("aria-label", this.i18n.headerTitle ?? "Chat"), this.root.setAttribute("aria-modal", "true");
597
- const a = document.createElement("div");
598
- a.className = "gengage-chat-header";
599
- const n = document.createElement("div");
600
- if (n.className = "gengage-chat-header-left", t.headerAvatarUrl) {
601
- const b = document.createElement("img");
602
- b.className = "gengage-chat-header-avatar", b.src = t.headerAvatarUrl, b.alt = t.headerTitle ?? "Assistant", n.appendChild(b);
603
- }
604
- const i = document.createElement("div");
605
- i.className = "gengage-chat-header-info";
606
- const s = document.createElement("div");
607
- s.className = "gengage-chat-header-title-row";
608
- const l = document.createElement("span");
609
- if (l.className = "gengage-chat-header-title", l.textContent = t.headerTitle ?? this.i18n.headerTitle ?? "Gengage Asistanı", s.appendChild(l), t.headerBadge) {
610
- const b = document.createElement("span");
611
- b.className = "gengage-chat-header-badge", b.textContent = t.headerBadge, s.appendChild(b);
612
- }
613
- i.appendChild(s);
614
- const r = document.createElement("a");
615
- r.className = "gengage-chat-header-powered", r.href = "https://gengage.ai/", r.target = "_blank", r.rel = "noopener noreferrer", r.innerHTML = '<svg viewBox="0 0 16 16" fill="currentColor"><path d="M8 1a7 7 0 110 14A7 7 0 018 1zm0 1.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM7 4.5h2v4H7v-4zm0 5h2v2H7v-2z"/></svg>Powered by Gengage', i.appendChild(r), n.appendChild(i), a.appendChild(n);
616
- const c = document.createElement("div");
617
- if (c.className = "gengage-chat-header-right", t.headerCartUrl) {
618
- const b = document.createElement("a");
619
- b.className = "gengage-chat-header-btn", b.href = t.headerCartUrl, b.target = "_blank", b.rel = "noopener noreferrer", b.setAttribute("aria-label", "Sepetim"), b.innerHTML = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/></svg>', c.appendChild(b);
620
- }
621
- if (t.headerFavoritesToggle) {
622
- const b = document.createElement("button");
623
- b.className = "gengage-chat-header-btn", b.type = "button", b.setAttribute("aria-label", "Favorilerim"), b.innerHTML = '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>', b.addEventListener("click", () => t.onFavoritesClick?.()), c.appendChild(b);
624
- }
625
- const g = document.createElement("button");
626
- g.className = "gengage-chat-close", g.type = "button", g.setAttribute("aria-label", this.i18n.closeButton), g.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>', g.addEventListener("click", t.onClose), c.appendChild(g), a.appendChild(c);
627
- const h = document.createElement("div");
628
- h.className = "gengage-chat-body", this._panelEl = document.createElement("div"), this._panelEl.className = "gengage-chat-panel", this._panelTopBar = new Mt({
629
- onBack: () => t.onPanelBack?.(),
630
- onForward: () => t.onPanelForward?.()
631
- }), this._panelEl.appendChild(this._panelTopBar.getElement()), h.appendChild(this._panelEl), this._dividerEl = document.createElement("div"), this._dividerEl.className = "gengage-chat-panel-divider gengage-chat-panel-divider--hidden", this._dividerEl.setAttribute("role", "separator"), this._dividerEl.setAttribute("aria-label", "Toggle panel");
632
- const p = document.createElement("button");
633
- p.className = "gengage-chat-panel-divider-toggle", p.type = "button", p.setAttribute("aria-label", "Toggle panel"), p.textContent = "»", p.addEventListener("click", () => {
634
- if (this._ignoreNextDividerClick) {
635
- this._ignoreNextDividerClick = !1;
636
- return;
637
- }
638
- this.togglePanel(), this._onPanelToggle?.();
639
- });
640
- let d = null, f = null;
641
- const k = 24;
642
- this._dividerEl.addEventListener(
643
- "touchstart",
644
- (b) => {
645
- if (window.innerWidth > 768) return;
646
- const A = b.changedTouches?.[0];
647
- A && (d = A.clientX, f = A.clientY);
648
- },
649
- { passive: !0 }
650
- ), this._dividerEl.addEventListener(
651
- "touchend",
652
- (b) => {
653
- if (window.innerWidth > 768 || d === null || f === null) return;
654
- const A = b.changedTouches?.[0];
655
- if (!A) return;
656
- const C = A.clientX - d, L = A.clientY - f;
657
- if (d = null, f = null, Math.abs(L) < k || Math.abs(L) < Math.abs(C)) return;
658
- const B = L < 0;
659
- B !== this._panelCollapsed && (this._ignoreNextDividerClick = !0, this.setPanelCollapsed(B), this._onPanelToggle?.());
660
- },
661
- { passive: !0 }
662
- ), this._dividerEl.appendChild(p), h.appendChild(this._dividerEl);
663
- const _ = document.createElement("div");
664
- _.className = "gengage-chat-conversation", _.appendChild(a), this._kvkkSlot = document.createElement("div"), this._kvkkSlot.className = "gengage-chat-kvkk-slot", _.appendChild(this._kvkkSlot), this.messagesEl = document.createElement("div"), this.messagesEl.className = "gengage-chat-messages", this.messagesEl.setAttribute("role", "log"), this.messagesEl.setAttribute("aria-live", "polite"), this.messagesEl.setAttribute("aria-label", "Chat messages");
665
- let P = !1;
666
- this.messagesEl.addEventListener(
667
- "scroll",
668
- () => {
669
- P || (P = !0, requestAnimationFrame(() => {
670
- P = !1;
671
- const { scrollTop: b, scrollHeight: A, clientHeight: C } = this.messagesEl;
672
- this._userScrolledUp = A - b - C > 10;
673
- }));
674
- },
675
- { passive: !0 }
676
- ), _.appendChild(this.messagesEl), this._thumbnailsColumn = new Bt({
677
- onThumbnailClick: (b) => t.onThumbnailClick?.(b)
678
- }), this._panelEl.appendChild(this._thumbnailsColumn.getElement()), this._pillsEl = document.createElement("div"), this._pillsEl.className = "gengage-chat-pills", this._pillsEl.setAttribute("role", "toolbar"), this._pillsEl.setAttribute("aria-label", "Suggestions"), this._pillsEl.style.display = "none";
679
- const S = document.createElement("div");
680
- S.className = "gengage-chat-pills-scroll", this._pillsEl.appendChild(S);
681
- const T = document.createElement("button");
682
- T.className = "gengage-chat-pills-arrow", T.type = "button", T.setAttribute("aria-label", "More suggestions"), T.textContent = "›", T.addEventListener("click", () => {
683
- S.scrollBy({ left: 150, behavior: "smooth" });
684
- }), this._pillsEl.appendChild(T);
685
- let w = !1;
686
- S.addEventListener(
687
- "scroll",
688
- () => {
689
- w || (w = !0, requestAnimationFrame(() => {
690
- w = !1;
691
- const b = S.scrollLeft + S.clientWidth >= S.scrollWidth - 4;
692
- T.style.display = b ? "none" : "";
693
- }));
694
- },
695
- { passive: !0 }
696
- ), _.appendChild(this._pillsEl), this._inputChipsEl = document.createElement("div"), this._inputChipsEl.className = "gengage-chat-input-chips", this._inputChipsEl.style.display = "none", _.appendChild(this._inputChipsEl);
697
- const u = document.createElement("div");
698
- u.className = "gengage-chat-input-area", this.inputEl = document.createElement("textarea"), this.inputEl.className = "gengage-chat-input", this.inputEl.rows = 1, this.inputEl.placeholder = this.i18n.inputPlaceholder, this.inputEl.addEventListener("input", () => {
699
- requestAnimationFrame(() => {
700
- this.inputEl.style.height = "auto", this.inputEl.style.height = `${Math.min(this.inputEl.scrollHeight, 120)}px`;
701
- });
702
- }), this.inputEl.addEventListener("keydown", (b) => {
703
- b.key === "Enter" && (window.innerWidth < 768 || !b.shiftKey) && (b.preventDefault(), this._submit());
704
- }), this.inputEl.addEventListener("paste", (b) => {
705
- const A = b.clipboardData?.files[0];
706
- A && A.type.startsWith("image/") && (b.preventDefault(), this._onAttachment ? this._onAttachment(A) : this.stageAttachment(A));
707
- }), this._fileInput = document.createElement("input"), this._fileInput.type = "file", this._fileInput.accept = "image/jpeg,image/png,image/webp", this._fileInput.style.display = "none", this._fileInput.addEventListener("change", () => {
708
- const b = this._fileInput.files?.[0];
709
- b && (this._onAttachment ? this._onAttachment(b) : this.stageAttachment(b)), this._fileInput.value = "";
710
- });
711
- const E = document.createElement("button");
712
- E.className = "gengage-chat-attach-btn", E.type = "button", E.setAttribute("aria-label", this.i18n.attachImageButton), E.innerHTML = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>', E.addEventListener("click", () => this._fileInput.click()), this._previewStrip = document.createElement("div"), this._previewStrip.className = "gengage-chat-attachment-preview gengage-chat-attachment-preview--hidden";
713
- const I = document.createElement("img");
714
- I.className = "gengage-chat-attachment-preview-thumb", I.alt = "", this._previewName = document.createElement("span"), this._previewName.className = "gengage-chat-attachment-name";
715
- const m = document.createElement("button");
716
- m.className = "gengage-chat-attachment-remove", m.type = "button", m.setAttribute("aria-label", this.i18n.removeAttachmentButton), m.textContent = "×", m.addEventListener("click", () => this.clearAttachment()), this._previewStrip.appendChild(I), this._previewStrip.appendChild(this._previewName), this._previewStrip.appendChild(m), this.sendBtn = document.createElement("button"), this.sendBtn.className = "gengage-chat-send", this.sendBtn.type = "button", this.sendBtn.setAttribute("aria-label", this.i18n.sendButton), this.sendBtn.innerHTML = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>', this.sendBtn.addEventListener("click", () => this._submit()), u.addEventListener("dragover", (b) => {
717
- b.preventDefault(), u.classList.add("gengage-chat-input-area--dragover");
718
- }), u.addEventListener("dragleave", () => {
719
- u.classList.remove("gengage-chat-input-area--dragover");
720
- }), u.addEventListener("drop", (b) => {
721
- b.preventDefault(), u.classList.remove("gengage-chat-input-area--dragover");
722
- const A = b.dataTransfer?.files[0];
723
- A && (this._onAttachment ? this._onAttachment(A) : this.stageAttachment(A));
724
- });
725
- const x = document.createElement("div");
726
- x.className = "gengage-chat-input-pill", x.appendChild(E), x.appendChild(this.inputEl), this._voiceEnabled && Lt() && (this._micBtn = document.createElement("button"), this._micBtn.className = "gengage-chat-mic-btn", this._micBtn.type = "button", this._micBtn.setAttribute("aria-label", this.i18n.voiceButton), this._micBtn.innerHTML = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>', this._micBtn.addEventListener("click", () => this._toggleVoice()), x.appendChild(this._micBtn), this._voiceInput = new Nt(
727
- {
728
- onInterim: (b) => {
729
- this.inputEl.value = b, this.inputEl.style.height = "auto", this.inputEl.style.height = `${Math.min(this.inputEl.scrollHeight, 120)}px`;
730
- },
731
- onFinal: (b) => {
732
- this.inputEl.value = b;
733
- },
734
- onAutoSubmit: (b) => {
735
- this.inputEl.value = b, this._micBtn?.classList.remove("gengage-chat-mic-btn--active"), this._submit();
736
- },
737
- onStateChange: (b) => {
738
- b === "listening" ? this._micBtn?.classList.add("gengage-chat-mic-btn--active") : this._micBtn?.classList.remove("gengage-chat-mic-btn--active");
739
- },
740
- onError: (b, A) => {
741
- this._micBtn?.classList.remove("gengage-chat-mic-btn--active");
742
- }
743
- },
744
- { lang: this._voiceLang }
745
- )), x.appendChild(this.sendBtn), u.appendChild(this._previewStrip), u.appendChild(this._fileInput), u.appendChild(x), _.appendChild(u), h.appendChild(_), this.root.appendChild(h);
746
- const y = document.createElement("div");
747
- y.className = "gengage-chat-footer", y.textContent = this.i18n.poweredBy, this.root.appendChild(y), this.root.addEventListener("keydown", (b) => {
748
- b.key === "Escape" && t.onClose();
749
- }), this._trapFocus(), e.appendChild(this.root);
750
- }
751
- addMessage(e) {
752
- const t = document.createElement("div");
753
- if (t.className = `gengage-chat-bubble gengage-chat-bubble--${e.role}`, t.dataset.messageId = e.id, e.threadId && (t.dataset.threadId = e.threadId), this._firstBotMessageIds.has(e.id) && t.classList.add("gengage-chat-bubble--first"), e.attachment) {
754
- const a = document.createElement("img");
755
- a.className = "gengage-chat-attachment-thumb";
756
- const n = URL.createObjectURL(e.attachment);
757
- a.src = n, a.alt = e.attachment.name, a.addEventListener("load", () => URL.revokeObjectURL(n), { once: !0 }), a.addEventListener("error", () => URL.revokeObjectURL(n), { once: !0 }), t.insertBefore(a, t.firstChild);
758
- }
759
- if (e.content) {
760
- const a = document.createElement("div");
761
- if (a.className = "gengage-chat-bubble-text", e.role === "assistant") {
762
- if (a.innerHTML = $(e.content), this._onLinkClick) {
763
- const n = a.querySelectorAll("a[href]");
764
- for (const i of n)
765
- i.addEventListener("click", (s) => {
766
- s.preventDefault();
767
- const l = i.getAttribute("href");
768
- l && this._onLinkClick?.(l);
769
- });
770
- }
771
- } else
772
- a.textContent = e.content;
773
- t.appendChild(a);
774
- }
775
- if (e.role === "user" && this._onRollback) {
776
- const a = document.createElement("button");
777
- a.className = "gengage-chat-rollback-btn", a.type = "button", a.setAttribute("aria-label", "Rollback to this message"), a.innerHTML = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg>', a.addEventListener("click", (n) => {
778
- n.stopPropagation(), this._onRollback?.(e.id);
779
- }), t.appendChild(a);
780
- }
781
- this.messagesEl.appendChild(t), this._scrollToBottom(e.role === "user");
782
- }
783
- showTypingIndicator(e) {
784
- this.removeTypingIndicator();
785
- const t = document.createElement("div");
786
- if (t.className = "gengage-chat-typing", t.dataset.typing = "true", this._thinkingSteps.length > 0)
787
- this._renderThinkingStepsInto(t);
788
- else {
789
- const a = document.createElement("div");
790
- a.className = "gengage-chat-typing-dots";
791
- for (let n = 0; n < 3; n++) a.appendChild(document.createElement("span"));
792
- if (t.appendChild(a), e) {
793
- const n = document.createElement("span");
794
- n.className = "gengage-chat-typing-sparkle", n.textContent = "✨", t.appendChild(n);
795
- const i = document.createElement("span");
796
- i.className = "gengage-chat-typing-text", i.textContent = e, t.appendChild(i);
797
- }
798
- }
799
- this.messagesEl.appendChild(t), this._scrollToBottom(!0);
800
- }
801
- /** Accumulate a new thinking step (shown as a checklist in the typing indicator). */
802
- addThinkingStep(e) {
803
- this._thinkingSteps.push(e), this._renderThinkingSteps();
804
- }
805
- removeTypingIndicator() {
806
- this.messagesEl.querySelector(".gengage-chat-typing")?.remove(), this._thinkingSteps = [];
807
- }
808
- showError(e, t) {
809
- const a = document.createElement("div");
810
- a.className = "gengage-chat-error";
811
- const n = document.createElement("span");
812
- if (n.textContent = e ?? this.i18n.errorMessage, a.appendChild(n), t) {
813
- const i = document.createElement("button");
814
- i.className = "gengage-chat-error-retry", i.textContent = this.i18n.retryButton ?? "Retry", i.addEventListener("click", () => {
815
- a.remove(), t();
816
- }), a.appendChild(i);
817
- }
818
- this.messagesEl.appendChild(a), this._scrollToBottom(!0);
819
- }
820
- clearMessages() {
821
- this.messagesEl.innerHTML = "";
822
- }
823
- /** Replace suggestion pills. Pass empty array to hide. */
824
- setPills(e) {
825
- const t = this._pillsEl.querySelector(".gengage-chat-pills-scroll");
826
- if (!t) return;
827
- for (; t.firstChild; ) t.removeChild(t.firstChild);
828
- if (e.length === 0) {
829
- this._pillsEl.style.display = "none";
830
- return;
831
- }
832
- this._pillsEl.style.display = "";
833
- for (const n of e) {
834
- const i = document.createElement("button");
835
- if (i.className = n.image ? "gengage-chat-pill gengage-chat-pill--rich" : "gengage-chat-pill", i.type = "button", n.icon) {
836
- const l = pe[n.icon];
837
- if (l) {
838
- const r = document.createElement("span");
839
- r.className = "gengage-chat-pill-icon", r.innerHTML = l, i.appendChild(r);
840
- }
841
- }
842
- if (n.image && W(n.image)) {
843
- const l = document.createElement("img");
844
- l.className = "gengage-chat-pill-img", l.src = n.image, l.alt = "", i.appendChild(l);
845
- }
846
- const s = document.createElement("span");
847
- if (s.className = "gengage-chat-pill-text", s.textContent = n.label, i.appendChild(s), n.description) {
848
- const l = document.createElement("span");
849
- l.className = "gengage-chat-pill-desc", l.textContent = n.description, i.appendChild(l);
850
- }
851
- i.addEventListener("click", () => n.onAction()), t.appendChild(i);
852
- }
853
- const a = this._pillsEl.querySelector(".gengage-chat-pills-arrow");
854
- a && requestAnimationFrame(() => {
855
- a.style.display = t.scrollWidth > t.clientWidth ? "" : "none";
856
- });
857
- }
858
- focusInput() {
859
- this.inputEl.focus();
860
- }
861
- showKvkkBanner(e, t) {
862
- this._kvkkSlot.innerHTML = "";
863
- const a = At({ htmlContent: e, onDismiss: t });
864
- this._kvkkSlot.appendChild(a);
865
- }
866
- hideKvkkBanner() {
867
- this._kvkkSlot.innerHTML = "";
868
- }
869
- getElement() {
870
- return this.root;
871
- }
872
- /** Stage a file attachment for sending. Shows preview. */
873
- stageAttachment(e) {
874
- this._pendingAttachment = e, this._previewName.textContent = e.name;
875
- const t = this._previewStrip.querySelector(".gengage-chat-attachment-preview-thumb");
876
- t && (t.src && t.src.startsWith("blob:") && URL.revokeObjectURL(t.src), t.src = URL.createObjectURL(e)), this._previewStrip.classList.remove("gengage-chat-attachment-preview--hidden");
877
- }
878
- /** Remove the staged attachment and hide preview. */
879
- clearAttachment() {
880
- const e = this._previewStrip.querySelector(".gengage-chat-attachment-preview-thumb");
881
- e?.src && (URL.revokeObjectURL(e.src), e.src = ""), this._pendingAttachment = null, this._previewStrip.classList.add("gengage-chat-attachment-preview--hidden");
882
- }
883
- /** Get the currently staged attachment file, or null. */
884
- getPendingAttachment() {
885
- return this._pendingAttachment;
886
- }
887
- /** Replace panel content and show the panel. */
888
- setPanelContent(e) {
889
- this._panelEl.innerHTML = "", this._panelEl.appendChild(this._panelTopBar.getElement()), this._panelEl.appendChild(e), this._dividerEl.classList.remove("gengage-chat-panel-divider--hidden"), this._panelVisible || (this._panelVisible = !0, this._panelEl.classList.add("gengage-chat-panel--visible"), this.root.classList.add("gengage-chat-drawer--with-panel")), this._panelCollapsed && this._panelEl.classList.add("gengage-chat-panel--collapsed");
890
- }
891
- /** Append content to the panel without replacing existing content. */
892
- appendPanelContent(e) {
893
- this._panelEl.appendChild(e), this._dividerEl.classList.remove("gengage-chat-panel-divider--hidden"), this._panelVisible || (this._panelVisible = !0, this._panelEl.classList.add("gengage-chat-panel--visible"), this.root.classList.add("gengage-chat-drawer--with-panel"));
894
- }
895
- /** Return the panel element's content child (after topbar), or null. */
896
- getPanelContentElement() {
897
- const e = this._panelEl.children;
898
- for (let t = 0; t < e.length; t++) {
899
- const a = e[t];
900
- if (!(a.classList.contains("gengage-chat-panel-topbar") || a.classList.contains("gengage-chat-thumbnails-column")))
901
- return a;
902
- }
903
- return null;
904
- }
905
- /** Whether the panel is currently visible and has rendered content (beyond topbar + thumbnails column). */
906
- hasPanelContent() {
907
- return this._panelVisible && this.getPanelContentElement() !== null;
908
- }
909
- /** Whether panel currently shows loading skeleton blocks. */
910
- isPanelLoading() {
911
- return this._panelEl.querySelector(".gengage-chat-panel-skeleton") !== null;
912
- }
913
- /** Show loading skeleton in the panel. Variant depends on contentType hint. */
914
- showPanelLoading(e) {
915
- this._dividerEl.classList.remove("gengage-chat-panel-divider--hidden"), this._panelEl.innerHTML = "", this._panelEl.appendChild(this._panelTopBar.getElement());
916
- const t = document.createElement("div");
917
- switch (t.className = "gengage-chat-panel-skeleton", e) {
918
- case "productDetails": {
919
- const a = document.createElement("div");
920
- a.className = "gengage-chat-panel-skeleton-block gengage-chat-panel-skeleton-block--image", t.appendChild(a);
921
- for (let n = 0; n < 3; n++) {
922
- const i = document.createElement("div");
923
- i.className = "gengage-chat-panel-skeleton-block gengage-chat-panel-skeleton-block--text", t.appendChild(i);
924
- }
925
- break;
926
- }
927
- case "productList":
928
- case "groupList": {
929
- const a = document.createElement("div");
930
- a.className = "gengage-chat-panel-skeleton-grid";
931
- for (let n = 0; n < 6; n++) {
932
- const i = document.createElement("div");
933
- i.className = "gengage-chat-panel-skeleton-block gengage-chat-panel-skeleton-block--card", a.appendChild(i);
934
- }
935
- t.appendChild(a);
936
- break;
937
- }
938
- case "comparisonTable": {
939
- for (let a = 0; a < 4; a++) {
940
- const n = document.createElement("div");
941
- n.className = "gengage-chat-panel-skeleton-block gengage-chat-panel-skeleton-block--row", t.appendChild(n);
942
- }
943
- break;
944
- }
945
- default: {
946
- for (let a = 0; a < 3; a++) {
947
- const n = document.createElement("div");
948
- n.className = "gengage-chat-panel-skeleton-block", t.appendChild(n);
949
- }
950
- break;
951
- }
952
- }
953
- this._panelEl.appendChild(t), this._panelVisible || (this._panelVisible = !0, this._panelEl.classList.add("gengage-chat-panel--visible"), this.root.classList.add("gengage-chat-drawer--with-panel"));
954
- }
955
- /** Update the panel top bar navigation state. */
956
- updatePanelTopBar(e, t, a) {
957
- this._panelTopBar.update(e, t, a);
958
- }
959
- /**
960
- * Hide the panel and clear its content. Always hides — even in force-expanded mode.
961
- * Callers: _hideDrawer (stale panel cleanup), stream onDone (loading skeleton cleanup),
962
- * thread navigation (no snapshot to restore). All require full hide.
963
- * Keeps `_panelCollapsed` untouched so user collapse preference survives future panel renders.
964
- */
965
- clearPanel() {
966
- this._panelEl.innerHTML = "", this._panelEl.appendChild(this._panelTopBar.getElement()), this._panelVisible = !1, this._panelEl.classList.remove("gengage-chat-panel--visible", "gengage-chat-panel--collapsed"), this.root.classList.remove("gengage-chat-drawer--with-panel"), this._dividerEl.classList.add("gengage-chat-panel-divider--hidden");
967
- }
968
- /** Expand panel without locking — user can still toggle via divider. */
969
- expandPanel() {
970
- this._panelCollapsed = !1, this._panelEl.classList.remove("gengage-chat-panel--collapsed"), this._panelVisible || (this._panelVisible = !0, this._panelEl.classList.add("gengage-chat-panel--visible"), this.root.classList.add("gengage-chat-drawer--with-panel"));
971
- }
972
- /**
973
- * Ensure the panel starts expanded (panelMode: 'expanded').
974
- * Users can still collapse/expand via the divider chevron.
975
- */
976
- setForceExpanded() {
977
- this._panelCollapsed = !1, this._panelEl.classList.remove("gengage-chat-panel--collapsed"), this._panelVisible || (this._panelVisible = !0, this._panelEl.classList.add("gengage-chat-panel--visible"), this.root.classList.add("gengage-chat-drawer--with-panel")), this._dividerEl.classList.remove("gengage-chat-panel-divider--hidden");
978
- }
979
- /** Toggle panel between collapsed and expanded. */
980
- togglePanel() {
981
- this.setPanelCollapsed(!this._panelCollapsed);
982
- }
983
- /** Whether the panel is currently collapsed by the user. */
984
- isPanelCollapsed() {
985
- return this._panelCollapsed;
986
- }
987
- /** Programmatically set panel collapsed state. */
988
- setPanelCollapsed(e) {
989
- this._panelCollapsed = e, e ? this._panelEl.classList.add("gengage-chat-panel--collapsed") : this._panelEl.classList.remove("gengage-chat-panel--collapsed");
990
- const t = this._dividerEl.querySelector(".gengage-chat-panel-divider-toggle");
991
- t && (t.textContent = e ? "«" : "»");
992
- }
993
- /** Save panel collapsed state to sessionStorage. */
994
- persistPanelState(e) {
995
- try {
996
- const t = `gengage:panel:${e}`;
997
- this._panelCollapsed ? sessionStorage.setItem(t, "collapsed") : sessionStorage.removeItem(t);
998
- } catch {
999
- }
1000
- }
1001
- /** Restore panel collapsed state from sessionStorage. Returns true when restored as collapsed. */
1002
- restorePanelState(e) {
1003
- try {
1004
- const t = `gengage:panel:${e}`;
1005
- if (sessionStorage.getItem(t) === "collapsed")
1006
- return this._panelCollapsed = !0, !0;
1007
- } catch {
1008
- }
1009
- return !1;
1010
- }
1011
- /** Re-render thinking steps inside the existing typing indicator container. */
1012
- _renderThinkingSteps() {
1013
- const e = this.messagesEl.querySelector('[data-typing="true"]');
1014
- if (!e) {
1015
- this.showTypingIndicator();
1016
- return;
1017
- }
1018
- e.innerHTML = "", this._renderThinkingStepsInto(e), this._scrollToBottom(!1);
1019
- }
1020
- /** Render the accumulated thinking-step checklist into a container element. */
1021
- _renderThinkingStepsInto(e) {
1022
- const t = document.createElement("div");
1023
- t.className = "gengage-chat-thinking-steps";
1024
- for (let a = 0; a < this._thinkingSteps.length; a++) {
1025
- const n = document.createElement("div");
1026
- n.className = "gengage-chat-thinking-step";
1027
- const i = document.createElement("span");
1028
- i.className = "gengage-chat-thinking-step-marker", a < this._thinkingSteps.length - 1 ? (i.textContent = "✓", i.classList.add("gengage-chat-thinking-step-marker--done")) : (i.textContent = "●", i.classList.add("gengage-chat-thinking-step-marker--active")), n.appendChild(i);
1029
- const s = document.createElement("span");
1030
- s.className = "gengage-chat-thinking-step-text", s.textContent = this._thinkingSteps[a], n.appendChild(s), t.appendChild(n);
1031
- }
1032
- e.appendChild(t);
1033
- }
1034
- _trapFocus() {
1035
- this.root.addEventListener("keydown", (e) => {
1036
- if (e.key !== "Tab") return;
1037
- const t = this.root.querySelectorAll(
1038
- 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
1039
- );
1040
- if (t.length === 0) return;
1041
- const a = t[0], n = t[t.length - 1];
1042
- if (!a || !n) return;
1043
- const s = this.root.getRootNode().activeElement ?? document.activeElement;
1044
- e.shiftKey ? s === a && (e.preventDefault(), n.focus()) : s === n && (e.preventDefault(), a.focus());
1045
- });
1046
- }
1047
- _submit() {
1048
- const e = this.inputEl.value.trim(), t = this._pendingAttachment;
1049
- !e && !t || (this.onSend(e, t ?? void 0), this.inputEl.value = "", this.inputEl.style.height = "auto", this.clearAttachment());
1050
- }
1051
- _toggleVoice() {
1052
- if (this._voiceInput)
1053
- if (this._voiceInput.state === "listening") {
1054
- const e = this._voiceInput.stop();
1055
- e.trim() && (this.inputEl.value = e, this._submit());
1056
- } else
1057
- this.inputEl.value = "", this._voiceInput.start();
1058
- }
1059
- /** Lock auto-scroll for 500ms after session history restore to prevent visual jump. */
1060
- lockScrollForRestore() {
1061
- this._scrollLockedUntil = Date.now() + 500;
1062
- }
1063
- /** Scroll to bottom only if user hasn't scrolled up. Force=true always scrolls. */
1064
- _scrollToBottom(e = !1) {
1065
- !e && this._userScrolledUp || !e && Date.now() < this._scrollLockedUntil || requestAnimationFrame(() => {
1066
- this.messagesEl.scrollTop = this.messagesEl.scrollHeight, this._userScrolledUp = !1;
1067
- });
1068
- }
1069
- /** Public method for typewriter ticks — scrolls only if user is near bottom. */
1070
- scrollToBottomIfNeeded() {
1071
- this._scrollToBottom(!1);
1072
- }
1073
- /** Update a bot message's text content in the DOM (e.g. for fallback messages). */
1074
- updateBotMessage(e, t) {
1075
- const a = this.messagesEl.querySelector(`[data-message-id="${CSS.escape(e)}"]`);
1076
- if (!a) return;
1077
- let n = a.querySelector(".gengage-chat-bubble-text");
1078
- n || (n = document.createElement("div"), n.className = "gengage-chat-bubble-text", a.appendChild(n)), n.innerHTML = $(t), this._scrollToBottom(!1);
1079
- }
1080
- /** Mark a message as the first bot message in its thread (for special styling). */
1081
- markFirstBotMessage(e) {
1082
- this._firstBotMessageIds.add(e);
1083
- const t = this.messagesEl.querySelector(`[data-message-id="${CSS.escape(e)}"]`);
1084
- t && t.classList.add("gengage-chat-bubble--first");
1085
- }
1086
- /** Scroll to the first message of the last thread (for restore targeting). */
1087
- scrollToLastThread() {
1088
- const e = this.messagesEl.querySelectorAll("[data-thread-id]");
1089
- if (e.length === 0) {
1090
- this._scrollToBottom(!0);
1091
- return;
1092
- }
1093
- const t = e[e.length - 1].getAttribute("data-thread-id");
1094
- if (!t) {
1095
- this._scrollToBottom(!0);
1096
- return;
1097
- }
1098
- const a = this.messagesEl.querySelector(`[data-thread-id="${CSS.escape(t)}"]`);
1099
- a ? requestAnimationFrame(() => {
1100
- a.scrollIntoView({ block: "start", behavior: "auto" }), this._userScrolledUp = !1;
1101
- }) : this._scrollToBottom(!0);
1102
- }
1103
- /** Set compact input-area chips (search/info/review shortcuts above input). */
1104
- setInputAreaChips(e) {
1105
- if (this._inputChipsEl.innerHTML = "", e.length === 0) {
1106
- this._inputChipsEl.style.display = "none";
1107
- return;
1108
- }
1109
- this._inputChipsEl.style.display = "";
1110
- for (const t of e) {
1111
- const a = document.createElement("button");
1112
- if (a.className = "gengage-chat-input-chip", a.type = "button", t.icon) {
1113
- const i = pe[t.icon];
1114
- if (i) {
1115
- const s = document.createElement("span");
1116
- s.className = "gengage-chat-input-chip-icon", s.innerHTML = i, a.appendChild(s);
1117
- }
1118
- }
1119
- const n = document.createElement("span");
1120
- n.textContent = t.label, a.appendChild(n), a.addEventListener("click", () => t.onAction()), this._inputChipsEl.appendChild(a);
1121
- }
1122
- }
1123
- /** Clear input-area chips. */
1124
- clearInputAreaChips() {
1125
- this._inputChipsEl.innerHTML = "", this._inputChipsEl.style.display = "none";
1126
- }
1127
- setThumbnails(e) {
1128
- this._thumbnailsColumn.setEntries(e), e.length > 0 ? this._thumbnailsColumn.show() : this._thumbnailsColumn.hide();
1129
- }
1130
- hideThumbnails() {
1131
- this._thumbnailsColumn.hide();
1132
- }
1133
- }
1134
- const Rt = `<svg width="28" height="28" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
1135
- <rect x="3" y="7" width="18" height="13" rx="3" fill="currentColor" opacity="0.15"/>
1136
- <rect x="3" y="7" width="18" height="13" rx="3" stroke="currentColor" stroke-width="1.5"/>
1137
- <circle cx="9" cy="13" r="1.5" fill="currentColor"/>
1138
- <circle cx="15" cy="13" r="1.5" fill="currentColor"/>
1139
- <path d="M9.5 17C10.3 17.6 11.1 18 12 18C12.9 18 13.7 17.6 14.5 17" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
1140
- <path d="M12 7V4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
1141
- <circle cx="12" cy="3" r="1" fill="currentColor"/>
1142
- <path d="M1 12V14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
1143
- <path d="M23 12V14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
1144
- </svg>`;
1145
- function Ut(o) {
1146
- const e = document.createElement("div");
1147
- e.className = "gengage-chat-launcher-container";
1148
- const t = document.createElement("div");
1149
- t.className = "gengage-chat-launcher-content-area", e.appendChild(t);
1150
- const a = document.createElement("button");
1151
- if (a.className = "gengage-chat-launcher", a.type = "button", a.setAttribute("aria-label", o.ariaLabel ?? "Open chat"), a.innerHTML = o.svgMarkup ?? Rt, o.tooltip !== void 0) {
1152
- const i = document.createElement("span");
1153
- i.className = "gengage-chat-launcher-tooltip", i.textContent = o.tooltip, a.appendChild(i);
1154
- }
1155
- o.hideMobile && (e.dataset.hideMobile = "1"), o.mobileBreakpoint !== void 0 && (e.dataset.mobileBreakpoint = String(o.mobileBreakpoint)), a.addEventListener("click", o.onClick), e.appendChild(a);
1156
- const n = document.createElement("div");
1157
- return n.className = "gengage-chat-launcher-content-area-bottom", e.appendChild(n), { container: e, button: a, contentArea: t, contentAreaBottom: n };
1158
- }
1159
- function qt(o) {
1160
- const e = document.createElement("div");
1161
- e.className = "gengage-chat-proactive";
1162
- const t = document.createElement("p");
1163
- t.className = "gengage-chat-proactive-message", t.textContent = o.message, e.appendChild(t);
1164
- const a = document.createElement("div");
1165
- a.className = "gengage-chat-proactive-actions";
1166
- let n = null;
1167
- function i() {
1168
- n !== null && clearTimeout(n), e.remove();
1169
- }
1170
- if (o.actionButtons && o.actionButtons.length > 0)
1171
- for (const r of o.actionButtons) {
1172
- const c = document.createElement("button");
1173
- c.className = "gengage-chat-proactive-accept", c.type = "button", c.textContent = r.title, c.addEventListener("click", () => {
1174
- i(), r.onSelect();
1175
- }), a.appendChild(c);
1176
- }
1177
- else {
1178
- const r = document.createElement("button");
1179
- r.className = "gengage-chat-proactive-accept", r.type = "button", r.textContent = o.acceptLabel ?? "Sohbete Başla", r.addEventListener("click", () => {
1180
- i(), o.onAccept();
1181
- }), a.appendChild(r);
1182
- }
1183
- const s = document.createElement("button");
1184
- s.className = "gengage-chat-proactive-dismiss", s.type = "button", s.textContent = "×", s.setAttribute("aria-label", o.closeAriaLabel ?? "Kapat"), s.addEventListener("click", () => {
1185
- i(), o.onDismiss();
1186
- }), e.appendChild(s), e.appendChild(a);
1187
- const l = o.autoDismissMs ?? 15e3;
1188
- return l > 0 && (n = setTimeout(() => {
1189
- e.parentElement && (e.remove(), o.onDismiss());
1190
- }, l)), requestAnimationFrame(() => e.classList.add("gengage-chat-proactive--visible")), e;
1191
- }
1192
- class Ht {
1193
- constructor(e = {}) {
1194
- this._idleTimer = null, this._maxScrollDepth = 0, this._lastReportedDepth = 0, this._listeners = [], this._destroyed = !1, this._idleThreshold = e.idleThresholdMs ?? 3e4, this._scrollGranularity = e.scrollGranularity ?? 25, this._onActivity = e.onActivity ?? null, this._setup();
1195
- }
1196
- _setup() {
1197
- this._emit({ type: "pageview", timestamp: Date.now() }), this._resetIdleTimer(), this._listen(window, "scroll", () => this._onScroll(), { passive: !0 }), this._listen(window, "mousemove", () => this._resetIdleTimer(), { passive: !0 }), this._listen(window, "keydown", () => this._resetIdleTimer(), { passive: !0 }), this._listen(window, "touchstart", () => this._resetIdleTimer(), { passive: !0 }), this._listen(document, "visibilitychange", () => this._onVisibility());
1198
- }
1199
- _listen(e, t, a, n) {
1200
- e.addEventListener(t, a, n), this._listeners.push([e, t, a]);
1201
- }
1202
- _resetIdleTimer() {
1203
- this._idleTimer && clearTimeout(this._idleTimer), this._idleTimer = setTimeout(() => {
1204
- this._emit({ type: "idle", timestamp: Date.now() });
1205
- }, this._idleThreshold);
1206
- }
1207
- _onScroll() {
1208
- const e = window.scrollY || document.documentElement.scrollTop, t = Math.max(document.documentElement.scrollHeight - window.innerHeight, 1), a = Math.min(100, Math.round(e / t * 100));
1209
- a > this._maxScrollDepth && (this._maxScrollDepth = a);
1210
- const n = Math.floor(a / this._scrollGranularity) * this._scrollGranularity;
1211
- n > this._lastReportedDepth && (this._lastReportedDepth = n, this._emit({
1212
- type: "scroll",
1213
- timestamp: Date.now(),
1214
- data: { depth: n }
1215
- })), this._resetIdleTimer();
1216
- }
1217
- _onVisibility() {
1218
- document.hidden ? (this._emit({ type: "blur", timestamp: Date.now() }), this._idleTimer && clearTimeout(this._idleTimer)) : (this._emit({ type: "focus", timestamp: Date.now() }), this._resetIdleTimer());
1219
- }
1220
- _emit(e) {
1221
- this._destroyed || this._onActivity?.(e);
1222
- }
1223
- /** Current max scroll depth reached (0-100). */
1224
- get maxScrollDepth() {
1225
- return this._maxScrollDepth;
1226
- }
1227
- destroy() {
1228
- this._destroyed = !0, this._idleTimer && clearTimeout(this._idleTimer);
1229
- for (const [e, t, a] of this._listeners)
1230
- e.removeEventListener(t, a);
1231
- this._listeners = [];
1232
- }
1233
- }
1234
- const Ft = /* @__PURE__ */ new Set([
1235
- "audio/ogg",
1236
- "audio/mpeg",
1237
- "audio/mp3",
1238
- "audio/wav",
1239
- "audio/webm",
1240
- "audio/aac",
1241
- "audio/mp4"
1242
- ]);
1243
- function Ot(o, e = "audio/ogg") {
1244
- const t = e.split(";")[0].trim();
1245
- if (!Ft.has(t)) return null;
1246
- try {
1247
- const a = new Audio(`data:${e};base64,${o}`);
1248
- return a.play().catch(() => {
1249
- }), {
1250
- stop: () => {
1251
- a.pause(), a.currentTime = 0;
1252
- }
1253
- };
1254
- } catch {
1255
- return null;
1256
- }
1257
- }
1258
- class jt {
1259
- constructor(e) {
1260
- this._timer = null, this._destroyed = !1, this._abortController = null, this._sessionStart = Date.now(), this._lastActivity = Date.now(), this._searchesCount = 0, this._actionsCount = 0, this._triggerFireCounts = {}, this._options = e;
1261
- const t = Re(e.middlewareUrl);
1262
- this._endpoint = `${t}/v2/heartbeat`;
1263
- }
1264
- start() {
1265
- this._timer || this._destroyed || this._scheduleNext();
1266
- }
1267
- /** Schedule the next poll after the current one finishes (prevents overlapping polls). */
1268
- _scheduleNext() {
1269
- this._destroyed || (this._timer = setTimeout(() => {
1270
- this._poll().finally(() => this._scheduleNext());
1271
- }, this._options.intervalMs));
1272
- }
1273
- stop() {
1274
- this._timer && (clearTimeout(this._timer), this._timer = null);
1275
- }
1276
- /** Call when the user performs an action (search, click, etc.). */
1277
- recordAction() {
1278
- this._actionsCount++, this._lastActivity = Date.now();
1279
- }
1280
- /** Call when the user performs a search. */
1281
- recordSearch() {
1282
- this._searchesCount++, this._lastActivity = Date.now();
1283
- }
1284
- /** Call on any user interaction to reset idle timer. */
1285
- recordActivity() {
1286
- this._lastActivity = Date.now();
1287
- }
1288
- destroy() {
1289
- this._destroyed = !0, this._abortController?.abort(), this._abortController = null, this.stop();
1290
- }
1291
- async _poll() {
1292
- if (this._destroyed) return;
1293
- const e = Date.now(), t = {
1294
- account_id: this._options.accountId,
1295
- thread_id: this._options.sessionId,
1296
- output_language: this._options.locale.toUpperCase(),
1297
- idle_seconds: (e - this._lastActivity) / 1e3,
1298
- page_type: this._options.getPageType(),
1299
- current_sku: this._options.getCurrentSku(),
1300
- cart_item_count: 0,
1301
- searches_count: this._searchesCount,
1302
- actions_count: this._actionsCount,
1303
- session_duration_seconds: (e - this._sessionStart) / 1e3,
1304
- trigger_fire_counts: { ...this._triggerFireCounts }
1305
- };
1306
- this._abortController = new AbortController();
1307
- try {
1308
- const a = await fetch(this._endpoint, {
1309
- method: "POST",
1310
- headers: { "Content-Type": "application/json" },
1311
- body: JSON.stringify(t),
1312
- signal: this._abortController.signal
1313
- });
1314
- if (this._destroyed || !a.ok) return;
1315
- const n = await a.json();
1316
- if (this._destroyed) return;
1317
- n.action === "message" && n.message && (n.trigger_type && (this._triggerFireCounts[n.trigger_type] = (this._triggerFireCounts[n.trigger_type] ?? 0) + 1), this._options.onMessage(n));
1318
- } catch {
1319
- }
1320
- }
1321
- }
1322
- const Vt = {
1323
- screen_size: "Ekran Boyutu",
1324
- weight: "Ağırlık",
1325
- battery_capacity: "Batarya Kapasitesi",
1326
- battery_life: "Batarya Ömrü",
1327
- storage: "Depolama",
1328
- memory: "Bellek",
1329
- ram: "RAM",
1330
- processor: "İşlemci",
1331
- camera: "Kamera",
1332
- resolution: "Çözünürlük",
1333
- display_type: "Ekran Tipi",
1334
- refresh_rate: "Yenileme Hızı",
1335
- color: "Renk",
1336
- material: "Malzeme",
1337
- dimensions: "Boyutlar",
1338
- warranty: "Garanti",
1339
- connectivity: "Bağlantı",
1340
- water_resistance: "Su Dayanıklılığı",
1341
- operating_system: "İşletim Sistemi",
1342
- brand: "Marka",
1343
- model: "Model",
1344
- price: "Fiyat",
1345
- energy_class: "Enerji Sınıfı",
1346
- noise_level: "Gürültü Seviyesi",
1347
- capacity: "Kapasite",
1348
- power: "Güç",
1349
- voltage: "Voltaj",
1350
- width: "Genişlik",
1351
- height: "Yükseklik",
1352
- depth: "Derinlik"
1353
- };
1354
- function $t(o) {
1355
- return Vt[o] ?? o.replace(/_/g, " ").replace(/^\w/, (e) => e.toUpperCase());
1356
- }
1357
- function Gt(o) {
1358
- const { recommended: e, products: t, attributes: a, highlights: n, specialCases: i, onProductClick: s, i18n: l } = o, r = document.createElement("div");
1359
- r.className = "gengage-chat-comparison";
1360
- const c = document.createElement("h3");
1361
- if (c.className = "gengage-chat-comparison-heading", c.textContent = l?.comparisonHeading ?? "KARŞILAŞTIRMA SONUÇLARI", r.appendChild(c), e) {
1362
- const g = document.createElement("div");
1363
- g.className = "gengage-chat-comparison-recommended";
1364
- const h = document.createElement("div");
1365
- h.className = "gengage-chat-comparison-recommended-label", h.textContent = l?.recommendedChoiceLabel ?? "Önerilen Seçim", g.appendChild(h);
1366
- const p = document.createElement("div");
1367
- if (p.className = "gengage-chat-comparison-recommended-body", e.imageUrl && W(e.imageUrl)) {
1368
- const _ = document.createElement("img");
1369
- _.src = e.imageUrl, _.alt = e.name, _.loading = "lazy", _.addEventListener(
1370
- "error",
1371
- () => {
1372
- _.style.display = "none";
1373
- },
1374
- { once: !0 }
1375
- ), p.appendChild(_);
1376
- }
1377
- const d = document.createElement("div");
1378
- d.className = "gengage-chat-comparison-recommended-info";
1379
- const f = document.createElement("div");
1380
- f.className = "gengage-chat-comparison-recommended-title", f.textContent = e.name, d.appendChild(f);
1381
- const k = document.createElement("div");
1382
- if (k.className = "gengage-chat-comparison-recommended-price", k.textContent = q(e.price, o.pricing), d.appendChild(k), p.appendChild(d), p.addEventListener("click", () => {
1383
- s(e.sku);
1384
- }), p.style.cursor = "pointer", g.appendChild(p), n.length > 0) {
1385
- const _ = document.createElement("div");
1386
- _.className = "gengage-chat-comparison-highlights";
1387
- const P = document.createElement("div");
1388
- P.className = "gengage-chat-comparison-highlights-label", P.textContent = l?.highlightsLabel ?? "Öne Çıkan Özellikler", _.appendChild(P);
1389
- const S = document.createElement("ul");
1390
- for (const T of n) {
1391
- const w = document.createElement("li");
1392
- w.textContent = T, S.appendChild(w);
1393
- }
1394
- _.appendChild(S), g.appendChild(_);
1395
- }
1396
- if (o.recommendedText) {
1397
- const _ = document.createElement("div");
1398
- _.className = "gengage-chat-comparison-recommended-text", _.innerHTML = $(o.recommendedText), g.appendChild(_);
1399
- }
1400
- r.appendChild(g);
1401
- }
1402
- if (o.keyDifferencesHtml) {
1403
- const g = document.createElement("div");
1404
- g.className = "gengage-chat-comparison-key-differences";
1405
- const h = document.createElement("h4");
1406
- h.textContent = l?.keyDifferencesLabel ?? "Temel Farklar", g.appendChild(h);
1407
- const p = document.createElement("div");
1408
- p.className = "gengage-chat-comparison-key-differences-content", p.innerHTML = $(Kt(o.keyDifferencesHtml)), g.appendChild(p), r.appendChild(g);
1409
- }
1410
- if (i && i.length > 0) {
1411
- const g = document.createElement("details");
1412
- g.className = "gengage-chat-comparison-special";
1413
- const h = document.createElement("summary");
1414
- h.textContent = l?.specialCasesLabel ?? "Özel Durumlar İçin", g.appendChild(h);
1415
- const p = document.createElement("ul");
1416
- for (const d of i)
1417
- Wt(p, d);
1418
- p.childElementCount > 0 && g.appendChild(p), r.appendChild(g);
1419
- }
1420
- if (t.length > 0 && a.length > 0) {
1421
- const g = document.createElement("table");
1422
- g.className = "gengage-chat-comparison-table";
1423
- const h = document.createElement("thead"), p = document.createElement("tr"), d = document.createElement("th");
1424
- p.appendChild(d);
1425
- for (const k of t) {
1426
- const _ = document.createElement("th");
1427
- if (k.sku === e?.sku && (_.className = "gengage-chat-comparison-selected"), k.imageUrl && W(k.imageUrl)) {
1428
- const T = document.createElement("img");
1429
- T.src = k.imageUrl, T.alt = k.name, T.loading = "lazy", T.addEventListener(
1430
- "error",
1431
- () => {
1432
- T.style.display = "none";
1433
- },
1434
- { once: !0 }
1435
- ), _.appendChild(T);
1436
- }
1437
- const P = document.createElement("div");
1438
- P.textContent = k.name, _.appendChild(P);
1439
- const S = document.createElement("div");
1440
- S.className = "gengage-chat-comparison-table-price", S.textContent = q(k.price, o.pricing), _.appendChild(S), p.appendChild(_);
1441
- }
1442
- h.appendChild(p), g.appendChild(h);
1443
- const f = document.createElement("tbody");
1444
- for (const k of a) {
1445
- const _ = document.createElement("tr"), P = document.createElement("td");
1446
- P.className = "gengage-chat-comparison-label", P.textContent = $t(k.label), _.appendChild(P);
1447
- for (let S = 0; S < k.values.length; S++) {
1448
- const T = document.createElement("td");
1449
- t[S]?.sku === e?.sku && (T.className = "gengage-chat-comparison-selected"), T.textContent = k.values[S] ?? "", _.appendChild(T);
1450
- }
1451
- f.appendChild(_);
1452
- }
1453
- g.appendChild(f), r.appendChild(g);
1454
- }
1455
- if (o.productActions) {
1456
- const g = document.createElement("div");
1457
- g.className = "gengage-chat-comparison-product-actions";
1458
- for (const h of t)
1459
- if (o.productActions[h.sku]) {
1460
- const d = document.createElement("button");
1461
- d.className = "gengage-chat-comparison-view-btn", d.type = "button", d.textContent = h.name, d.addEventListener("click", () => s(h.sku)), g.appendChild(d);
1462
- }
1463
- g.childElementCount > 0 && r.appendChild(g);
1464
- }
1465
- return r;
1466
- }
1467
- function Kt(o) {
1468
- const e = o.split(`
1469
- `).filter((t) => t.trim());
1470
- return e.length <= 1 ? o : "<ul>" + e.map((t) => `<li>${t.trim()}</li>`).join("") + "</ul>";
1471
- }
1472
- function Wt(o, e) {
1473
- const t = $(e);
1474
- if (!t) return;
1475
- const a = document.createElement("template");
1476
- a.innerHTML = t;
1477
- const n = Array.from(a.content.querySelectorAll("li"));
1478
- if (n.length > 0) {
1479
- for (const s of n) {
1480
- const l = document.createElement("li");
1481
- l.innerHTML = $(s.innerHTML), o.appendChild(l);
1482
- }
1483
- return;
1484
- }
1485
- const i = document.createElement("li");
1486
- Yt(e) ? i.innerHTML = t : i.textContent = e, o.appendChild(i);
1487
- }
1488
- function Yt(o) {
1489
- return /<\/?[a-z][\s\S]*>/i.test(o);
1490
- }
1491
- function Qt(o, e) {
1492
- const t = document.createElement("div");
1493
- t.className = "gengage-chat-review-highlights";
1494
- const a = o.props?.reviews;
1495
- if (!Array.isArray(a) || a.length === 0) {
1496
- const p = document.createElement("div");
1497
- return p.className = "gengage-chat-review-empty", p.textContent = e?.emptyReviewsMessage ?? "Yorum özeti bulunamadı.", t.appendChild(p), t;
1498
- }
1499
- const n = a.filter(
1500
- (p) => p !== null && typeof p == "object"
1501
- ), i = { all: n.length, positive: 0, negative: 0, neutral: 0 };
1502
- for (const p of n)
1503
- p.review_class === "positive" ? i.positive++ : p.review_class === "negative" ? i.negative++ : i.neutral++;
1504
- const s = document.createElement("div");
1505
- s.className = "gengage-chat-review-tabs";
1506
- const l = [{ label: `Tümü (${i.all})`, filter: "all" }];
1507
- i.positive > 0 && l.push({ label: `Olumlu (${i.positive})`, filter: "positive" }), i.negative > 0 && l.push({ label: `Olumsuz (${i.negative})`, filter: "negative" });
1508
- let r = "all";
1509
- const c = document.createElement("div");
1510
- c.className = "gengage-chat-review-items";
1511
- function g() {
1512
- for (; c.firstChild; ) c.removeChild(c.firstChild);
1513
- const p = r === "all" ? n : n.filter((d) => d.review_class === r);
1514
- for (const d of p) {
1515
- const f = document.createElement("article");
1516
- f.className = "gengage-chat-review-item";
1517
- const k = d.review_class;
1518
- if ((k === "positive" || k === "negative" || k === "neutral") && (f.dataset.tone = k), typeof d.review_tag == "string" && d.review_tag.length > 0) {
1519
- const _ = document.createElement("div");
1520
- _.className = "gengage-chat-review-tag", _.textContent = d.review_tag, f.appendChild(_);
1521
- }
1522
- if (typeof d.review_text == "string" && d.review_text.length > 0) {
1523
- const _ = document.createElement("div");
1524
- _.className = "gengage-chat-review-text", _.textContent = d.review_text, f.appendChild(_);
1525
- }
1526
- if (d.review_rating !== void 0 && String(d.review_rating).length > 0) {
1527
- const _ = document.createElement("div");
1528
- _.className = "gengage-chat-review-rating", _.textContent = String(d.review_rating), f.appendChild(_);
1529
- }
1530
- c.appendChild(f);
1531
- }
1532
- }
1533
- for (const p of l) {
1534
- const d = document.createElement("button");
1535
- d.className = "gengage-chat-review-tab", d.type = "button", d.textContent = p.label, p.filter === r && d.classList.add("gengage-chat-review-tab--active"), d.addEventListener("click", () => {
1536
- r = p.filter;
1537
- for (const f of s.querySelectorAll(".gengage-chat-review-tab"))
1538
- f.classList.toggle("gengage-chat-review-tab--active", f === d);
1539
- g();
1540
- }), s.appendChild(d);
1541
- }
1542
- t.appendChild(s);
1543
- const h = /* @__PURE__ */ new Map();
1544
- for (const p of n)
1545
- if (typeof p.review_tag == "string" && p.review_tag.length > 0) {
1546
- const d = h.get(p.review_tag);
1547
- d ? d.count++ : h.set(p.review_tag, { count: 1, sentiment: p.review_class ?? "neutral" });
1548
- }
1549
- if (h.size > 0) {
1550
- const p = document.createElement("div");
1551
- p.className = "gengage-chat-review-pills";
1552
- for (const [d, f] of h) {
1553
- const k = document.createElement("span");
1554
- k.className = "gengage-chat-review-pill", k.dataset.tone = f.sentiment;
1555
- const _ = document.createElement("span");
1556
- _.className = "gengage-chat-review-pill-icon", _.textContent = f.sentiment === "positive" ? "✓" : f.sentiment === "negative" ? "✕" : "●", k.appendChild(_);
1557
- const P = document.createElement("span");
1558
- if (P.textContent = d, k.appendChild(P), f.count > 1) {
1559
- const S = document.createElement("span");
1560
- S.className = "gengage-chat-review-pill-count", S.textContent = String(f.count), k.appendChild(S);
1561
- }
1562
- p.appendChild(k);
1563
- }
1564
- t.appendChild(p);
1565
- }
1566
- return g(), t.appendChild(c), t;
1567
- }
1568
- function Ee(o) {
1569
- const e = o.product.sku;
1570
- if (typeof e == "string" && e.length > 0) return e;
1571
- const t = o.action?.payload;
1572
- return t && typeof t == "object" && "sku" in t && typeof t.sku == "string" ? t.sku : null;
1573
- }
1574
- const Xt = {
1575
- winner: "roleWinner",
1576
- best_value: "roleBestValue",
1577
- best_alternative: "roleBestAlternative"
1578
- };
1579
- function Se(o, e) {
1580
- if (!o || !e) return null;
1581
- const t = Xt[o];
1582
- return t ? e[t] ?? o : o;
1583
- }
1584
- function Jt(o, e) {
1585
- const t = document.createElement("div");
1586
- t.className = "gengage-chat-ai-top-picks";
1587
- const a = o.props?.suggestions ?? [];
1588
- if (a.length === 0) return t;
1589
- const n = document.createElement("h3");
1590
- n.className = "gengage-chat-ai-top-picks-title", n.textContent = e.i18n?.aiTopPicksTitle ?? "Top Picks", t.appendChild(n);
1591
- const i = document.createElement("div");
1592
- i.className = "gengage-chat-ai-top-picks-cards";
1593
- for (let s = 0; s < a.length; s++) {
1594
- const l = a[s], c = l.role === "winner" || s === 0 ? Zt(l, e) : ea(l, e);
1595
- i.appendChild(c);
1596
- }
1597
- return t.appendChild(i), t;
1598
- }
1599
- function Zt(o, e) {
1600
- const t = document.createElement("div");
1601
- t.className = "gengage-chat-ai-toppick-card gengage-chat-ai-toppick-card--winner";
1602
- const a = document.createElement("span");
1603
- a.className = "gengage-chat-ai-toppick-badge", a.textContent = Se(o.role, e.i18n) ?? e.i18n?.roleWinner ?? "TOP MATCH", t.appendChild(a);
1604
- const n = o.product, i = n.discountPercent;
1605
- if (typeof i == "number" && i > 0) {
1606
- const h = document.createElement("span");
1607
- h.className = "gengage-chat-ai-toppick-discount-badge", h.textContent = `%${se(i)}`, t.appendChild(h);
1608
- }
1609
- const s = n.imageUrl;
1610
- if (s && W(s)) {
1611
- const h = document.createElement("img");
1612
- h.className = "gengage-chat-ai-toppick-img", R(h, "src", s), h.alt = n.name ?? "", X(h), t.appendChild(h);
1613
- }
1614
- const l = document.createElement("div");
1615
- l.className = "gengage-chat-ai-toppick-body";
1616
- const r = n.name;
1617
- if (r) {
1618
- const h = document.createElement("div");
1619
- h.className = "gengage-chat-ai-toppick-name", h.textContent = r, l.appendChild(h);
1620
- }
1621
- if (o.reason) {
1622
- const h = document.createElement("div");
1623
- h.className = "gengage-chat-ai-toppick-reason", h.textContent = o.reason, l.appendChild(h);
1624
- }
1625
- if (o.labels && o.labels.length > 0 && l.appendChild(Te(o.labels)), typeof o.expertQualityScore == "number") {
1626
- const h = document.createElement("div");
1627
- h.className = "gengage-chat-ai-toppick-score";
1628
- const p = o.expertQualityScore <= 5 ? 5 : 10;
1629
- h.textContent = `${o.expertQualityScore}/${p}`, l.appendChild(h);
1630
- }
1631
- if (o.reviewHighlight) {
1632
- const h = document.createElement("blockquote");
1633
- h.className = "gengage-chat-ai-toppick-review", h.textContent = o.reviewHighlight, l.appendChild(h);
1634
- }
1635
- const c = n.price, g = n.originalPrice;
1636
- if (c) {
1637
- const h = document.createElement("div");
1638
- if (h.className = "gengage-chat-ai-toppick-price", g && g !== c) {
1639
- const d = document.createElement("span");
1640
- d.className = "gengage-chat-ai-toppick-original-price", d.textContent = q(g, e.pricing), h.appendChild(d), h.appendChild(document.createTextNode(" "));
1641
- }
1642
- const p = document.createElement("span");
1643
- p.textContent = q(c, e.pricing), h.appendChild(p), l.appendChild(h);
1644
- }
1645
- if (t.appendChild(l), o.action) {
1646
- const h = Ee(o), p = n.url ?? "", d = document.createElement("div");
1647
- d.className = "gengage-chat-ai-toppick-spinner", d.style.display = h && e.topPicksLoadingSku === h ? "" : "none", t.appendChild(d);
1648
- const f = document.createElement("button");
1649
- f.className = "gengage-chat-ai-toppick-cta", f.type = "button", f.textContent = e.i18n?.viewDetails ?? "View Details", f.addEventListener("click", () => {
1650
- if (o.action?.type === "findSimilar" && h && e.onProductClick) {
1651
- e.onProductClick({ sku: h, url: p });
1652
- return;
1653
- }
1654
- e.onAction(o.action);
1655
- }), t.appendChild(f);
1656
- }
1657
- return t;
1658
- }
1659
- function ea(o, e) {
1660
- const t = document.createElement("div");
1661
- t.className = "gengage-chat-ai-toppick-card gengage-chat-ai-toppick-card--compact";
1662
- const a = o.product, n = a.discountPercent;
1663
- if (typeof n == "number" && n > 0) {
1664
- const g = document.createElement("span");
1665
- g.className = "gengage-chat-ai-toppick-discount-badge", g.textContent = `%${se(n)}`, t.appendChild(g);
1666
- }
1667
- const i = a.imageUrl;
1668
- if (i && W(i)) {
1669
- const g = document.createElement("img");
1670
- g.className = "gengage-chat-ai-toppick-img", R(g, "src", i), g.alt = a.name ?? "", X(g), t.appendChild(g);
1671
- }
1672
- const s = document.createElement("div");
1673
- s.className = "gengage-chat-ai-toppick-body";
1674
- const l = Se(o.role, e.i18n);
1675
- if (l) {
1676
- const g = document.createElement("div");
1677
- g.className = "gengage-chat-ai-toppick-role", g.textContent = l, s.appendChild(g);
1678
- }
1679
- const r = a.name;
1680
- if (r) {
1681
- const g = document.createElement("div");
1682
- g.className = "gengage-chat-ai-toppick-name", g.textContent = r, s.appendChild(g);
1683
- }
1684
- if (o.reason) {
1685
- const g = document.createElement("div");
1686
- g.className = "gengage-chat-ai-toppick-reason", g.textContent = o.reason, s.appendChild(g);
1687
- }
1688
- o.labels && o.labels.length > 0 && s.appendChild(Te(o.labels));
1689
- const c = a.price;
1690
- if (c) {
1691
- const g = document.createElement("div");
1692
- g.className = "gengage-chat-ai-toppick-price", g.textContent = q(c, e.pricing), s.appendChild(g);
1693
- }
1694
- if (t.appendChild(s), o.action) {
1695
- const g = Ee(o), h = a.url ?? "", p = document.createElement("div");
1696
- p.className = "gengage-chat-ai-toppick-spinner", p.style.display = g && e.topPicksLoadingSku === g ? "" : "none", t.appendChild(p);
1697
- const d = document.createElement("button");
1698
- d.className = "gengage-chat-ai-toppick-cta", d.type = "button", d.textContent = e.i18n?.viewDetails ?? "View Details", d.addEventListener("click", () => {
1699
- if (o.action?.type === "findSimilar" && g && e.onProductClick) {
1700
- e.onProductClick({ sku: g, url: h });
1701
- return;
1702
- }
1703
- e.onAction(o.action);
1704
- }), t.appendChild(d);
1705
- }
1706
- return t;
1707
- }
1708
- function Te(o) {
1709
- const e = document.createElement("div");
1710
- e.className = "gengage-chat-ai-toppick-labels";
1711
- for (const t of o) {
1712
- const a = document.createElement("span");
1713
- a.className = "gengage-chat-ai-toppick-label", a.dataset.sentiment = t.sentiment ?? "neutral", a.textContent = t.label, e.appendChild(a);
1714
- }
1715
- return e;
1716
- }
1717
- function ta(o, e) {
1718
- const t = document.createElement("div");
1719
- t.className = "gengage-chat-grounding-review";
1720
- const a = o.props ?? {}, n = a.title, i = a.reviewCount, s = a.action, l = e.i18n?.groundingReviewCta ?? "Yorumları Oku", r = document.createElement("span");
1721
- r.className = "gengage-chat-grounding-review-icon", r.textContent = "📋", t.appendChild(r);
1722
- const c = document.createElement("div");
1723
- c.className = "gengage-chat-grounding-review-body";
1724
- const g = document.createElement("div");
1725
- if (g.className = "gengage-chat-grounding-review-title", g.textContent = n ?? "Müşteri Yorumları", c.appendChild(g), i) {
1726
- const p = document.createElement("div");
1727
- p.className = "gengage-chat-grounding-review-subtitle";
1728
- const d = e.i18n?.groundingReviewSubtitle ?? "{count} yorum mevcut";
1729
- p.textContent = d.replace("{count}", i), c.appendChild(p);
1730
- }
1731
- t.appendChild(c);
1732
- const h = document.createElement("span");
1733
- return h.className = "gengage-chat-grounding-review-cta", h.textContent = `${l} →`, t.appendChild(h), s && (t.style.cursor = "pointer", t.addEventListener("click", () => e.onAction(s))), t;
1734
- }
1735
- function aa(o) {
1736
- if (o.action.type !== "findSimilar") return o.action;
1737
- const e = o.action.payload && typeof o.action.payload == "object" ? o.action.payload : null, t = typeof e?.input == "string" && e.input.trim() || typeof e?.text == "string" && e.text.trim() || o.name.trim();
1738
- if (!t) return o.action;
1739
- const a = {
1740
- text: t,
1741
- is_suggested_text: 1
1742
- };
1743
- if (typeof e?.sku == "string" && e.sku.trim() && (a.sku = e.sku), Array.isArray(e?.group_skus)) {
1744
- const n = e.group_skus.filter((i) => typeof i == "string" && i.length > 0);
1745
- n.length > 0 && (a.group_skus = n);
1746
- }
1747
- return {
1748
- title: o.action.title,
1749
- type: "inputText",
1750
- payload: a
1751
- };
1752
- }
1753
- function na(o, e) {
1754
- const t = document.createElement("div");
1755
- t.className = "gengage-chat-grouping-cards";
1756
- const a = o.props?.entries ?? [];
1757
- if (a.length === 0) return t;
1758
- for (const n of a) {
1759
- const i = document.createElement("div");
1760
- if (i.className = "gengage-chat-grouping-card", i.style.cursor = "pointer", i.addEventListener("click", () => e.onAction(aa(n))), n.image && W(n.image)) {
1761
- const c = document.createElement("img");
1762
- c.className = "gengage-chat-grouping-card-img", c.src = n.image, c.alt = n.name, c.width = 20, c.height = 20, i.appendChild(c);
1763
- }
1764
- const s = document.createElement("div");
1765
- s.className = "gengage-chat-grouping-card-body";
1766
- const l = document.createElement("span");
1767
- if (l.className = "gengage-chat-grouping-card-name", l.textContent = n.name, s.appendChild(l), n.description) {
1768
- const c = document.createElement("span");
1769
- c.className = "gengage-chat-grouping-card-desc", c.textContent = n.description, s.appendChild(c);
1770
- }
1771
- if (n.labels && n.labels.length > 0) {
1772
- const c = document.createElement("span");
1773
- c.className = "gengage-chat-grouping-card-labels", c.textContent = n.labels.slice(0, 3).join(" · "), s.appendChild(c);
1774
- }
1775
- i.appendChild(s);
1776
- const r = document.createElement("span");
1777
- r.className = "gengage-chat-grouping-card-arrow", r.textContent = "↳", i.insertBefore(r, i.firstChild), t.appendChild(i);
1778
- }
1779
- return t;
1780
- }
1781
- function ia(o, e) {
1782
- const t = document.createElement("div");
1783
- t.className = "gengage-chat-suggested-search-cards";
1784
- const a = o.props?.entries ?? [];
1785
- if (a.length === 0) return t;
1786
- for (const n of a) {
1787
- const i = document.createElement("div");
1788
- if (i.className = "gengage-chat-suggested-search-card", i.style.cursor = "pointer", i.addEventListener("click", () => e.onAction(n.action)), n.image && W(n.image)) {
1789
- const r = document.createElement("img");
1790
- r.className = "gengage-chat-suggested-search-card-img", r.src = n.image, r.alt = n.shortName, r.width = 40, r.height = 40, i.appendChild(r);
1791
- }
1792
- const s = document.createElement("div");
1793
- s.className = "gengage-chat-suggested-search-card-body";
1794
- const l = document.createElement("div");
1795
- if (l.className = "gengage-chat-suggested-search-card-name", l.textContent = n.shortName, s.appendChild(l), n.detailedMessage) {
1796
- const r = document.createElement("div");
1797
- r.className = "gengage-chat-suggested-search-card-desc", r.textContent = n.detailedMessage, s.appendChild(r);
1798
- }
1799
- if (n.whyDifferent) {
1800
- const r = document.createElement("div");
1801
- r.className = "gengage-chat-suggested-search-card-diff", r.textContent = n.whyDifferent, s.appendChild(r);
1802
- }
1803
- i.appendChild(s), t.appendChild(i);
1804
- }
1805
- return t;
1806
- }
1807
- function oa(o, e) {
1808
- const t = document.createElement("button");
1809
- t.className = "gengage-chat-comparison-floating-btn", t.type = "button";
1810
- const a = e.i18n?.compareSelected ?? "Karşılaştır";
1811
- return t.textContent = `${a} (${o.length})`, t.addEventListener("click", () => {
1812
- e.onAction({
1813
- title: a,
1814
- type: "getComparisonTable",
1815
- payload: { sku_list: [...o] }
1816
- });
1817
- }), t;
1818
- }
1819
- function ra(o) {
1820
- const e = document.createElement("div");
1821
- e.className = "gengage-chat-pros-cons";
1822
- const t = o.props?.productName;
1823
- if (t) {
1824
- const i = document.createElement("h4");
1825
- i.className = "gengage-chat-pros-cons-heading", i.textContent = t, e.appendChild(i);
1826
- }
1827
- const a = o.props?.pros, n = o.props?.cons;
1828
- if (a && a.length > 0) {
1829
- const i = document.createElement("ul");
1830
- i.className = "gengage-chat-pros-cons-list";
1831
- for (const s of a) {
1832
- const l = document.createElement("li");
1833
- l.className = "gengage-chat-pros-cons-item";
1834
- const r = document.createElement("span");
1835
- r.className = "gengage-chat-pros-cons-icon gengage-chat-pros-cons-icon--pro", r.textContent = "✓", l.appendChild(r);
1836
- const c = document.createElement("span");
1837
- c.textContent = s, l.appendChild(c), i.appendChild(l);
1838
- }
1839
- e.appendChild(i);
1840
- }
1841
- if (n && n.length > 0) {
1842
- const i = document.createElement("ul");
1843
- i.className = "gengage-chat-pros-cons-list";
1844
- for (const s of n) {
1845
- const l = document.createElement("li");
1846
- l.className = "gengage-chat-pros-cons-item";
1847
- const r = document.createElement("span");
1848
- r.className = "gengage-chat-pros-cons-icon gengage-chat-pros-cons-icon--con", r.textContent = "✗", l.appendChild(r);
1849
- const c = document.createElement("span");
1850
- c.textContent = s, l.appendChild(c), i.appendChild(l);
1851
- }
1852
- e.appendChild(i);
1853
- }
1854
- return e;
1855
- }
1856
- function sa(o, e) {
1857
- const t = o.props?.groups ?? [], a = o.props?.filterTags ?? [], n = document.createElement("div");
1858
- if (n.className = "gengage-chat-categories", t.length === 0) return n;
1859
- const i = document.createElement("div");
1860
- i.className = "gengage-chat-categories-tabs", i.setAttribute("role", "tablist");
1861
- const s = [], l = [], r = (c) => {
1862
- for (let g = 0; g < s.length; g++) {
1863
- const h = g === c;
1864
- s[g].classList.toggle("gengage-chat-categories-tab--active", h), s[g].setAttribute("aria-selected", String(h)), s[g].tabIndex = h ? 0 : -1, l[g].style.display = h ? "" : "none";
1865
- }
1866
- };
1867
- for (let c = 0; c < t.length; c++) {
1868
- const g = t[c], h = `gengage-cat-tab-${c}`, p = `gengage-cat-panel-${c}`, d = document.createElement("button");
1869
- d.className = "gengage-chat-categories-tab", d.type = "button", d.id = h, d.setAttribute("role", "tab"), d.setAttribute("aria-controls", p), d.setAttribute("aria-selected", String(c === 0)), d.tabIndex = c === 0 ? 0 : -1, c === 0 && d.classList.add("gengage-chat-categories-tab--active"), d.textContent = g.groupName, d.addEventListener("click", () => r(c)), d.addEventListener("keydown", (k) => {
1870
- let _ = -1;
1871
- k.key === "ArrowRight" || k.key === "ArrowDown" ? _ = (c + 1) % t.length : k.key === "ArrowLeft" || k.key === "ArrowUp" ? _ = (c - 1 + t.length) % t.length : k.key === "Home" ? _ = 0 : k.key === "End" && (_ = t.length - 1), _ >= 0 && (k.preventDefault(), r(_), s[_].focus());
1872
- }), s.push(d), i.appendChild(d);
1873
- const f = document.createElement("div");
1874
- f.className = "gengage-chat-categories-grid", f.id = p, f.setAttribute("role", "tabpanel"), f.setAttribute("aria-labelledby", h), c !== 0 && (f.style.display = "none");
1875
- for (const k of g.products) {
1876
- const _ = ca(k, e);
1877
- f.appendChild(_);
1878
- }
1879
- l.push(f);
1880
- }
1881
- n.appendChild(i);
1882
- for (const c of l) n.appendChild(c);
1883
- if (a.length > 0) {
1884
- const c = document.createElement("div");
1885
- c.className = "gengage-chat-categories-filter-tags";
1886
- for (const g of a) {
1887
- const h = document.createElement("button");
1888
- h.className = "gengage-chat-categories-filter-tag", h.type = "button", h.textContent = g.title, g.action && h.addEventListener("click", () => {
1889
- e.onAction(g.action);
1890
- }), c.appendChild(h);
1891
- }
1892
- n.appendChild(c);
1893
- }
1894
- return n;
1895
- }
1896
- function ca(o, e) {
1897
- const t = document.createElement("div");
1898
- if (t.className = "gengage-chat-product-card", o.imageUrl && W(o.imageUrl)) {
1899
- const i = document.createElement("img");
1900
- i.className = "gengage-chat-product-card-img", i.src = o.imageUrl, i.alt = o.name, t.appendChild(i);
1901
- }
1902
- const a = document.createElement("div");
1903
- a.className = "gengage-chat-product-card-body";
1904
- const n = document.createElement("div");
1905
- if (n.className = "gengage-chat-product-card-name", n.textContent = o.name, a.appendChild(n), o.price) {
1906
- const i = document.createElement("div");
1907
- i.className = "gengage-chat-product-card-price", i.textContent = o.price, a.appendChild(i);
1908
- }
1909
- return t.appendChild(a), e.onProductSelect && (t.style.cursor = "pointer", t.addEventListener("click", () => {
1910
- e.onProductSelect?.(o);
1911
- })), t;
1912
- }
1913
- function la(o, e) {
1914
- const t = document.createElement("div");
1915
- t.className = "gengage-chat-handoff-notice", t.setAttribute("role", "alert");
1916
- const a = document.createElement("span");
1917
- a.className = "gengage-chat-handoff-notice-icon", a.textContent = "👤", a.setAttribute("aria-hidden", "true"), t.appendChild(a);
1918
- const n = document.createElement("h4");
1919
- n.className = "gengage-chat-handoff-notice-heading", n.textContent = e.i18n?.handoffHeading ?? "Transferring to a support agent", t.appendChild(n);
1920
- const i = o.props?.summary;
1921
- if (i) {
1922
- const s = document.createElement("p");
1923
- s.className = "gengage-chat-handoff-notice-summary", s.textContent = i, t.appendChild(s);
1924
- }
1925
- return t;
1926
- }
1927
- function ga(o, e) {
1928
- const t = o.props?.product ?? o.props, a = document.createElement("div");
1929
- if (a.className = "gengage-chat-product-summary", !t) return a;
1930
- a.style.cursor = "pointer", a.addEventListener("click", (d) => {
1931
- d.target.closest("a") || e.onProductSelect?.(t);
1932
- });
1933
- const n = t.imageUrl;
1934
- if (n && G(n)) {
1935
- const d = document.createElement("div");
1936
- d.className = "gengage-chat-product-summary__image";
1937
- const f = document.createElement("img");
1938
- R(f, "src", n);
1939
- const k = t.name;
1940
- k && (f.alt = k), X(f), d.appendChild(f), a.appendChild(d);
1941
- }
1942
- const i = document.createElement("div");
1943
- i.className = "gengage-chat-product-summary__content";
1944
- const s = t.brand, l = t.name;
1945
- if (l) {
1946
- const d = document.createElement("div");
1947
- d.className = "gengage-chat-product-summary__name";
1948
- const f = s && !l.toLowerCase().startsWith(s.toLowerCase());
1949
- d.textContent = f ? `${s} ${l}` : l, i.appendChild(d);
1950
- }
1951
- const r = t.rating, c = t.reviewCount;
1952
- if (typeof r == "number" && Number.isFinite(r) && r > 0) {
1953
- const d = document.createElement("div");
1954
- if (d.className = "gengage-chat-product-summary__rating", d.textContent = _e(ye(r)), typeof c == "number" && Number.isFinite(c)) {
1955
- const f = document.createElement("span");
1956
- f.className = "gengage-chat-product-summary__review-count", f.textContent = ` (${c})`, d.appendChild(f);
1957
- }
1958
- i.appendChild(d);
1959
- }
1960
- const g = t.price, h = t.originalPrice;
1961
- if (g) {
1962
- const d = document.createElement("div");
1963
- if (d.className = "gengage-chat-product-summary__price", h && h !== g) {
1964
- const k = document.createElement("span");
1965
- k.className = "gengage-chat-product-summary__price-original", k.textContent = q(h, e.pricing), d.appendChild(k), d.appendChild(document.createTextNode(" "));
1966
- }
1967
- const f = document.createElement("span");
1968
- f.className = "gengage-chat-product-summary__price-current", f.textContent = q(g, e.pricing), d.appendChild(f), i.appendChild(d);
1969
- }
1970
- a.appendChild(i);
1971
- const p = t.url;
1972
- if (p && G(p)) {
1973
- const d = document.createElement("a");
1974
- d.className = "gengage-chat-product-summary__cta", R(d, "href", p), R(d, "target", "_blank"), R(d, "rel", "noopener noreferrer"), d.textContent = e.i18n?.productCtaLabel ?? "İncele", a.appendChild(d);
1975
- }
1976
- return a;
1977
- }
1978
- function Ie() {
1979
- return window.innerWidth < 768;
1980
- }
1981
- const Le = {
1982
- ActionButtons: ({ element: o, context: e }) => ha(o, e),
1983
- ActionButton: ({ element: o, context: e }) => ua(o, e),
1984
- ProductCard: ({ element: o, context: e }) => ma(o, e),
1985
- ProductDetailsPanel: ({ element: o, context: e }) => fa(o, e),
1986
- ProductGrid: ({ element: o, spec: e, renderElement: t, context: a }) => va(o, e, t, a),
1987
- ReviewHighlights: ({ element: o, context: e }) => Qt(o, { emptyReviewsMessage: e.i18n?.emptyReviewsMessage }),
1988
- ComparisonTable: ({ element: o, context: e }) => wa(o, e),
1989
- AITopPicks: ({ element: o, context: e }) => Jt(o, e),
1990
- GroundingReviewCard: ({ element: o, context: e }) => ta(o, e),
1991
- AIGroupingCards: ({ element: o, context: e }) => na(o, e),
1992
- AISuggestedSearchCards: ({ element: o, context: e }) => ia(o, e),
1993
- ProsAndCons: ({ element: o }) => ra(o),
1994
- CategoriesContainer: ({ element: o, context: e }) => sa(o, e),
1995
- HandoffNotice: ({ element: o, context: e }) => la(o, e),
1996
- ProductSummaryCard: ({ element: o, context: e }) => ga(o, e),
1997
- Divider: ({ element: o }) => _a(o)
1998
- }, Ne = ({
1999
- element: o,
2000
- renderElement: e
2001
- }) => {
2002
- if (!o.children || o.children.length === 0)
2003
- return null;
2004
- const t = document.createElement("div");
2005
- for (const a of o.children) {
2006
- const n = e(a);
2007
- n && t.appendChild(n);
2008
- }
2009
- return t;
2010
- };
2011
- function da() {
2012
- return { ...Le };
2013
- }
2014
- function pa(o, e, t = Le, a = Ne) {
2015
- return Ue({
2016
- spec: o,
2017
- context: e,
2018
- registry: t,
2019
- containerClassName: "gengage-chat-uispec",
2020
- unknownRenderer: a
2021
- });
2022
- }
2023
- function ha(o, e) {
2024
- const t = document.createElement("div");
2025
- t.className = "gengage-chat-action-buttons";
2026
- const a = o.props?.buttons;
2027
- if (a)
2028
- for (const n of a) {
2029
- const i = document.createElement("button");
2030
- i.className = "gengage-chat-action-btn", i.textContent = n.label, i.addEventListener("click", () => e.onAction(n.action)), t.appendChild(i);
2031
- }
2032
- return t;
2033
- }
2034
- function ua(o, e) {
2035
- const t = document.createElement("button");
2036
- t.className = "gengage-chat-action-btn";
2037
- const a = o.props?.label;
2038
- typeof a == "string" && (t.textContent = a);
2039
- const n = o.props?.action;
2040
- return n && t.addEventListener("click", () => e.onAction(n)), t;
2041
- }
2042
- function ma(o, e) {
2043
- const t = document.createElement("div");
2044
- t.className = "gengage-chat-product-card";
2045
- const a = o.props?.product ?? o.props;
2046
- if (!a) return t;
2047
- const n = a.sku;
2048
- n && (t.dataset.sku = n), e.onProductSelect && (t.style.cursor = "pointer", t.addEventListener("click", (w) => {
2049
- w.target.closest(".gengage-chat-product-card-atc") || w.target.closest(".gengage-chat-product-card-cta") || e.onProductSelect?.(a);
2050
- }));
2051
- const i = a.imageUrl;
2052
- if (i && G(i)) {
2053
- const w = document.createElement("div");
2054
- w.className = "gengage-chat-product-card-img-wrapper";
2055
- const u = document.createElement("img");
2056
- u.className = "gengage-chat-product-card-img", u.loading = "lazy", R(u, "src", i);
2057
- const E = a.name;
2058
- E && (u.alt = E), X(u), w.appendChild(u);
2059
- const I = a.discountPercent;
2060
- if (typeof I == "number" && I > 0) {
2061
- const y = document.createElement("span");
2062
- y.className = "gengage-chat-product-card-discount-badge", y.textContent = `%${se(I)}`, w.appendChild(y);
2063
- }
2064
- const m = a.sku;
2065
- if (m) {
2066
- const y = document.createElement("button");
2067
- y.className = "gengage-chat-find-similar-pill", y.type = "button", y.textContent = e.i18n?.findSimilarLabel ?? "Benzerlerini Bul", y.addEventListener("click", (b) => {
2068
- b.stopPropagation(), e.onAction({
2069
- title: e.i18n?.findSimilarLabel ?? "Benzerlerini Bul",
2070
- type: "findSimilar",
2071
- payload: { sku: m, ...i ? { image_url: i } : {} }
2072
- });
2073
- }), w.appendChild(y);
2074
- }
2075
- const x = a.sku;
2076
- if (x && e.onFavoriteToggle) {
2077
- const y = document.createElement("button");
2078
- y.className = "gengage-chat-favorite-btn", y.type = "button", y.setAttribute("aria-label", "Favorilere ekle");
2079
- const b = e.favoritedSkus?.has(x) ?? !1;
2080
- b && y.classList.add("gengage-chat-favorite-btn--active");
2081
- const A = b ? "currentColor" : "none";
2082
- y.innerHTML = `<svg width="16" height="16" viewBox="0 0 24 24" fill="${A}" stroke="currentColor" stroke-width="2"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>`, y.addEventListener("click", (C) => {
2083
- C.stopPropagation(), y.classList.toggle("gengage-chat-favorite-btn--active");
2084
- const L = y.querySelector("svg");
2085
- L && L.setAttribute(
2086
- "fill",
2087
- y.classList.contains("gengage-chat-favorite-btn--active") ? "currentColor" : "none"
2088
- ), e.onFavoriteToggle(x, a);
2089
- }), w.appendChild(y);
2090
- }
2091
- t.appendChild(w);
2092
- }
2093
- const s = document.createElement("div");
2094
- s.className = "gengage-chat-product-card-body";
2095
- const l = a.brand;
2096
- if (l) {
2097
- const w = document.createElement("div");
2098
- w.className = "gengage-chat-product-card-brand", w.textContent = l, s.appendChild(w);
2099
- }
2100
- const r = a.name;
2101
- if (r) {
2102
- const w = document.createElement("div");
2103
- w.className = "gengage-chat-product-card-name", w.textContent = r, s.appendChild(w);
2104
- }
2105
- const c = a.rating, g = a.reviewCount;
2106
- if (typeof c == "number" && Number.isFinite(c)) {
2107
- const w = document.createElement("div");
2108
- if (w.className = "gengage-chat-product-card-rating", w.textContent = _e(c), typeof g == "number" && Number.isFinite(g)) {
2109
- const u = document.createElement("span");
2110
- u.className = "gengage-chat-product-card-review-count", u.textContent = ` (${g})`, w.appendChild(u);
2111
- }
2112
- s.appendChild(w);
2113
- }
2114
- const h = a.price, p = a.originalPrice;
2115
- if (a.price_async === !0) {
2116
- const w = document.createElement("div");
2117
- w.className = "gengage-chat-product-card-price";
2118
- const u = document.createElement("span");
2119
- u.className = "gengage-chat-price-skeleton", w.appendChild(u), s.appendChild(w), setTimeout(() => {
2120
- u.parentElement && (h ? u.replaceWith(document.createTextNode(q(h, e.pricing))) : u.remove());
2121
- }, 300);
2122
- } else if (h) {
2123
- const w = document.createElement("div");
2124
- if (w.className = "gengage-chat-product-card-price", p && p !== h) {
2125
- const E = document.createElement("span");
2126
- E.className = "gengage-chat-product-card-original-price", E.textContent = q(p, e.pricing), w.appendChild(E), w.appendChild(document.createTextNode(" "));
2127
- }
2128
- const u = document.createElement("span");
2129
- u.textContent = q(h, e.pricing), w.appendChild(u), s.appendChild(w);
2130
- }
2131
- const f = a.inStock;
2132
- if (typeof f == "boolean") {
2133
- const w = document.createElement("div");
2134
- w.className = `gengage-chat-product-card-stock ${f ? "is-in-stock" : "is-out-of-stock"}`, w.textContent = f ? e.i18n?.inStockLabel ?? "Stokta" : e.i18n?.outOfStockLabel ?? "Tükendi", s.appendChild(w);
2135
- }
2136
- const k = a.promotions;
2137
- if (k && k.length > 0) {
2138
- const w = document.createElement("div");
2139
- w.className = "gengage-chat-product-card-promos";
2140
- for (const u of k) {
2141
- const E = document.createElement("span");
2142
- E.className = "gengage-chat-product-card-promo-badge", E.textContent = u, w.appendChild(E);
2143
- }
2144
- s.appendChild(w);
2145
- }
2146
- t.appendChild(s);
2147
- const _ = a.url, P = a.sku, S = o.props?.action;
2148
- if (S) {
2149
- const w = document.createElement("button");
2150
- w.className = "gengage-chat-product-card-cta", w.type = "button", w.textContent = S.title || e.i18n?.productCtaLabel || "Incele", w.addEventListener("click", () => e.onAction(S)), t.appendChild(w);
2151
- } else if (_ && G(_)) {
2152
- const w = document.createElement("a");
2153
- w.className = "gengage-chat-product-card-cta", R(w, "href", _), R(w, "target", "_blank"), R(w, "rel", "noopener noreferrer"), w.textContent = e.i18n?.productCtaLabel ?? "İncele", w.addEventListener("click", (u) => {
2154
- e.onProductClick && P && (u.preventDefault(), e.onProductClick({ sku: P, url: _ }));
2155
- }), t.appendChild(w);
2156
- }
2157
- const T = a.cartCode;
2158
- if (T && P && f !== !1) {
2159
- const w = ke({
2160
- compact: !0,
2161
- label: e.i18n?.addToCartButton ?? "Sepete Ekle",
2162
- onSubmit: (u) => {
2163
- e.onAction({
2164
- title: e.i18n?.addToCartButton ?? "Sepete Ekle",
2165
- type: "addToCart",
2166
- payload: { sku: P, cartCode: T, quantity: u }
2167
- });
2168
- }
2169
- });
2170
- w.classList.add("gengage-chat-product-card-atc"), t.appendChild(w);
2171
- }
2172
- if (e.comparisonSelectMode && P && e.onToggleComparisonSku) {
2173
- const w = document.createElement("div");
2174
- w.className = "gengage-chat-comparison-select-wrapper";
2175
- const u = document.createElement("input");
2176
- return u.type = "checkbox", u.className = "gengage-chat-comparison-checkbox", u.checked = e.comparisonSelectedSkus?.includes(P) ?? !1, u.addEventListener("change", () => {
2177
- e.onToggleComparisonSku?.(P);
2178
- }), w.appendChild(u), w.appendChild(t), w;
2179
- }
2180
- return t;
2181
- }
2182
- function fa(o, e) {
2183
- const t = document.createElement("article");
2184
- t.className = "gengage-chat-product-details-panel";
2185
- const a = o.props?.product ?? o.props;
2186
- if (!a) return t;
2187
- const n = a.images, i = a.imageUrl, s = a.sku;
2188
- if (n && n.length > 1) {
2189
- const m = document.createElement("div");
2190
- m.className = "gengage-chat-product-details-media gengage-chat-product-details-gallery gengage-chat-product-details-img-wrap";
2191
- const x = document.createElement("img");
2192
- x.className = "gengage-chat-product-details-img";
2193
- const y = n.find((z) => G(z));
2194
- y && R(x, "src", y);
2195
- const b = a.name;
2196
- b && (x.alt = b), X(x), m.appendChild(x);
2197
- const A = document.createElement("div");
2198
- A.className = "gengage-chat-product-gallery-thumbs";
2199
- let C = null, L = 0;
2200
- for (let z = 0; z < n.length; z++) {
2201
- const H = n[z];
2202
- if (!H || !G(H)) continue;
2203
- const U = document.createElement("img");
2204
- U.className = "gengage-chat-product-gallery-thumb", z === 0 && (U.classList.add("gengage-chat-product-gallery-thumb--active"), C = U), R(U, "src", H), U.alt = `${b ?? "Product"} ${z + 1}`, U.width = 48, U.height = 48, X(U), U.addEventListener("click", () => {
2205
- R(x, "src", H), C && C.classList.remove("gengage-chat-product-gallery-thumb--active"), U.classList.add("gengage-chat-product-gallery-thumb--active"), C = U, L = z;
2206
- }), A.appendChild(U);
2207
- }
2208
- let B = 0;
2209
- const N = 50;
2210
- if (x.addEventListener(
2211
- "touchstart",
2212
- (z) => {
2213
- B = z.changedTouches[0].clientX;
2214
- },
2215
- { passive: !0 }
2216
- ), x.addEventListener("touchend", (z) => {
2217
- const H = z.changedTouches[0].clientX, U = B - H;
2218
- if (Math.abs(U) < N) return;
2219
- const ne = A.querySelectorAll(".gengage-chat-product-gallery-thumb"), ie = U > 0 ? Math.min(L + 1, ne.length - 1) : Math.max(L - 1, 0);
2220
- ie !== L && ne[ie] && ne[ie].click();
2221
- }), m.appendChild(A), s) {
2222
- const z = document.createElement("button");
2223
- z.className = "gengage-chat-find-similar-pill", z.type = "button", z.textContent = e.i18n?.findSimilarLabel ?? "Benzerlerini Bul", z.addEventListener("click", () => {
2224
- e.onAction({
2225
- title: e.i18n?.findSimilarLabel ?? "Benzerlerini Bul",
2226
- type: "findSimilar",
2227
- payload: { sku: s, ...y ? { image_url: y } : {} }
2228
- });
2229
- }), m.appendChild(z);
2230
- }
2231
- t.appendChild(m);
2232
- } else if (i && G(i)) {
2233
- const m = document.createElement("div");
2234
- m.className = "gengage-chat-product-details-media gengage-chat-product-details-img-wrap";
2235
- const x = document.createElement("img");
2236
- x.className = "gengage-chat-product-details-img", x.loading = "lazy", R(x, "src", i), X(x);
2237
- const y = a.name;
2238
- if (y && (x.alt = y), m.appendChild(x), s) {
2239
- const b = document.createElement("button");
2240
- b.className = "gengage-chat-find-similar-pill", b.type = "button", b.textContent = e.i18n?.findSimilarLabel ?? "Benzerlerini Bul", b.addEventListener("click", () => {
2241
- e.onAction({
2242
- title: e.i18n?.findSimilarLabel ?? "Benzerlerini Bul",
2243
- type: "findSimilar",
2244
- payload: { sku: s, ...i ? { image_url: i } : {} }
2245
- });
2246
- }), m.appendChild(b);
2247
- }
2248
- t.appendChild(m);
2249
- }
2250
- const l = document.createElement("div");
2251
- l.className = "gengage-chat-product-details-content";
2252
- const r = a.name;
2253
- if (r) {
2254
- const m = document.createElement("h3");
2255
- m.className = "gengage-chat-product-details-title", m.textContent = r, l.appendChild(m);
2256
- }
2257
- const c = a.rating, g = a.reviewCount;
2258
- if (typeof c == "number" && Number.isFinite(c)) {
2259
- const m = document.createElement("div");
2260
- if (m.className = "gengage-chat-product-details-rating", m.textContent = `★ ${ye(c).toFixed(1)}`, typeof g == "number" && Number.isFinite(g)) {
2261
- const x = document.createElement("span");
2262
- x.className = "gengage-chat-product-details-review-count", x.textContent = ` (${g})`, m.appendChild(x);
2263
- }
2264
- l.appendChild(m);
2265
- }
2266
- const h = a.price, p = a.originalPrice;
2267
- if (a.price_async === !0) {
2268
- const m = document.createElement("div");
2269
- m.className = "gengage-chat-product-details-price";
2270
- const x = document.createElement("span");
2271
- x.className = "gengage-chat-price-skeleton", m.appendChild(x), l.appendChild(m), setTimeout(() => {
2272
- if (x.parentElement)
2273
- if (h) {
2274
- const y = document.createElement("span");
2275
- y.className = "gengage-chat-product-details-current-price", y.textContent = q(h, e.pricing), x.replaceWith(y);
2276
- } else
2277
- x.remove();
2278
- }, 300);
2279
- } else if (h) {
2280
- const m = document.createElement("div");
2281
- if (m.className = "gengage-chat-product-details-price", p && p !== h) {
2282
- const y = document.createElement("span");
2283
- y.className = "gengage-chat-product-details-original-price", y.textContent = q(p, e.pricing), m.appendChild(y), m.appendChild(document.createTextNode(" "));
2284
- }
2285
- const x = document.createElement("span");
2286
- x.className = "gengage-chat-product-details-current-price", x.textContent = q(h, e.pricing), m.appendChild(x), l.appendChild(m);
2287
- }
2288
- const f = a.inStock;
2289
- if (typeof f == "boolean") {
2290
- const m = document.createElement("div");
2291
- m.className = `gengage-chat-product-details-stock ${f ? "is-in-stock" : "is-out-of-stock"}`, m.textContent = f ? "Stokta var" : "Stokta yok", l.appendChild(m);
2292
- }
2293
- const k = a.promotions;
2294
- if (k && k.length > 0) {
2295
- const m = document.createElement("div");
2296
- m.className = "gengage-chat-product-details-promos";
2297
- for (const x of k) {
2298
- const y = document.createElement("span");
2299
- y.className = "gengage-chat-product-details-promo-badge", y.textContent = x, m.appendChild(y);
2300
- }
2301
- l.appendChild(m);
2302
- }
2303
- const _ = a.variants;
2304
- if (_ && _.length > 0) {
2305
- const m = document.createElement("div");
2306
- m.className = "gengage-chat-product-variants";
2307
- const x = document.createElement("div");
2308
- x.className = "gengage-chat-product-variants-label", x.textContent = e.i18n?.variantsLabel ?? "Varyantlar", m.appendChild(x);
2309
- const y = document.createElement("div");
2310
- y.className = "gengage-chat-product-variants-list";
2311
- for (const b of _) {
2312
- const A = b.name ?? b.variant_name, C = b.sku;
2313
- if (!A && !C) continue;
2314
- const L = document.createElement("button");
2315
- L.className = "gengage-chat-product-variant-btn", L.type = "button";
2316
- const B = A ?? C ?? "", N = b.price;
2317
- N && String(N) !== String(h) ? L.textContent = `${B} - ${q(String(N), e.pricing)}` : L.textContent = B, C && L.addEventListener("click", () => {
2318
- e.onAction({
2319
- title: B,
2320
- type: "launchVariant",
2321
- payload: { sku: C }
2322
- });
2323
- }), y.appendChild(L);
2324
- }
2325
- m.appendChild(y), l.appendChild(m);
2326
- }
2327
- const P = a.sku, S = a.cartCode, T = document.createElement("div");
2328
- T.className = "gengage-chat-product-details-actions";
2329
- const w = o.props?.action;
2330
- if (w) {
2331
- const m = document.createElement("button");
2332
- m.className = "gengage-chat-product-details-cta", m.type = "button", m.textContent = w.title || e.i18n?.productCtaLabel || "Incele", m.addEventListener("click", () => e.onAction(w)), T.appendChild(m);
2333
- } else {
2334
- const m = a.url;
2335
- if (m && G(m)) {
2336
- const x = document.createElement("a");
2337
- x.className = "gengage-chat-product-details-cta", R(x, "href", m), R(x, "target", "_blank"), R(x, "rel", "noopener noreferrer"), x.textContent = e.i18n?.productCtaLabel ?? "Incele", x.addEventListener("click", (y) => {
2338
- e.onProductClick && P && (y.preventDefault(), e.onProductClick({ sku: P, url: m }));
2339
- }), T.appendChild(x);
2340
- }
2341
- }
2342
- if (S && P && f !== !1) {
2343
- const m = ke({
2344
- compact: !1,
2345
- label: e.i18n?.addToCartButton ?? "Sepete Ekle",
2346
- onSubmit: (x) => {
2347
- e.onAction({
2348
- title: e.i18n?.addToCartButton ?? "Sepete Ekle",
2349
- type: "addToCart",
2350
- payload: { sku: P, cartCode: S, quantity: x }
2351
- });
2352
- }
2353
- });
2354
- m.classList.add("gengage-chat-product-details-atc-stepper"), T.appendChild(m);
2355
- }
2356
- const u = a.url;
2357
- if (u && G(u)) {
2358
- let m = function(L, B) {
2359
- const N = document.createElementNS(A, "circle");
2360
- N.setAttribute("cx", L), N.setAttribute("cy", B), N.setAttribute("r", "3"), C.appendChild(N);
2361
- }, x = function(L, B, N, z) {
2362
- const H = document.createElementNS(A, "line");
2363
- H.setAttribute("x1", L), H.setAttribute("y1", B), H.setAttribute("x2", N), H.setAttribute("y2", z), C.appendChild(H);
2364
- };
2365
- const y = document.createElement("button");
2366
- y.className = "gengage-chat-product-details-share", y.type = "button";
2367
- const b = e.i18n?.shareButton ?? "Paylaş";
2368
- y.title = b, y.setAttribute("aria-label", b);
2369
- const A = "http://www.w3.org/2000/svg", C = document.createElementNS(A, "svg");
2370
- C.setAttribute("width", "18"), C.setAttribute("height", "18"), C.setAttribute("viewBox", "0 0 24 24"), C.setAttribute("fill", "none"), C.setAttribute("stroke", "currentColor"), C.setAttribute("stroke-width", "2"), C.setAttribute("stroke-linecap", "round"), C.setAttribute("stroke-linejoin", "round"), m("18", "5"), m("6", "12"), m("18", "19"), x("8.59", "13.51", "15.42", "17.49"), x("15.41", "6.51", "8.59", "10.49"), y.appendChild(C), y.addEventListener("click", async () => {
2371
- const L = a.name;
2372
- try {
2373
- navigator.share ? await navigator.share({ title: L ?? "", url: u }) : navigator.clipboard && (await navigator.clipboard.writeText(u), y.classList.add("gengage-chat-product-details-share--copied"), setTimeout(() => y.classList.remove("gengage-chat-product-details-share--copied"), 1500));
2374
- } catch {
2375
- }
2376
- }), T.appendChild(y);
2377
- }
2378
- T.childElementCount > 0 && l.appendChild(T), t.appendChild(l);
2379
- const E = a.description, I = a.specifications;
2380
- return (E || I) && t.appendChild(ba(E, I, e)), t;
2381
- }
2382
- function ba(o, e, t) {
2383
- const a = document.createElement("div");
2384
- a.className = "gengage-chat-product-detail-tabs";
2385
- const n = document.createElement("div");
2386
- n.className = "gengage-chat-product-detail-tab-bar";
2387
- const i = [];
2388
- if (o) {
2389
- const l = document.createElement("button");
2390
- l.className = "gengage-chat-product-detail-tab gengage-chat-product-detail-tab--active", l.type = "button", l.textContent = t.i18n?.productInfoTab ?? "Ürün Bilgileri", n.appendChild(l);
2391
- const r = document.createElement("div");
2392
- r.className = "gengage-chat-product-detail-tab-panel", r.textContent = o, i.push(r);
2393
- }
2394
- if (e) {
2395
- const l = document.createElement("button");
2396
- l.className = `gengage-chat-product-detail-tab${o ? "" : " gengage-chat-product-detail-tab--active"}`, l.type = "button", l.textContent = t.i18n?.specificationsTab ?? "Teknik Özellikler", n.appendChild(l);
2397
- const r = document.createElement("div");
2398
- r.className = "gengage-chat-product-detail-tab-panel", o && (r.style.display = "none");
2399
- const c = document.createElement("table");
2400
- c.className = "gengage-chat-product-specs-table";
2401
- const g = Array.isArray(e) ? e : Object.entries(e).map(([h, p]) => ({ key: h, value: p }));
2402
- for (const h of g) {
2403
- const p = document.createElement("tr"), d = document.createElement("td");
2404
- d.className = "gengage-chat-product-specs-key", d.textContent = h.key;
2405
- const f = document.createElement("td");
2406
- f.className = "gengage-chat-product-specs-value", f.textContent = h.value, p.appendChild(d), p.appendChild(f), c.appendChild(p);
2407
- }
2408
- r.appendChild(c), i.push(r);
2409
- }
2410
- const s = n.querySelectorAll(".gengage-chat-product-detail-tab");
2411
- s.forEach((l, r) => {
2412
- l.addEventListener("click", () => {
2413
- s.forEach((c) => c.classList.remove("gengage-chat-product-detail-tab--active")), l.classList.add("gengage-chat-product-detail-tab--active"), i.forEach((c, g) => {
2414
- c.style.display = g === r ? "" : "none";
2415
- });
2416
- });
2417
- }), a.appendChild(n);
2418
- for (const l of i) a.appendChild(l);
2419
- return a;
2420
- }
2421
- function Pe(o, e, t) {
2422
- if (!t || t.type === "related") return o;
2423
- const a = o.map((n) => {
2424
- const s = e.elements[n]?.props?.product, l = s ? Number(s.price) : NaN;
2425
- return { id: n, price: Number.isFinite(l) ? l : 1 / 0 };
2426
- });
2427
- return a.sort((n, i) => n.price === 1 / 0 && i.price === 1 / 0 ? 0 : n.price === 1 / 0 ? 1 : i.price === 1 / 0 ? -1 : t.direction === "desc" ? i.price - n.price : n.price - i.price), a.map((n) => n.id);
2428
- }
2429
- function xa(o, e, t, a) {
2430
- const n = Pe(e, t, a), i = /* @__PURE__ */ new Map();
2431
- for (const s of Array.from(o.children)) {
2432
- const l = s.dataset.elementId;
2433
- l && i.set(l, s);
2434
- }
2435
- for (const s of n) {
2436
- const l = i.get(s);
2437
- l && o.appendChild(l);
2438
- }
2439
- }
2440
- function va(o, e, t, a) {
2441
- const n = document.createElement("div");
2442
- n.className = "gengage-chat-product-grid-wrapper";
2443
- const i = o.children ?? [];
2444
- if (i.length > 1 && a?.onSortChange) {
2445
- const c = document.createElement("div");
2446
- c.className = "gengage-chat-product-sort-toolbar";
2447
- const g = a.productSort ?? { type: "related" }, h = [
2448
- { label: a.i18n?.sortRelated ?? "Önerilen", sortState: { type: "related" } },
2449
- { label: a.i18n?.sortPriceAsc ?? "Fiyat ↑", sortState: { type: "price", direction: "asc" } },
2450
- { label: a.i18n?.sortPriceDesc ?? "Fiyat ↓", sortState: { type: "price", direction: "desc" } }
2451
- ];
2452
- for (const p of h) {
2453
- const d = document.createElement("button");
2454
- d.className = "gengage-chat-product-sort-btn", d.type = "button", g.type === p.sortState.type && g.direction === p.sortState.direction && d.classList.add("gengage-chat-product-sort-btn--active"), d.textContent = p.label, d.addEventListener("click", () => {
2455
- a.onSortChange?.(p.sortState), xa(s, i, e, p.sortState), c.querySelectorAll(".gengage-chat-product-sort-btn").forEach((k) => k.classList.remove("gengage-chat-product-sort-btn--active")), d.classList.add("gengage-chat-product-sort-btn--active");
2456
- }), c.appendChild(d);
2457
- }
2458
- if (a.onToggleComparisonSku) {
2459
- const p = document.createElement("div");
2460
- p.className = "gengage-chat-product-sort-separator", c.appendChild(p);
2461
- const d = document.createElement("button");
2462
- d.className = "gengage-chat-comparison-toggle-btn", d.type = "button", a.comparisonSelectMode && d.classList.add("gengage-chat-comparison-toggle-btn--active"), d.textContent = a.i18n?.compareSelected ?? "Karşılaştır", d.addEventListener("click", () => {
2463
- a.onToggleComparisonSku?.("");
2464
- }), c.appendChild(d);
2465
- }
2466
- n.appendChild(c);
2467
- }
2468
- const s = document.createElement("div");
2469
- s.className = "gengage-chat-product-grid";
2470
- const l = Pe(i, e, a?.productSort);
2471
- for (const c of l) {
2472
- if (!e.elements[c]) continue;
2473
- const g = t(c);
2474
- g && (g.dataset.elementId = c, s.appendChild(g));
2475
- }
2476
- if (Ie() && s.classList.add("gengage-chat-product-grid--mobile"), n.appendChild(s), o.props?.endOfList !== !0 && i.length > 0) {
2477
- const c = document.createElement("button");
2478
- c.className = "gengage-chat-product-grid-view-more", c.type = "button", c.textContent = a?.i18n?.viewMoreLabel ?? "Daha Fazla Göster", c.addEventListener("click", () => {
2479
- a?.onAction({ title: "More", type: "moreProductList", payload: {} });
2480
- }), n.appendChild(c);
2481
- }
2482
- if (a?.comparisonSelectMode && a.comparisonSelectedSkus && a.comparisonSelectedSkus.length >= 2) {
2483
- const c = oa(a.comparisonSelectedSkus, a);
2484
- n.appendChild(c);
2485
- }
2486
- return n;
2487
- }
2488
- function wa(o, e) {
2489
- const t = o.props ?? {}, a = t.keyDifferencesHtml, n = t.recommended, i = t.products ?? [], s = t.attributes ?? [], l = t.highlights ?? [], r = t.specialCases, c = t.recommendedText, g = t.winnerHits, h = t.productActions;
2490
- if (!n)
2491
- return document.createElement("div");
2492
- const p = {
2493
- recommended: n,
2494
- products: i,
2495
- attributes: s,
2496
- highlights: l,
2497
- specialCases: r,
2498
- onProductClick: (f) => {
2499
- e.onProductClick?.({ sku: f, url: "" });
2500
- },
2501
- pricing: e.pricing
2502
- };
2503
- c !== void 0 && (p.recommendedText = c), g !== void 0 && (p.winnerHits = g), h !== void 0 && (p.productActions = h), a !== void 0 && (p.keyDifferencesHtml = a), e.i18n && (p.i18n = {
2504
- comparisonHeading: e.i18n.panelTitleComparisonResults,
2505
- recommendedChoiceLabel: e.i18n.recommendedChoiceLabel,
2506
- highlightsLabel: e.i18n.highlightsLabel,
2507
- keyDifferencesLabel: e.i18n.keyDifferencesLabel,
2508
- specialCasesLabel: e.i18n.specialCasesLabel,
2509
- addToCartButton: e.i18n.addToCartButton
2510
- });
2511
- const d = Gt(p);
2512
- return Ie() && d.classList.add("gengage-chat-comparison--mobile"), d;
2513
- }
2514
- function _a(o) {
2515
- const e = document.createElement("hr");
2516
- e.className = "gengage-chat-divider";
2517
- const t = o.props?.label;
2518
- if (t) {
2519
- const a = document.createElement("div");
2520
- a.className = "gengage-chat-divider-wrapper";
2521
- const n = document.createElement("span");
2522
- return n.className = "gengage-chat-divider-label", n.textContent = t, a.appendChild(e), a.appendChild(n), a;
2523
- }
2524
- return e;
2525
- }
2526
- const ya = /* @__PURE__ */ new Set([
2527
- "P",
2528
- "DIV",
2529
- "H1",
2530
- "H2",
2531
- "H3",
2532
- "H4",
2533
- "H5",
2534
- "H6",
2535
- "LI",
2536
- "UL",
2537
- "OL",
2538
- "BLOCKQUOTE",
2539
- "PRE",
2540
- "TABLE",
2541
- "SECTION",
2542
- "HR",
2543
- "FIGURE",
2544
- "FIGCAPTION",
2545
- "DL",
2546
- "DT",
2547
- "DD"
2548
- ]);
2549
- function ka(o) {
2550
- const e = [];
2551
- let t = [];
2552
- for (const a of o)
2553
- a.nodeType === Node.ELEMENT_NODE && ya.has(a.tagName) ? (t.length > 0 && (e.push(t), t = []), e.push([a])) : t.push(a);
2554
- return t.length > 0 && e.push(t), e;
2555
- }
2556
- function Ca(o) {
2557
- for (const e of o)
2558
- for (const t of e)
2559
- if (t.nodeType === Node.ELEMENT_NODE && (t.tagName === "TABLE" || t.querySelector?.("table")))
2560
- return !0;
2561
- return !1;
2562
- }
2563
- function Ea() {
2564
- return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
2565
- }
2566
- function Sa(o) {
2567
- const { container: e, html: t, delayMs: a = 30, onTick: n, onComplete: i } = o, s = document.createElement("template");
2568
- s.innerHTML = t;
2569
- const l = ka(s.content.childNodes);
2570
- if (Ea() || l.length <= 1 || Ca(l))
2571
- return e.innerHTML = t, i?.(), { complete() {
2572
- }, cancel() {
2573
- }, isRunning: !1 };
2574
- e.innerHTML = "";
2575
- let r = 0, c = null, g = !0;
2576
- function h() {
2577
- if (!g || r >= l.length) {
2578
- g = !1, i?.();
2579
- return;
2580
- }
2581
- const p = l[r], d = document.createElement("span");
2582
- d.className = "gengage-chat-typewriter-block";
2583
- for (const f of p)
2584
- d.appendChild(f.cloneNode(!0));
2585
- e.appendChild(d), r++, n?.(), r < l.length ? c = setTimeout(h, a) : (g = !1, i?.());
2586
- }
2587
- return h(), {
2588
- complete() {
2589
- g && (c !== null && clearTimeout(c), g = !1, e.innerHTML = t, i?.());
2590
- },
2591
- cancel() {
2592
- c !== null && clearTimeout(c), g = !1;
2593
- },
2594
- get isRunning() {
2595
- return g;
2596
- }
2597
- };
2598
- }
2599
- function he(o) {
2600
- return o !== void 0 && /[\p{L}\p{N}_]/u.test(o);
2601
- }
2602
- function Ta(o) {
2603
- const { container: e, mentions: t, onProductClick: a } = o;
2604
- if (t.length === 0) return;
2605
- const n = /* @__PURE__ */ new Map();
2606
- for (const i of t)
2607
- i.short_name.length !== 0 && n.set(i.short_name.toLowerCase(), i);
2608
- if (n.size !== 0)
2609
- for (const [i, s] of n) {
2610
- const l = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
2611
- let r = l.nextNode(), c = !1;
2612
- for (; r && !c; ) {
2613
- const g = r.textContent ?? "", h = g.toLowerCase().indexOf(i);
2614
- if (h === -1) {
2615
- r = l.nextNode();
2616
- continue;
2617
- }
2618
- const p = h > 0 ? g[h - 1] : void 0, d = g[h + s.short_name.length];
2619
- if (he(p) || he(d)) {
2620
- r = l.nextNode();
2621
- continue;
2622
- }
2623
- const f = g.slice(0, h), k = g.slice(h, h + s.short_name.length), _ = g.slice(h + s.short_name.length), P = r.parentNode;
2624
- if (!P) {
2625
- r = l.nextNode();
2626
- continue;
2627
- }
2628
- const S = document.createElement("a");
2629
- S.className = "gengage-product-mention", S.textContent = k, S.href = "#", S.addEventListener("click", (T) => {
2630
- T.preventDefault(), a(s.sku);
2631
- }), f && P.insertBefore(document.createTextNode(f), r), P.insertBefore(S, r), _ && P.insertBefore(document.createTextNode(_), r), P.removeChild(r), c = !0;
2632
- }
2633
- }
2634
- }
2635
- const Ia = /* @__PURE__ */ new Set(["search", "info", "review", "similar"]), La = /* @__PURE__ */ new Set([
2636
- "quickAnswer",
2637
- "reviewSummary",
2638
- "searchDiscovery",
2639
- "launchDiscovery",
2640
- "exploreTogetherV2"
2641
- ]);
2642
- function Na(o) {
2643
- return !!(o.icon && Ia.has(o.icon) || o.action?.type && La.has(o.action.type));
2644
- }
2645
- const Ae = "gengage_choice_prompter_dismissed";
2646
- function Pa(o) {
2647
- const e = document.createElement("div");
2648
- e.className = "gengage-chat-choice-prompter";
2649
- const t = document.createElement("div");
2650
- t.className = "gengage-chat-choice-prompter-heading", t.textContent = o.heading, e.appendChild(t);
2651
- const a = document.createElement("div");
2652
- a.className = "gengage-chat-choice-prompter-suggestion", a.textContent = o.suggestion, e.appendChild(a);
2653
- const n = document.createElement("button");
2654
- n.type = "button", n.className = "gengage-chat-choice-prompter-cta", n.textContent = o.ctaLabel, n.addEventListener("click", () => {
2655
- ue(), e.remove(), o.onCtaClick();
2656
- }), e.appendChild(n);
2657
- const i = document.createElement("button");
2658
- return i.type = "button", i.className = "gengage-chat-choice-prompter-dismiss", i.textContent = "×", i.setAttribute("aria-label", "Dismiss"), i.addEventListener("click", () => {
2659
- ue(), e.remove(), o.onDismiss?.();
2660
- }), e.appendChild(i), e;
2661
- }
2662
- function Aa() {
2663
- try {
2664
- return sessionStorage.getItem(Ae) === "1";
2665
- } catch {
2666
- return !1;
2667
- }
2668
- }
2669
- function ue() {
2670
- try {
2671
- sessionStorage.setItem(Ae, "1");
2672
- } catch {
2673
- }
2674
- }
2675
- const Ma = "gengage_assistant", Ba = 3, Y = "sessions", F = "context", V = "payload", O = "favorites";
2676
- function ee(o) {
2677
- return new Promise((e, t) => {
2678
- o.onsuccess = () => e(o.result), o.onerror = () => t(o.error);
2679
- });
2680
- }
2681
- function Z(o) {
2682
- return new Promise((e, t) => {
2683
- o.oncomplete = () => e(), o.onerror = () => t(o.error), o.onabort = () => t(o.error ?? new DOMException("Transaction aborted"));
2684
- });
2685
- }
2686
- class za {
2687
- constructor(e = Ma, t = Ba) {
2688
- this._db = null, this._dbName = e, this._version = t;
2689
- }
2690
- // -------------------------------------------------------------------------
2691
- // Lifecycle
2692
- // -------------------------------------------------------------------------
2693
- async open() {
2694
- return this._db ? this._db : new Promise((e, t) => {
2695
- const a = indexedDB.open(this._dbName, this._version);
2696
- a.onupgradeneeded = (n) => {
2697
- const i = a.result, s = n.oldVersion;
2698
- s < 1 && (i.createObjectStore(Y, { keyPath: ["userId", "appId", "sessionId"] }), i.createObjectStore(F, { keyPath: ["sessionId", "threadId"] }), i.createObjectStore(V, {
2699
- keyPath: ["threadId", "messageId"]
2700
- }).createIndex("threadId", "threadId", { unique: !1 }), i.createObjectStore(O, { keyPath: ["userId", "appId", "sku"] })), s >= 1 && s < 2 && (i.objectStoreNames.contains(Y) && i.deleteObjectStore(Y), i.objectStoreNames.contains(V) && i.deleteObjectStore(V), i.createObjectStore(Y, { keyPath: ["userId", "appId", "sessionId"] }), i.createObjectStore(V, {
2701
- keyPath: ["threadId", "messageId"]
2702
- }).createIndex("threadId", "threadId", { unique: !1 }), i.objectStoreNames.contains(F) || i.createObjectStore(F, { keyPath: ["sessionId", "threadId"] })), s < 3 && (i.objectStoreNames.contains(O) || i.createObjectStore(O, { keyPath: ["userId", "appId", "sku"] }));
2703
- }, a.onsuccess = () => {
2704
- this._db = a.result, e(this._db);
2705
- }, a.onerror = () => t(a.error);
2706
- });
2707
- }
2708
- close() {
2709
- this._db?.close(), this._db = null;
2710
- }
2711
- // -------------------------------------------------------------------------
2712
- // Sessions
2713
- // -------------------------------------------------------------------------
2714
- async saveSession(e) {
2715
- const a = this._requireDb().transaction(Y, "readwrite");
2716
- a.objectStore(Y).put(e), await Z(a);
2717
- }
2718
- async loadSession(e, t, a) {
2719
- const i = this._requireDb().transaction(Y, "readonly");
2720
- return await ee(i.objectStore(Y).get([e, t, a])) ?? null;
2721
- }
2722
- // -------------------------------------------------------------------------
2723
- // Context (compound key: [sessionId, threadId])
2724
- // -------------------------------------------------------------------------
2725
- async saveContext(e) {
2726
- const a = this._requireDb().transaction(F, "readwrite");
2727
- a.objectStore(F).put(e), await Z(a);
2728
- }
2729
- async loadContext(e, t) {
2730
- const n = this._requireDb().transaction(F, "readonly");
2731
- return await ee(n.objectStore(F).get([e, t])) ?? null;
2732
- }
2733
- /**
2734
- * Delete all context entries for a session whose threadId is lexicographically
2735
- * greater than the given threadId. Used during rollback to prune future branches.
2736
- *
2737
- * Thread IDs are UUIDv7 (lexicographically sortable by time), so string
2738
- * comparison is sufficient.
2739
- */
2740
- async deleteContextsAfterThread(e, t) {
2741
- const n = this._requireDb().transaction(F, "readwrite"), s = n.objectStore(F).openCursor();
2742
- await new Promise((l, r) => {
2743
- s.onsuccess = () => {
2744
- const c = s.result;
2745
- if (!c) {
2746
- l();
2747
- return;
2748
- }
2749
- const g = c.value;
2750
- if (g.sessionId === e && g.threadId > t)
2751
- try {
2752
- c.delete();
2753
- } catch {
2754
- }
2755
- c.continue();
2756
- }, s.onerror = () => r(s.error);
2757
- }), await Z(n);
2758
- }
2759
- /**
2760
- * Load the most recent context for a session (latest threadId).
2761
- * Uses lexicographic ordering of UUIDv7 threadIds for chronological sort.
2762
- */
2763
- async loadLatestContext(e) {
2764
- const n = this._requireDb().transaction(F, "readonly").objectStore(F), i = IDBKeyRange.bound([e, ""], [e, "￿"]);
2765
- return new Promise((s, l) => {
2766
- const r = n.openCursor(i, "prev");
2767
- r.onsuccess = () => {
2768
- const c = r.result;
2769
- s(c ? c.value : null);
2770
- }, r.onerror = () => l(r.error);
2771
- });
2772
- }
2773
- // -------------------------------------------------------------------------
2774
- // Payload
2775
- // -------------------------------------------------------------------------
2776
- async savePayload(e) {
2777
- const a = this._requireDb().transaction(V, "readwrite");
2778
- a.objectStore(V).put(e), await Z(a);
2779
- }
2780
- async loadPayload(e, t) {
2781
- const n = this._requireDb().transaction(V, "readonly");
2782
- return await ee(n.objectStore(V).get([e, t])) ?? null;
2783
- }
2784
- async loadPayloadsByThread(e) {
2785
- const n = this._requireDb().transaction(V, "readonly").objectStore(V).index("threadId"), i = [];
2786
- return new Promise((s, l) => {
2787
- const r = n.openCursor(IDBKeyRange.only(e));
2788
- r.onsuccess = () => {
2789
- const c = r.result;
2790
- if (!c) {
2791
- s(i);
2792
- return;
2793
- }
2794
- i.push(c.value), c.continue();
2795
- }, r.onerror = () => l(r.error);
2796
- });
2797
- }
2798
- // -------------------------------------------------------------------------
2799
- // Favorites
2800
- // -------------------------------------------------------------------------
2801
- async saveFavorite(e) {
2802
- const a = this._requireDb().transaction(O, "readwrite");
2803
- a.objectStore(O).put(e), await Z(a);
2804
- }
2805
- async removeFavorite(e, t, a) {
2806
- const i = this._requireDb().transaction(O, "readwrite");
2807
- i.objectStore(O).delete([e, t, a]), await Z(i);
2808
- }
2809
- async loadFavorites(e, t) {
2810
- const n = this._requireDb().transaction(O, "readonly");
2811
- return (await ee(n.objectStore(O).getAll())).filter((s) => s.userId === e && s.appId === t);
2812
- }
2813
- async isFavorite(e, t, a) {
2814
- const i = this._requireDb().transaction(O, "readonly");
2815
- return await ee(i.objectStore(O).get([e, t, a])) !== void 0;
2816
- }
2817
- // -------------------------------------------------------------------------
2818
- // Internal
2819
- // -------------------------------------------------------------------------
2820
- _requireDb() {
2821
- if (!this._db)
2822
- throw new Error("GengageIndexedDB: database not open. Call open() first.");
2823
- return this._db;
2824
- }
2825
- }
2826
- const Da = [
2827
- "comparisonTable",
2828
- "groupList",
2829
- "productDetailsSimilars",
2830
- "productList"
2831
- ];
2832
- class Ra {
2833
- constructor(e) {
2834
- this._lockCount = 1, this._hiddenByUser = !1, this._lastPanelContentType = null, this._chatShown = !1, this._isFavoritesMode = !1, this._lastExtended = !1, this._onChange = e.onChange;
2835
- const t = new Set(Da);
2836
- e.productDetailsInPanel && t.add("productDetails"), this._panelContentTypes = t;
2837
- }
2838
- get isExtended() {
2839
- return this._lockCount === 0 && !this._hiddenByUser && !this._isFavoritesMode && this._lastPanelContentType !== null && this._panelContentTypes.has(this._lastPanelContentType) && this._chatShown;
2840
- }
2841
- unlock() {
2842
- this._lockCount > 0 && this._lockCount--, this._checkStateChange();
2843
- }
2844
- lock() {
2845
- this._lockCount++, this._checkStateChange();
2846
- }
2847
- setHiddenByUser(e) {
2848
- this._hiddenByUser = e, this._checkStateChange();
2849
- }
2850
- setChatShown(e) {
2851
- this._chatShown = e, this._checkStateChange();
2852
- }
2853
- setFavoritesMode(e) {
2854
- this._isFavoritesMode = e, this._checkStateChange();
2855
- }
2856
- setPanelContentType(e) {
2857
- this._lastPanelContentType = e, this._checkStateChange();
2858
- }
2859
- _checkStateChange() {
2860
- const e = this.isExtended;
2861
- e !== this._lastExtended && (this._lastExtended = e, this._onChange(e));
2862
- }
2863
- }
2864
- class Ua {
2865
- constructor(e) {
2866
- this.deps = e, this.snapshots = /* @__PURE__ */ new Map(), this.snapshotTypes = /* @__PURE__ */ new Map(), this.activePanelMessageId = null, this.currentType = null, this.threads = [], this.lastActionType = null;
2867
- }
2868
- /**
2869
- * Deep-clone the current panel content (excluding topbar/thumbnails) and store
2870
- * it keyed by message ID. Called when a stream completes so panel content can
2871
- * be restored later without duplicating the topbar.
2872
- */
2873
- snapshotForMessage(e) {
2874
- const t = this.deps.drawer();
2875
- if (!t?.hasPanelContent() || t.isPanelLoading()) return;
2876
- const a = t.getPanelContentElement();
2877
- if (!a) return;
2878
- const n = a.cloneNode(!0);
2879
- this.snapshots.set(e, n), this.currentType && this.snapshotTypes.set(e, this.currentType);
2880
- }
2881
- /**
2882
- * Attach a click handler to a bot message bubble so clicking it restores
2883
- * the panel content that was active when that message was received.
2884
- */
2885
- attachClickHandler(e) {
2886
- const a = this.deps.shadow()?.querySelector(`[data-message-id="${CSS.escape(e)}"]`);
2887
- a && (a.style.cursor = "pointer", a.addEventListener("click", () => this.restoreForMessage(e)));
2888
- }
2889
- /**
2890
- * Restore the panel content snapshot associated with a given message ID.
2891
- * Highlights the active message and de-highlights the previous one.
2892
- * Also restores the panel topbar title for the snapshot's component type.
2893
- * Returns true if the snapshot was found and restored.
2894
- */
2895
- restoreForMessage(e) {
2896
- const t = this.snapshots.get(e);
2897
- if (!t) return !1;
2898
- const a = this.deps.shadow(), n = this.deps.drawer();
2899
- this.activePanelMessageId && a?.querySelector(`[data-message-id="${CSS.escape(this.activePanelMessageId)}"]`)?.classList.remove("gengage-chat-bubble--active"), a?.querySelector(`[data-message-id="${CSS.escape(e)}"]`)?.classList.add("gengage-chat-bubble--active"), this.activePanelMessageId = e, n?.setPanelContent(t.cloneNode(!0));
2900
- const s = this.snapshotTypes.get(e);
2901
- return s && (this.currentType = s, this.updateTopBar(s)), !0;
2902
- }
2903
- /**
2904
- * Send maximize-pdp / minify-pdp bridge messages with production-matching delays.
2905
- * Called by the extended mode manager when panel extension state changes.
2906
- */
2907
- notifyExtension(e) {
2908
- const t = this.deps.bridge();
2909
- e ? setTimeout(() => t?.send("maximize-pdp", {}), 350) : setTimeout(() => t?.send("minify-pdp", {}), 200);
2910
- }
2911
- /**
2912
- * Derive panel title from UISpec root element type using i18n strings.
2913
- * When the backend provides a `panelTitle` prop, it takes precedence.
2914
- */
2915
- titleForComponent(e, t) {
2916
- if (t) return t;
2917
- const a = this.deps.i18n();
2918
- switch (e) {
2919
- case "ProductDetailsPanel":
2920
- return a.panelTitleProductDetails;
2921
- case "ProductGrid":
2922
- return me(this.lastActionType) ? a.panelTitleSearchResults : a.panelTitleSimilarProducts;
2923
- case "ComparisonTable":
2924
- return a.panelTitleComparisonResults;
2925
- case "AIGroupingCards":
2926
- return a.panelTitleCategories;
2927
- default:
2928
- return "";
2929
- }
2930
- }
2931
- /**
2932
- * Update the panel top bar navigation state and title.
2933
- * When the backend provides a `panelTitle`, it takes precedence over i18n defaults.
2934
- */
2935
- updateTopBar(e, t) {
2936
- const a = this.deps.currentThreadId();
2937
- if (!a) return;
2938
- const n = this.threads.indexOf(a), i = n > 0, s = n >= 0 && n < this.threads.length - 1, l = this.titleForComponent(e, t);
2939
- this.deps.drawer()?.updatePanelTopBar(i, s, l);
2940
- }
2941
- /**
2942
- * Set panel topbar title during loading (before actual panel content arrives).
2943
- * Maps backend pending types to the same i18n titles used for final content.
2944
- */
2945
- updateTopBarForLoading(e) {
2946
- const t = this.deps.i18n(), n = {
2947
- productDetails: t.panelTitleProductDetails,
2948
- productList: me(this.lastActionType) ? t.panelTitleSearchResults : t.panelTitleSimilarProducts,
2949
- comparisonTable: t.panelTitleComparisonResults,
2950
- groupList: t.panelTitleCategories
2951
- }[e] ?? "";
2952
- if (n) {
2953
- const i = this.deps.currentThreadId(), s = i ? this.threads.indexOf(i) : -1, l = s > 0, r = s >= 0 && s < this.threads.length - 1;
2954
- this.deps.drawer()?.updatePanelTopBar(l, r, n);
2955
- }
2956
- }
2957
- /**
2958
- * Map UISpec component types to PanelContentType for the extended mode manager.
2959
- */
2960
- updateExtendedMode(e) {
2961
- const a = {
2962
- ComparisonTable: "comparisonTable",
2963
- AIGroupingCards: "groupList",
2964
- ProductDetailsPanel: "productDetails",
2965
- ProductGrid: "productList"
2966
- }[e] ?? null;
2967
- this.deps.extendedModeManager()?.setPanelContentType(a);
2968
- }
2969
- /** Navigate to the previous panel thread. */
2970
- navigateBack() {
2971
- const e = this.deps.currentThreadId();
2972
- if (!e) return;
2973
- const t = this.threads.indexOf(e);
2974
- if (t > 0) {
2975
- const a = this.threads[t - 1];
2976
- a && this.deps.rollbackToThread(a);
2977
- }
2978
- }
2979
- /** Navigate to the next panel thread. */
2980
- navigateForward() {
2981
- const e = this.deps.currentThreadId();
2982
- if (!e) return;
2983
- const t = this.threads.indexOf(e);
2984
- if (t >= 0 && t < this.threads.length - 1) {
2985
- const a = this.threads[t + 1];
2986
- a && this.deps.rollbackToThread(a);
2987
- }
2988
- }
2989
- /**
2990
- * Panel route shaping:
2991
- * - product details => expanded LHS panel (`ProductDetailsPanel`)
2992
- * - all other panel-routed specs keep their original component types
2993
- */
2994
- toPanelSpec(e) {
2995
- const t = e.elements[e.root];
2996
- if (!t || t.type !== "ProductCard") return e;
2997
- const a = {
2998
- ...t,
2999
- type: "ProductDetailsPanel"
3000
- };
3001
- return {
3002
- root: e.root,
3003
- elements: {
3004
- ...e.elements,
3005
- [e.root]: a
3006
- }
3007
- };
3008
- }
3009
- destroy() {
3010
- this.snapshots.clear(), this.snapshotTypes.clear(), this.activePanelMessageId = null, this.currentType = null, this.threads = [];
3011
- }
3012
- }
3013
- function me(o) {
3014
- return o === "user_message" || o === "inputText";
3015
- }
3016
- class fe {
3017
- constructor(e) {
3018
- this.favoritedSkus = /* @__PURE__ */ new Set(), this._db = e;
3019
- }
3020
- get db() {
3021
- return this._db;
3022
- }
3023
- set db(e) {
3024
- this._db = e;
3025
- }
3026
- /**
3027
- * Persist current session state to IndexedDB.
3028
- * Called after each stream completion (onDone). Non-fatal on failure.
3029
- */
3030
- async persist(e) {
3031
- if (!this._db) return;
3032
- const t = e.messages.map((n) => {
3033
- const i = {
3034
- id: n.id,
3035
- role: n.role,
3036
- timestamp: n.timestamp,
3037
- status: n.status === "streaming" ? "done" : n.status
3038
- };
3039
- return n.threadId !== void 0 && (i.threadId = n.threadId), n.content !== void 0 && (i.content = n.content), n.silent && (i.silent = !0), i;
3040
- }), a = {};
3041
- for (const [n, i] of e.panelSnapshots)
3042
- i.querySelector(".gengage-chat-panel-skeleton") || (a[n] = i.innerHTML);
3043
- await this._db.saveSession({
3044
- userId: e.userId,
3045
- appId: e.appId,
3046
- sessionId: e.sessionId,
3047
- messages: t,
3048
- currentThreadId: e.currentThreadId,
3049
- lastThreadId: e.lastThreadId,
3050
- createdAt: e.chatCreatedAt,
3051
- panelThreads: e.panelThreads.length > 0 ? e.panelThreads : void 0,
3052
- thumbnailEntries: e.thumbnailEntries.length > 0 ? e.thumbnailEntries : void 0,
3053
- panelSnapshotHtml: Object.keys(a).length > 0 ? a : void 0,
3054
- sku: e.sku
3055
- }), e.lastBackendContext && e.currentThreadId && await this._db.saveContext({
3056
- sessionId: e.sessionId,
3057
- threadId: e.currentThreadId,
3058
- context: e.lastBackendContext
3059
- });
3060
- for (const n of e.messages)
3061
- n.uiSpec && n.threadId && await this._db.savePayload({
3062
- threadId: n.threadId,
3063
- messageId: n.id,
3064
- uiSpec: n.uiSpec
3065
- });
3066
- }
3067
- /**
3068
- * Persist session to IndexedDB, then navigate to the URL.
3069
- * Sends an 'openURLInNewTab' bridge message so the host page can intercept
3070
- * (e.g. for SPA routing), then navigates directly as fallback.
3071
- *
3072
- * Legacy compatibility: the prior engine navigated via window.location.href
3073
- * after posting saveSessionAndOpenURL to the iframe. The clean-room runs in
3074
- * the same window (Shadow DOM, not iframe), so it navigates directly.
3075
- */
3076
- async saveAndOpenURL(e, t, a) {
3077
- try {
3078
- await t();
3079
- } catch {
3080
- }
3081
- a?.send("openURLInNewTab", { url: e }), window.location.href = e;
3082
- }
3083
- /**
3084
- * Load a UISpec payload from IndexedDB with retry logic.
3085
- * Returns null if not found or all retries fail.
3086
- */
3087
- async loadPayload(e, t) {
3088
- if (!this._db) return null;
3089
- for (let a = 0; a < 3; a++) {
3090
- try {
3091
- const n = await this._db.loadPayload(e, t);
3092
- if (n) return n.uiSpec;
3093
- } catch {
3094
- }
3095
- a < 2 && await new Promise((n) => setTimeout(n, 100));
3096
- }
3097
- return null;
3098
- }
3099
- /**
3100
- * Load favorited SKUs from IDB into the in-memory set.
3101
- */
3102
- async loadFavorites(e, t) {
3103
- if (this._db)
3104
- try {
3105
- const a = await this._db.loadFavorites(e, t);
3106
- for (const n of a) this.favoritedSkus.add(n.sku);
3107
- } catch {
3108
- }
3109
- }
3110
- /**
3111
- * Toggle a product's favorited state in IDB and in-memory set.
3112
- */
3113
- async toggleFavorite(e, t, a, n) {
3114
- this._db && (this.favoritedSkus.has(a) ? (this.favoritedSkus.delete(a), await this._db.removeFavorite(e, t, a)) : (this.favoritedSkus.add(a), await this._db.saveFavorite({
3115
- userId: e,
3116
- appId: t,
3117
- sku: a,
3118
- name: n.name,
3119
- imageUrl: n.imageUrl,
3120
- price: n.price,
3121
- savedAt: (/* @__PURE__ */ new Date()).toISOString()
3122
- })));
3123
- }
3124
- close() {
3125
- this._db?.close(), this._db = null;
3126
- }
3127
- }
3128
- const Me = "gengage_kvkk_shown", qa = ["kvkk", "kişisel veri", "kisisel veri"], Ha = /\b6698\b/;
3129
- function le(o) {
3130
- const e = o.toLowerCase();
3131
- return qa.some((t) => e.includes(t)) || Ha.test(e);
3132
- }
3133
- function be(o) {
3134
- try {
3135
- return localStorage.getItem(`${Me}_${o}`) === "1";
3136
- } catch {
3137
- return !1;
3138
- }
3139
- }
3140
- function Fa(o) {
3141
- try {
3142
- localStorage.setItem(`${Me}_${o}`, "1");
3143
- } catch {
3144
- }
3145
- }
3146
- function Oa(o) {
3147
- const t = new DOMParser().parseFromString(o, "text/html").body, a = Array.from(t.children);
3148
- for (const n of a)
3149
- if (le(n.textContent ?? "")) {
3150
- n.remove();
3151
- break;
3152
- }
3153
- return t.innerHTML.trim();
3154
- }
3155
- function ja(o) {
3156
- const e = new DOMParser().parseFromString(o, "text/html");
3157
- for (const t of Array.from(e.body.children))
3158
- if (le(t.textContent ?? ""))
3159
- return t.outerHTML;
3160
- return null;
3161
- }
3162
- const Va = {
3163
- tr: "TURKISH",
3164
- en: "ENGLISH",
3165
- de: "GERMAN",
3166
- fr: "FRENCH"
3167
- };
3168
- function $a(o) {
3169
- return o ? Va[o.toLowerCase().slice(0, 2)] ?? "TURKISH" : "TURKISH";
3170
- }
3171
- const Ga = ':host{all:initial;font-family:var(--gengage-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);font-size:var(--gengage-font-size, 14px)}.gengage-chat-root{position:fixed;z-index:var(--gengage-z-index, 2147483647);--_gengage-chat-offset: var(--gengage-chat-offset, 20px);--_gengage-chat-launcher-bottom: var(--gengage-chat-launcher-bottom, 20px);--_gengage-chat-launcher-right: var(--gengage-chat-launcher-right, 20px);--_gengage-chat-launcher-size: var(--gengage-chat-launcher-size, 56px);--_gengage-chat-drawer-width: var(--gengage-chat-width, 400px);--_gengage-chat-radius: var(--gengage-chat-shell-radius, 12px);--_gengage-chat-header-height: var(--gengage-chat-header-height, 60px);--_gengage-chat-conversation-width: var(--gengage-chat-conversation-width, 396px);--_gengage-chat-panel-min-width: var(--gengage-chat-panel-min-width, 320px);--_gengage-chat-panel-max-width: var(--gengage-chat-panel-max-width, 860px);--_gengage-chat-input-height: var(--gengage-chat-input-height, 48px);--_gengage-chat-shadow: var(--gengage-chat-shadow, 0 12px 40px rgba(15, 23, 42, .18));--_gengage-border-color: var(--gengage-border-color, #e5e7eb);--_gengage-discount-color: var(--gengage-discount-color, #ef4444);--_gengage-success-color: var(--gengage-success-color, #16a34a);--_gengage-text-secondary: var(--gengage-text-secondary, #64748b);--_gengage-qty-btn-size: var(--gengage-qty-btn-size, 28px);--_gengage-qty-btn-size-compact: var(--gengage-qty-btn-size-compact, 24px)}.gengage-chat-launcher-container{position:fixed;bottom:var(--_gengage-chat-launcher-bottom);right:var(--_gengage-chat-launcher-right);display:flex;flex-direction:column;align-items:flex-end;gap:10px;z-index:var(--gengage-z-index, 2147483647)}.gengage-chat-launcher-content-area,.gengage-chat-launcher-content-area-bottom{display:flex;flex-direction:column;align-items:flex-end;gap:8px}.gengage-chat-launcher-content-area:empty,.gengage-chat-launcher-content-area-bottom:empty{display:none}.gengage-chat-root--open .gengage-chat-launcher-content-area,.gengage-chat-root--open .gengage-chat-launcher-content-area-bottom{display:none}.gengage-chat-root--open .gengage-chat-launcher-container{pointer-events:none;opacity:0;transition:opacity .2s ease}.gengage-chat-launcher{width:var(--_gengage-chat-launcher-size);height:var(--_gengage-chat-launcher-size);border-radius:50%;border:none;background:var(--gengage-primary-color, #3b82f6);color:var(--gengage-primary-foreground, #fff);cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:0 8px 22px #0f172a47;transition:transform .18s cubic-bezier(.2,.8,.2,1),box-shadow .18s ease;position:relative;flex-shrink:0}.gengage-chat-launcher:hover{transform:scale(1.05);box-shadow:0 14px 28px #0f172a47}.gengage-chat-launcher svg{width:24px;height:24px}.gengage-chat-launcher--hidden-mobile{display:none!important}.gengage-chat-launcher-tooltip{position:absolute;right:calc(100% + 12px);top:50%;transform:translateY(-50%);padding:6px 12px;border-radius:8px;background:#1e293b;color:#fff;font-size:13px;font-weight:500;white-space:nowrap;opacity:0;pointer-events:none;transition:opacity .2s ease;box-shadow:0 2px 8px #00000026}.gengage-chat-launcher-tooltip:after{content:"";position:absolute;left:100%;top:50%;transform:translateY(-50%);border:5px solid transparent;border-left-color:#1e293b}.gengage-chat-launcher:hover .gengage-chat-launcher-tooltip{opacity:1}.gengage-chat-root--open .gengage-chat-launcher-tooltip{display:none}.gengage-chat-proactive{position:fixed;bottom:calc(var(--_gengage-chat-launcher-bottom) + var(--_gengage-chat-launcher-size) + 14px);right:var(--_gengage-chat-launcher-right);width:280px;padding:16px 18px;border-radius:16px;background:#fff;box-shadow:0 8px 30px #0000001f,0 2px 8px #0000000f;opacity:0;transform:translateY(8px) scale(.96);transition:opacity .25s ease,transform .25s ease;z-index:2147483645}.gengage-chat-proactive--visible{opacity:1;transform:translateY(0) scale(1)}.gengage-chat-proactive-message{margin:0 0 12px;font-size:14px;line-height:1.5;color:#1f2937}.gengage-chat-proactive-actions{display:flex;gap:8px}.gengage-chat-proactive-accept{flex:1;padding:8px 16px;border:none;border-radius:10px;background:var(--gengage-primary-color, #3b82f6);color:#fff;font-size:13px;font-weight:700;font-family:inherit;cursor:pointer;transition:filter .15s ease}.gengage-chat-proactive-accept:hover{filter:brightness(1.08)}.gengage-chat-proactive-dismiss{position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:transparent;color:#64748b;font-size:16px;cursor:pointer;display:flex;align-items:center;justify-content:center}.gengage-chat-proactive-dismiss:hover{color:#475569;background:#f1f5f9}.gengage-chat-drawer{position:fixed;top:0;bottom:0;right:0;width:var(--_gengage-chat-drawer-width);max-height:-webkit-fill-available;max-height:100dvh;border-radius:0;background:var(--gengage-background-color, #fff);box-shadow:var(--_gengage-chat-shadow);display:flex;flex-direction:column;overflow:hidden;z-index:var(--gengage-z-index, 2147483647)}.gengage-chat-root--mobile .gengage-chat-launcher-container{right:16px;bottom:calc(16px + env(safe-area-inset-bottom))}.gengage-chat-root--mobile .gengage-chat-drawer{left:0;right:0;bottom:0;width:100%;max-width:none;max-height:-webkit-fill-available;max-height:100dvh;border-radius:16px 16px 0 0;border-top:1px solid rgba(0,0,0,.06);box-shadow:0 -4px 16px #0000001a,0 12px 40px #0f172a2e;padding-bottom:env(safe-area-inset-bottom,0px)}.gengage-chat-root--mobile.gengage-chat-root--open:before{content:"";position:fixed;inset:0;background:#0000001f;z-index:-1;pointer-events:none}.gengage-chat-root--mobile.gengage-chat-root--mobile-half .gengage-chat-drawer{top:auto;height:min(72dvh,620px);max-height:min(72dvh,620px)}.gengage-chat-root--mobile.gengage-chat-root--mobile-full .gengage-chat-drawer{top:0;height:100dvh;max-height:100dvh;border-radius:0;border-top:none}.gengage-chat-root--mobile .gengage-chat-input-area{padding-bottom:calc(10px + env(safe-area-inset-bottom,0px));border-top:1px solid var(--_gengage-border-color, #e5e7eb);transform:translateY(calc(-1 * var(--gengage-keyboard-offset, 0px)))}.gengage-chat-header{display:flex;align-items:center;justify-content:space-between;box-sizing:border-box;min-height:var(--_gengage-chat-header-height);padding:4px 12px;background:var(--gengage-chat-header-bg, #1d2939);color:var(--gengage-chat-header-foreground, #fff);box-shadow:0 4px 20px #00000014,0 0 2px #0000001f;border:none;position:relative;z-index:2}.gengage-chat-header-left{display:flex;align-items:center;gap:10px;min-width:0}.gengage-chat-header-avatar{width:40px;height:40px;border-radius:50%;object-fit:cover;flex-shrink:0;border:2px solid rgba(255,255,255,.15)}.gengage-chat-header-info{display:flex;flex-direction:column;gap:2px;min-width:0}.gengage-chat-header-title-row{display:flex;align-items:center;gap:6px}.gengage-chat-header-title{font-weight:700;font-size:15px;line-height:1.25;letter-spacing:.01em;color:inherit}.gengage-chat-header-badge{display:inline-flex;align-items:center;padding:1px 6px;border-radius:4px;background:var(--gengage-primary-color, #3b82f6);color:#fff;font-size:10px;font-weight:700;letter-spacing:.04em;text-transform:uppercase;line-height:1.5}.gengage-chat-header-powered{display:flex;align-items:center;gap:4px;font-size:11px;color:#ffffffbf;text-decoration:none;transition:color .15s}.gengage-chat-header-powered:hover{color:#fffc}.gengage-chat-header-powered svg{width:12px;height:12px;opacity:.6}.gengage-chat-header-right{display:flex;align-items:center;gap:4px;flex-shrink:0}.gengage-chat-header-btn{width:32px;height:32px;border-radius:8px;background:transparent;border:1px solid rgba(255,255,255,.12);color:#ffffffb3;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;text-decoration:none;line-height:1;transition:background-color .15s ease,color .15s ease,border-color .15s ease}.gengage-chat-header-btn:hover{background:#ffffff1a;color:#fff;border-color:#ffffff40}.gengage-chat-close{width:32px;height:32px;border-radius:8px;background:transparent;border:1px solid rgba(255,255,255,.12);color:#ffffffb3;font-size:18px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;line-height:1;transition:background-color .15s ease,color .15s ease,border-color .15s ease}.gengage-chat-close:hover{background:#ffffff1a;color:#fff;border-color:#ffffff40}.gengage-chat-body{display:flex;flex:1;overflow:hidden;min-height:0}.gengage-chat-panel{display:none;width:0;overflow:hidden;transition:width .22s cubic-bezier(.2,.72,.2,1)}.gengage-chat-panel--visible{display:flex;flex-direction:column;position:relative;box-sizing:border-box;width:440px;min-width:440px;border-right:1px solid var(--_gengage-border-color);overflow-y:auto;padding:16px;background:#f8fafc}.gengage-chat-panel-divider{display:flex;align-items:center;width:4px;cursor:pointer;background:#e5e7eb;position:relative;flex-shrink:0;transition:background .15s;z-index:2}.gengage-chat-panel-divider:hover{background:#cbd5e1}.gengage-chat-panel-divider--hidden{display:none}.gengage-chat-panel-divider-toggle{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:24px;height:48px;border:1px solid var(--_gengage-border-color);border-radius:6px;background:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:var(--_gengage-text-secondary);box-shadow:0 1px 3px #00000014;transition:background .15s,color .15s;padding:0;line-height:1}.gengage-chat-panel-divider-toggle:hover{background:#f1f5f9;color:#334155}.gengage-chat-panel--collapsed{flex:0 0 0px!important;width:0!important;min-width:0!important;max-width:0!important;padding:0!important;border-right:none!important;overflow:hidden}.gengage-chat-panel--collapsed~.gengage-chat-panel-divider{width:0;background:transparent}.gengage-chat-panel--collapsed~.gengage-chat-panel-divider .gengage-chat-panel-divider-toggle{left:0;transform:translateY(-50%)}.gengage-chat-conversation{display:flex;flex-direction:column;flex:1;min-width:0;overflow:hidden;background:var(--gengage-background-color, #fff);position:relative;z-index:1}.gengage-chat-drawer--with-panel{width:auto;background:transparent;box-shadow:none}.gengage-chat-drawer--with-panel .gengage-chat-header{border-radius:0;flex-shrink:0}.gengage-chat-drawer--with-panel .gengage-chat-body{flex:1 1 0;min-height:0;gap:0;padding:0;align-items:stretch}.gengage-chat-drawer--with-panel .gengage-chat-panel--visible{flex:0 0 auto;width:clamp(var(--_gengage-chat-panel-min-width),50vw,var(--_gengage-chat-panel-max-width));min-width:var(--_gengage-chat-panel-min-width);max-width:var(--_gengage-chat-panel-max-width);border-right:none;background:#fff;padding:0 16px 16px;overflow-y:auto;margin:0;border-radius:0;box-shadow:0 8px 32px #0f172a1f,0 2px 8px #0f172a0f;max-height:100dvh}.gengage-chat-drawer--with-panel .gengage-chat-panel-divider{width:0;background:transparent}.gengage-chat-drawer--with-panel .gengage-chat-panel-divider-toggle{width:20px;height:48px;border-radius:10px;background:var(--gengage-primary-color, #3b82f6);color:#fff;border:2px solid #fff;box-shadow:0 2px 8px #0f172a2e;font-size:12px;z-index:10}.gengage-chat-drawer--with-panel .gengage-chat-panel-divider-toggle:hover{background:var(--gengage-primary-hover, #2563eb);color:#fff}.gengage-chat-drawer--with-panel .gengage-chat-conversation{flex:0 0 var(--_gengage-chat-conversation-width);width:var(--_gengage-chat-conversation-width);border-left:none;background:var(--gengage-background-color, #fff);box-shadow:-4px 0 24px #0f172a1f,-1px 0 4px #0f172a0f}.gengage-chat-drawer--with-panel .gengage-chat-messages{padding-right:6px;scrollbar-width:thin;scrollbar-color:rgba(0,0,0,.12) transparent}.gengage-chat-drawer--with-panel .gengage-chat-messages::-webkit-scrollbar{width:0}.gengage-chat-drawer--with-panel:has(.gengage-chat-panel--collapsed){width:var(--_gengage-chat-conversation-width);background:var(--gengage-background-color, #fff);box-shadow:var(--_gengage-chat-shadow)}.gengage-chat-drawer--with-panel .gengage-chat-footer{display:none}.gengage-chat-messages{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:16px;min-height:0;scroll-behavior:smooth;-webkit-overflow-scrolling:touch;overscroll-behavior:contain;touch-action:pan-y}.gengage-chat-messages::-webkit-scrollbar{width:6px}.gengage-chat-messages::-webkit-scrollbar-track{background:transparent}.gengage-chat-messages::-webkit-scrollbar-thumb{background:#0000001f;border-radius:3px}.gengage-chat-messages::-webkit-scrollbar-thumb:hover{background:#0003}.gengage-chat-bubble{max-width:85%;padding:12px 16px;border-radius:12px;line-height:1.5;font-size:14px;font-weight:500;word-wrap:break-word;overflow-wrap:break-word;animation:gengage-chat-msg-in .3s cubic-bezier(.2,.7,.2,1)}@keyframes gengage-chat-msg-in{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.gengage-chat-bubble--user{align-self:flex-end;background:var(--gengage-primary-color, #3b82f6);color:var(--gengage-primary-foreground, #fff);border-bottom-right-radius:4px}.gengage-chat-bubble--assistant{align-self:flex-start;background:#f3f4f6;color:#1f2937;border-bottom-left-radius:4px;min-width:120px}.gengage-chat-bubble--active{outline:2px solid var(--gengage-primary-color, #3b82f6);outline-offset:-2px}.gengage-chat-bubble--assistant:empty{display:none}.gengage-chat-bubble--assistant .gengage-chat-bubble-text a{color:var(--gengage-primary-color, #2563eb);text-decoration:underline}.gengage-chat-bubble--assistant .gengage-chat-bubble-text a:hover{text-decoration:none}.gengage-chat-bubble--assistant .gengage-chat-bubble-text p{margin:0 0 8px}.gengage-chat-bubble--assistant .gengage-chat-bubble-text p:last-child{margin-bottom:0}.gengage-chat-bubble--assistant .gengage-chat-bubble-text ul,.gengage-chat-bubble--assistant .gengage-chat-bubble-text ol{margin:6px 0;padding-left:20px}.gengage-chat-bubble--assistant .gengage-chat-bubble-text li{margin-bottom:6px;line-height:1.5}.gengage-chat-bubble--assistant .gengage-chat-bubble-text code{background:#0000000f;padding:1px 4px;border-radius:3px;font-size:.9em}.gengage-chat-bubble--assistant .gengage-chat-bubble-text pre{background:#0000000a;padding:8px;border-radius:6px;overflow-x:auto;margin:4px 0}.gengage-chat-bubble--assistant .gengage-chat-bubble-text table{border-collapse:collapse;margin:4px 0;font-size:.9em}.gengage-chat-bubble--assistant .gengage-chat-bubble-text th,.gengage-chat-bubble--assistant .gengage-chat-bubble-text td{border:1px solid var(--_gengage-border-color);padding:4px 8px}.gengage-chat-bubble--assistant .gengage-chat-bubble-text img{max-width:100%;height:auto;border-radius:4px;margin:4px 0}.gengage-chat-bubble--assistant .gengage-chat-bubble-text h1,.gengage-chat-bubble--assistant .gengage-chat-bubble-text h2,.gengage-chat-bubble--assistant .gengage-chat-bubble-text h3,.gengage-chat-bubble--assistant .gengage-chat-bubble-text h4,.gengage-chat-bubble--assistant .gengage-chat-bubble-text h5,.gengage-chat-bubble--assistant .gengage-chat-bubble-text h6{margin:8px 0 4px;line-height:1.3;color:#0f172a}.gengage-chat-bubble--assistant .gengage-chat-bubble-text blockquote{border-left:3px solid var(--_gengage-border-color);padding-left:12px;margin:4px 0;color:var(--_gengage-text-secondary)}.gengage-chat-bubble--first{border-left:3px solid var(--gengage-accent-primary, #3b82f6);padding-left:12px}.gengage-chat-bubble--first .gengage-chat-bubble-text{font-size:15px}.gengage-chat-typing{display:flex;align-items:center;gap:5px;padding:8px 4px;align-self:flex-start;max-width:85%}.gengage-chat-typing:has(.gengage-chat-typing-text),.gengage-chat-typing:has(.gengage-chat-thinking-steps){background:#f3f4f6;padding:10px 14px;border-radius:12px 12px 12px 4px;gap:8px}.gengage-chat-typing-dots{display:flex;align-items:center;gap:5px}.gengage-chat-typing-dots span{width:6px;height:6px;border-radius:50%;background:#94a3b8;display:inline-block;animation:gengage-chat-typing-fade 1.4s ease-in-out infinite}.gengage-chat-typing-dots span:nth-child(2){animation-delay:.2s}.gengage-chat-typing-dots span:nth-child(3){animation-delay:.4s}@keyframes gengage-chat-typing-fade{0%,to{opacity:.25}50%{opacity:1}}.gengage-chat-typing-sparkle{animation:gengage-sparkle-pulse 1.2s infinite}@keyframes gengage-sparkle-pulse{0%,to{opacity:1}50%{opacity:.4}}.gengage-chat-typing-text{font-size:13px;color:var(--_gengage-text-secondary);font-style:italic;flex:1;min-width:0;word-wrap:break-word;overflow-wrap:break-word}.gengage-chat-thinking-steps{display:flex;flex-direction:column;gap:4px;padding:4px 0}.gengage-chat-thinking-step{display:flex;align-items:center;gap:6px;font-size:13px;color:var(--gengage-chat-text-secondary, #666)}.gengage-chat-thinking-step-marker{font-size:12px;width:16px;text-align:center;flex-shrink:0}.gengage-chat-thinking-step-marker--done{color:var(--gengage-chat-success, #4caf50)}.gengage-chat-thinking-step-marker--active{color:var(--gengage-chat-primary, #1976d2);animation:gengage-thinking-pulse 1.5s ease-in-out infinite}@keyframes gengage-thinking-pulse{0%,to{opacity:1}50%{opacity:.4}}.gengage-chat-thinking-step-text{line-height:1.4}.gengage-chat-error{display:flex;align-items:center;justify-content:center;gap:10px;padding:10px 14px;border-radius:10px;background:#fef2f2;color:#991b1b;font-size:13px;text-align:center;border:1px solid #fecaca}.gengage-chat-error-retry{flex-shrink:0;padding:4px 12px;border:1px solid #fca5a5;border-radius:6px;background:#fff;color:#991b1b;font-size:12px;font-weight:500;cursor:pointer;transition:background .15s}.gengage-chat-error-retry:hover{background:#fee2e2}.gengage-chat-input-area{display:flex;flex-wrap:wrap;align-items:center;gap:0;padding:8px 12px;border-top:1px solid var(--_gengage-border-color);background:var(--gengage-background-color, #fff)}.gengage-chat-input-pill{display:flex;align-items:center;gap:4px;flex:1;min-width:0;height:44px;background:#f3f4f6;border:1px solid var(--_gengage-border-color);border-radius:30px;padding:2px 8px;overflow:hidden;transition:border-color .2s ease,box-shadow .2s ease}.gengage-chat-input-pill:focus-within{border-color:var(--gengage-primary-color, #3b82f6);box-shadow:0 0 0 2px #3b82f626}.gengage-chat-input{flex:1;min-width:0;min-height:40px;max-height:120px;padding:0 6px 0 14px;border:none;border-radius:0;font-size:14px;font-family:inherit;line-height:1.4;align-content:center;outline:none;background:transparent;color:#1f2937;resize:none;overflow-y:hidden}@media(max-width:767px){.gengage-chat-input-pill{height:52px;padding:3px 8px}.gengage-chat-input{min-height:44px;max-height:44px;font-size:16px;white-space:nowrap;overflow:hidden}.gengage-chat-input::placeholder{font-size:15px}}.gengage-chat-input::placeholder{font-size:14px;color:#6b7280}.gengage-chat-send{width:36px;height:36px;min-width:36px;padding:0;border:none;border-radius:50%;background:var(--gengage-primary-color, #3b82f6);color:var(--gengage-primary-foreground, #fff);font-weight:700;font-size:0;font-family:inherit;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:background-color .2s cubic-bezier(.4,0,.2,1),box-shadow .2s ease,transform .15s ease;box-shadow:0 2px 4px #0000001f}.gengage-chat-send:hover{filter:brightness(.92);transform:translateY(-1px);box-shadow:0 4px 8px #0000002e}.gengage-chat-send:active{transform:translateY(0);box-shadow:0 1px 2px #0000001f}.gengage-chat-send svg{width:18px;height:18px}.gengage-chat-send:disabled{background:#d1d5db;box-shadow:none;cursor:not-allowed}.gengage-chat-footer{padding:4px 10px;text-align:center;font-size:10px;color:#6b7280;border-top:1px solid #f1f5f9;background:var(--gengage-background-color, #fff)}.gengage-chat-uispec{width:100%}.gengage-chat-uispec:empty{display:none}.gengage-chat-uispec>*{animation:gengage-chat-widget-enter .16s cubic-bezier(.2,.7,.2,1) both}@keyframes gengage-chat-widget-enter{0%{opacity:0;transform:translateY(5px) scale(.99)}to{opacity:1;transform:translateY(0) scale(1)}}.gengage-chat-action-buttons{display:flex;gap:8px;padding:6px 0 4px;overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch}.gengage-chat-action-buttons::-webkit-scrollbar{display:none}.gengage-chat-action-btn{flex:0 0 auto;padding:8px 16px;border:none;border-radius:999px;background:var(--gengage-primary-color, #3b82f6);color:var(--gengage-primary-foreground, #fff);font-size:13px;font-weight:600;line-height:1.25;font-family:inherit;cursor:pointer;white-space:nowrap;transition:filter .15s ease,transform .1s ease}.gengage-chat-action-btn:hover{filter:brightness(.92)}.gengage-chat-action-btn:active{transform:scale(.97)}.gengage-chat-product-card{position:relative;border:1px solid #eee;border-radius:16px;overflow:hidden;background:#fff;width:160px;min-width:160px;max-width:160px;box-shadow:0 2px 8px #0000000f;transition:transform .1s ease,box-shadow .2s ease}.gengage-chat-product-card:hover{transform:translateY(-2px);box-shadow:0 4px 16px #0000001f}.gengage-chat-product-card-img{width:100%;height:120px;object-fit:contain;display:block;background:#fff;padding:8px;box-sizing:border-box}.gengage-chat-product-card-body{display:flex;flex-direction:column;gap:4px;padding:8px 10px 10px;text-align:center}.gengage-chat-product-card-name{font-size:13px;font-weight:600;color:#1f2937;line-height:1.35;margin-bottom:0;min-height:0;display:-webkit-box;-webkit-line-clamp:2;line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis}.gengage-chat-product-card-brand{font-size:10px;color:#666}.gengage-chat-product-card-rating{font-size:11px;color:#f59e0b;line-height:1}.gengage-chat-product-card-review-count{color:#64748b;font-size:10px}.gengage-chat-product-card-price{display:flex;align-items:baseline;justify-content:center;gap:4px;font-size:16px;font-weight:800;color:#0f172a}.gengage-chat-product-card-original-price{text-decoration:line-through;color:#64748b;font-weight:400;font-size:12px}.gengage-chat-price-skeleton{display:inline-block;width:80px;height:16px;background:linear-gradient(90deg,#e2e8f0 25%,#f1f5f9,#e2e8f0 75%);background-size:200% 100%;animation:gengage-skeleton-price-pulse 1.5s ease-in-out infinite;border-radius:4px;vertical-align:middle}@keyframes gengage-skeleton-price-pulse{0%{background-position:200% 0}to{background-position:-200% 0}}.gengage-chat-product-card-cta{display:block;padding:8px 10px;text-align:center;background:transparent;color:var(--gengage-primary-color, #3b82f6);text-decoration:none;font-size:12px;font-weight:700;letter-spacing:.01em;border-top:1px solid #f1f5f9;transition:color .15s ease,background .15s ease}.gengage-chat-product-card-cta:hover{color:var(--gengage-primary-color, #0b24d6);background:#f8fafc}.gengage-chat-product-card-cta:active{background:#f1f5f9}.gengage-chat-product-summary{display:flex;align-items:center;gap:12px;padding:10px 12px;border:1px solid #e5e7eb;border-radius:12px;background:#fff;cursor:pointer;transition:background .15s,box-shadow .15s;margin:4px 0}.gengage-chat-product-summary:hover{background:#f9fafb;box-shadow:0 1px 4px #0000000f}.gengage-chat-product-summary__image{flex-shrink:0;width:64px;height:64px;border-radius:8px;overflow:hidden;border:1px solid #f3f4f6;background:#f9fafb}.gengage-chat-product-summary__image img{width:100%;height:100%;object-fit:cover;display:block}.gengage-chat-product-summary__content{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}.gengage-chat-product-summary__name{font-size:13px;font-weight:500;line-height:1.3;color:#111827;display:-webkit-box;-webkit-line-clamp:2;line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.gengage-chat-product-summary__rating{font-size:11px;color:#f59e0b;line-height:1}.gengage-chat-product-summary__review-count{color:#6b7280;font-size:11px}.gengage-chat-product-summary__price{font-size:13px;font-weight:600;color:#111827;line-height:1;margin-top:2px}.gengage-chat-product-summary__price-original{text-decoration:line-through;color:#6b7280;font-weight:400;font-size:11px}.gengage-chat-product-summary__price-current{color:var(--gengage-primary-color, #111827)}.gengage-chat-product-summary__cta{flex-shrink:0;font-size:12px;font-weight:500;color:var(--gengage-primary-color, #2563eb);text-decoration:none;padding:4px 10px;border-radius:8px;transition:background .15s;white-space:nowrap}.gengage-chat-product-summary__cta:hover{background:#0000000a}.gengage-chat-product-summary__cta:focus-visible{outline:2px solid var(--gengage-primary-color, #2563eb);outline-offset:2px}.gengage-chat-product-grid{display:flex;gap:12px;overflow-x:auto;padding:8px 0;-webkit-overflow-scrolling:touch;scrollbar-width:none;scroll-snap-type:x proximity;min-height:180px}.gengage-chat-product-grid>*{scroll-snap-align:start;flex:0 0 auto}.gengage-chat-product-grid::-webkit-scrollbar{display:none}.gengage-chat-review-highlights{padding:2px 0 6px}.gengage-chat-review-item{border:1px solid var(--_gengage-border-color);border-radius:12px;padding:10px 12px;background:#fff}.gengage-chat-review-item[data-tone=positive]{border-color:#bbf7d0;background:#f0fdf4}.gengage-chat-review-item[data-tone=negative]{border-color:#fecaca;background:#fef2f2}.gengage-chat-review-tag{font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.03em;color:var(--_gengage-text-secondary);margin-bottom:4px}.gengage-chat-review-text{font-size:13px;line-height:1.45;color:#1f2937}.gengage-chat-review-rating{margin-top:6px;font-size:12px;font-weight:700;color:#0f172a}.gengage-chat-review-empty{font-size:12px;color:var(--_gengage-text-secondary)}.gengage-chat-review-tabs{display:flex;gap:6px;margin-bottom:10px}.gengage-chat-review-tab{padding:6px 14px;border:1px solid var(--_gengage-border-color);border-radius:999px;background:#fff;color:var(--_gengage-text-secondary);font-size:12px;font-weight:600;font-family:inherit;cursor:pointer;transition:background .15s,border-color .15s}.gengage-chat-review-tab:hover{background:#f8fafc}.gengage-chat-review-tab--active{background:#f1f5f9;border-color:#94a3b8;color:#0f172a}.gengage-chat-review-pills{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}.gengage-chat-review-pill{display:flex;align-items:center;gap:6px;padding:6px 10px;border:1px solid var(--_gengage-border-color);border-radius:8px;background:#fff;font-size:12px;color:#334155;box-shadow:0 1px 2px #0000000a}.gengage-chat-review-pill[data-tone=positive]{border-color:#bbf7d0}.gengage-chat-review-pill[data-tone=negative]{border-color:#fecaca}.gengage-chat-review-pill-icon{font-size:11px;font-weight:700}.gengage-chat-review-pill[data-tone=positive] .gengage-chat-review-pill-icon{color:#16a34a}.gengage-chat-review-pill[data-tone=negative] .gengage-chat-review-pill-icon{color:#dc2626}.gengage-chat-review-pill-count{font-size:10px;font-weight:700;background:#f1f5f9;color:var(--_gengage-text-secondary);border-radius:4px;padding:1px 5px}.gengage-chat-review-items{display:grid;gap:10px}.gengage-chat-divider{border:none;border-top:1px solid var(--_gengage-border-color);margin:8px 0}.gengage-chat-divider-wrapper{display:flex;align-items:center;gap:8px;margin:8px 0}.gengage-chat-divider-wrapper hr{flex:1;border:none;border-top:1px solid var(--_gengage-border-color);margin:0}.gengage-chat-divider-label{font-size:11px;color:#6b7280;white-space:nowrap}.gengage-chat--overlay .gengage-chat-drawer{position:fixed;inset:0;width:100%;max-width:480px;max-height:100%;margin:0 auto;border-radius:0;animation:gengage-chat-overlay-in .24s cubic-bezier(.2,.72,.2,1)}.gengage-chat--overlay:before{content:"";position:fixed;inset:0;background:#00000073;z-index:-1}@keyframes gengage-chat-overlay-in{0%{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}.gengage-chat-panel-skeleton{display:flex;flex-direction:column;gap:14px;padding:6px 0}.gengage-chat-panel-skeleton-block{height:110px;border-radius:10px;background:linear-gradient(90deg,#e5e7eb 25%,#f3f4f6,#e5e7eb 75%);background-size:200% 100%;animation:gengage-panel-shimmer 1.4s infinite}@keyframes gengage-panel-shimmer{0%{background-position:200% 0}to{background-position:-200% 0}}.gengage-chat-panel-skeleton-block--image{height:200px;border-radius:8px;margin-bottom:12px}.gengage-chat-panel-skeleton-block--text{height:16px;border-radius:4px;margin-bottom:8px}.gengage-chat-panel-skeleton-block--text:nth-child(3){width:80%}.gengage-chat-panel-skeleton-block--text:nth-child(4){width:60%}.gengage-chat-panel-skeleton-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}.gengage-chat-panel-skeleton-block--card{height:120px;border-radius:8px}.gengage-chat-panel-skeleton-block--row{height:32px;border-radius:4px;margin-bottom:4px}.gengage-chat-panel .gengage-chat-product-card{width:100%;max-width:100%;min-width:0;display:flex;flex-direction:column;border-radius:12px;border:1px solid var(--_gengage-border-color);box-shadow:0 1px 4px #0000000f;overflow:hidden;padding:0}.gengage-chat-panel .gengage-chat-product-card:hover{transform:translateY(-2px);box-shadow:0 4px 12px #0000001a;border-color:#d1d5db}.gengage-chat-panel .gengage-chat-product-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));overflow-x:visible;gap:12px;min-height:auto;padding:4px 0}.gengage-chat-panel .gengage-chat-product-card-img{width:100%;height:160px;border-radius:0;object-fit:contain;background:#fafafa;padding:12px;box-sizing:border-box}.gengage-chat-panel .gengage-chat-product-card-body{padding:10px 12px 12px;text-align:left;gap:4px}.gengage-chat-panel .gengage-chat-product-card-name{min-height:0;margin-bottom:2px;font-size:13px;-webkit-line-clamp:2;line-clamp:2}.gengage-chat-panel .gengage-chat-product-card-price{justify-content:flex-start;font-size:15px}.gengage-chat-panel .gengage-chat-product-card-cta{display:block;padding:10px 12px;text-align:center;border-top:1px solid #f1f5f9;border-radius:0;background:transparent;color:var(--gengage-primary-color, #3b82f6);font-weight:700;font-size:13px}.gengage-chat-product-details-panel{display:flex;flex-direction:column;gap:12px;width:100%;background:#fff;border:1px solid var(--_gengage-border-color);border-radius:16px;padding:14px;box-sizing:border-box}.gengage-chat-product-details-media{border:1px solid #f1f5f9;border-radius:12px;background:#fafafa;padding:12px;display:flex;flex-direction:column;align-items:center}.gengage-chat-product-details-img{width:100%;height:auto;max-height:300px;object-fit:contain;border-radius:8px}.gengage-chat-product-details-content{display:flex;flex-direction:column;gap:8px;min-width:0}.gengage-chat-product-details-title{margin:0;font-size:17px;font-weight:700;line-height:1.3;color:#0f172a}.gengage-chat-product-details-rating{display:inline-flex;align-items:center;gap:4px;width:fit-content;padding:3px 8px;border-radius:999px;background:#fff7ed;color:#9a3412;font-size:13px;font-weight:700}.gengage-chat-product-details-review-count{color:#7c2d12;font-weight:600}.gengage-chat-product-details-price{display:flex;align-items:baseline;gap:6px}.gengage-chat-product-details-original-price{font-size:14px;color:#64748b;text-decoration:line-through}.gengage-chat-product-details-current-price{font-size:22px;font-weight:800;line-height:1.1;color:#0f172a}.gengage-chat-product-details-stock{width:fit-content;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:700}.gengage-chat-product-details-stock.is-in-stock{background:#dcfce7;color:#166534}.gengage-chat-product-details-stock.is-out-of-stock{background:#fee2e2;color:#991b1b}.gengage-chat-product-details-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:4px}.gengage-chat-product-details-cta{display:inline-flex;align-items:center;justify-content:center;min-height:40px;padding:0 20px;border-radius:999px;border:none;text-decoration:none;background:var(--gengage-primary-color, #3b82f6);color:var(--gengage-primary-foreground, #fff);font-size:14px;font-weight:700;cursor:pointer;transition:filter .14s ease,transform .12s ease}.gengage-chat-product-details-cta:hover{filter:brightness(1.05);transform:translateY(-1px)}.gengage-chat-product-details-cta:active{transform:translateY(1px)}.gengage-chat-product-details-atc{display:inline-flex;align-items:center;justify-content:center;gap:6px;padding:10px 20px;border:none;border-radius:10px;background:var(--_gengage-success-color);color:#fff;font-size:14px;font-weight:700;font-family:inherit;cursor:pointer;transition:filter .12s ease,transform .12s ease}.gengage-chat-product-details-atc:hover{filter:brightness(1.08);transform:translateY(-1px)}.gengage-chat-product-details-atc:active{transform:translateY(1px)}.gengage-chat-product-detail-tabs{margin-top:4px;border-top:1px solid var(--_gengage-border-color);padding-top:12px}.gengage-chat-product-detail-tab-bar{display:flex;gap:0;border-bottom:2px solid var(--_gengage-border-color);margin-bottom:12px}.gengage-chat-product-detail-tab{flex:1;padding:8px 12px;border:none;background:transparent;color:var(--_gengage-text-secondary);font-size:13px;font-weight:600;font-family:inherit;cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-2px;transition:color .15s,border-color .15s}.gengage-chat-product-detail-tab:hover{color:#334155}.gengage-chat-product-detail-tab--active{color:var(--gengage-primary-color, #3b82f6);border-bottom-color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-product-detail-tab-panel{font-size:13px;line-height:1.6;color:#374151}.gengage-chat-product-specs-table{width:100%;border-collapse:collapse;font-size:13px}.gengage-chat-product-specs-table tr:nth-child(2n){background:#f8fafc}.gengage-chat-product-specs-key{padding:6px 10px;font-weight:600;color:#475569;white-space:nowrap;border-bottom:1px solid #f1f5f9;width:40%}.gengage-chat-product-specs-value{padding:6px 10px;color:#1f2937;border-bottom:1px solid #f1f5f9}.gengage-chat-product-card-atc{position:absolute;bottom:42px;right:6px;opacity:0;transition:opacity .15s ease;z-index:1}.gengage-chat-product-card:hover .gengage-chat-product-card-atc{opacity:1}.gengage-chat-drawer.gengage-chat-drawer--hidden,.gengage-chat-root--mobile .gengage-chat-drawer.gengage-chat-drawer--hidden{display:none!important;pointer-events:none;box-shadow:none}@media(max-width:900px){.gengage-chat-drawer--with-panel .gengage-chat-panel--visible{width:clamp(280px,calc(100vw - var(--_gengage-chat-conversation-width)),560px);max-width:560px}}.gengage-chat-attachment-preview{display:flex;align-items:center;gap:8px;padding:6px 10px;background:#f3f4f6;border:1px solid var(--_gengage-border-color);border-radius:8px;width:100%;box-sizing:border-box}.gengage-chat-attachment-preview--hidden{display:none}.gengage-chat-attachment-preview-thumb{width:40px;height:40px;border-radius:4px;object-fit:cover;flex-shrink:0}.gengage-chat-attachment-name{flex:1;font-size:12px;color:#4b5563;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.gengage-chat-attachment-remove{background:none;border:none;cursor:pointer;font-size:18px;color:#6b7280;padding:0 4px;line-height:1;flex-shrink:0}.gengage-chat-attachment-remove:hover{color:#ef4444}.gengage-chat-attach-btn{background:none;border:none;cursor:pointer;width:32px;height:32px;padding:0;line-height:1;flex-shrink:0;display:flex;align-items:center;justify-content:center;border-radius:50%;color:#6b7280;transition:color .15s,background .15s}.gengage-chat-attach-btn:hover{color:#4b5563;background:#0000000d}.gengage-chat-attach-btn svg{width:20px;height:20px}.gengage-chat-mic-btn{background:none;border:none;cursor:pointer;width:32px;height:32px;padding:0;line-height:1;flex-shrink:0;display:flex;align-items:center;justify-content:center;border-radius:50%;color:#6b7280;transition:color .15s,background .15s}.gengage-chat-mic-btn:hover{color:#4b5563;background:#0000000d}.gengage-chat-mic-btn svg{width:20px;height:20px}.gengage-chat-mic-btn--active{color:#ef4444;animation:gengage-mic-pulse 1.2s ease-in-out infinite}.gengage-chat-mic-btn--active:hover{color:#dc2626}@keyframes gengage-mic-pulse{0%,to{transform:scale(1);opacity:1}50%{transform:scale(1.15);opacity:.8}}.gengage-chat-input-area--dragover{outline:2px dashed var(--gengage-primary-color, #3b82f6);outline-offset:-2px;background:#eff6ff}.gengage-chat-attachment-thumb{width:120px;max-width:100%;height:auto;border-radius:8px;margin-bottom:6px;display:block}@media(max-width:768px){.gengage-chat-root{--_gengage-qty-btn-size: 44px;--_gengage-qty-btn-size-compact: 44px}.gengage-chat-header-btn,.gengage-chat-close{width:44px;height:44px;border-radius:12px}.gengage-chat-attach-btn,.gengage-chat-mic-btn,.gengage-chat-send{width:44px;height:44px;min-width:44px}.gengage-chat-attach-btn svg,.gengage-chat-mic-btn svg{width:22px;height:22px}.gengage-chat-panel-divider{display:flex;width:100%;height:20px;align-items:center;justify-content:center;cursor:ns-resize;background:transparent;touch-action:pan-y;position:relative;overflow:visible}.gengage-chat-panel-divider--hidden{display:none}.gengage-chat-drawer--with-panel{left:0;right:0;width:100%;border-radius:0}.gengage-chat-drawer--with-panel .gengage-chat-body{flex-direction:column}.gengage-chat-drawer--with-panel .gengage-chat-panel--visible{width:100%;min-width:0;max-width:none;max-height:30dvh;border-right:none;border-bottom:1px solid var(--_gengage-border-color);padding:0 12px 12px;margin:0;border-radius:0;box-shadow:none}.gengage-chat-drawer--with-panel .gengage-chat-panel-divider{width:100%;height:20px;background:transparent;border-bottom:1px solid rgba(148,163,184,.22)}.gengage-chat-drawer--with-panel .gengage-chat-panel-divider-toggle{left:50%;top:50%;transform:translate(-50%,-50%);width:100%;height:44px;border:none;border-radius:0;background:transparent;box-shadow:none;color:transparent;font-size:0;line-height:0;padding:0}.gengage-chat-drawer--with-panel .gengage-chat-panel-divider-toggle:before{content:"";display:block;width:52px;height:5px;margin:0 auto;border-radius:999px;background:#94a3b8;box-shadow:0 1px #64748b59;transition:background .15s ease}.gengage-chat-drawer--with-panel .gengage-chat-panel-divider-toggle:hover,.gengage-chat-drawer--with-panel .gengage-chat-panel-divider-toggle:active{background:transparent;color:transparent}.gengage-chat-drawer--with-panel .gengage-chat-panel-divider-toggle:hover:before,.gengage-chat-drawer--with-panel .gengage-chat-panel-divider-toggle:active:before{background:#64748b}.gengage-chat-panel--collapsed~.gengage-chat-panel-divider{width:100%;background:transparent}.gengage-chat-panel--collapsed~.gengage-chat-panel-divider .gengage-chat-panel-divider-toggle{left:50%;transform:translate(-50%,-50%)}.gengage-chat-drawer--with-panel .gengage-chat-conversation{width:100%;flex:1;border-left:none}.gengage-qty-stepper--compact .gengage-qty-value{min-width:24px;font-size:13px}.gengage-qty-stepper--compact .gengage-qty-submit{min-height:44px;padding:0 12px;font-size:13px}.gengage-chat-product-details-atc-stepper .gengage-qty-submit{min-height:44px;padding:0 16px}.gengage-chat-product-details-share{width:44px;height:44px}.gengage-chat-panel .gengage-chat-product-card{grid-template-columns:84px 1fr}.gengage-chat-panel .gengage-chat-product-card-cta{grid-column:1 / -1;width:100%}.gengage-chat-product-details-panel{padding:12px;gap:12px}.gengage-chat-product-details-media{min-height:140px}.gengage-chat-product-details-title{font-size:15px}.gengage-chat-product-details-current-price{font-size:20px}.gengage-chat-product-grid{scroll-snap-type:x mandatory}.gengage-chat-product-card{width:280px;min-width:280px;scroll-snap-align:center}.gengage-chat-product-card-img{height:180px}}@media(max-width:480px){.gengage-chat-drawer{position:fixed;inset:0;width:100%;max-height:100%;border-radius:0}.gengage-chat-bubble{max-width:100%}}.gengage-chat-kvkk-banner{display:flex;align-items:flex-start;gap:8px;padding:10px 14px;background:#fffbeb;border-bottom:1px solid #fde68a;font-size:12px;line-height:1.5;color:#92400e}.gengage-chat-kvkk-content{flex:1;min-width:0}.gengage-chat-kvkk-content a{color:#b45309;text-decoration:underline}.gengage-chat-kvkk-dismiss{flex-shrink:0;width:20px;height:20px;border:none;background:transparent;color:#92400e;font-size:16px;cursor:pointer;padding:0;line-height:1}.gengage-chat-comparison{padding:16px}.gengage-chat-comparison-heading{font-size:14px;font-weight:700;letter-spacing:.05em;color:#0f172a;margin:0 0 16px}.gengage-chat-comparison-recommended{border:1px solid var(--_gengage-border-color);border-radius:12px;padding:16px;background:#fff;box-shadow:0 1px 3px #0000000f;margin-bottom:12px}.gengage-chat-comparison-recommended-label{font-size:12px;font-weight:700;color:#16a34a;text-transform:uppercase;letter-spacing:.04em;margin-bottom:12px}.gengage-chat-comparison-recommended-body{display:flex;gap:12px;align-items:flex-start}.gengage-chat-comparison-recommended-body img{width:80px;height:80px;object-fit:contain;border-radius:8px;background:#f8fafc}.gengage-chat-comparison-recommended-info{flex:1;min-width:0}.gengage-chat-comparison-recommended-title{font-size:14px;font-weight:600;color:#0f172a;margin-bottom:4px}.gengage-chat-comparison-recommended-price{font-size:16px;font-weight:700;color:#0f172a}.gengage-chat-comparison-highlights{margin-top:12px;padding-top:12px;border-top:1px solid #f1f5f9}.gengage-chat-comparison-highlights-label{font-size:12px;font-weight:600;color:var(--_gengage-text-secondary);margin-bottom:6px}.gengage-chat-comparison-highlights ul{margin:0;padding-left:18px;font-size:13px;color:#334155;line-height:1.6}.gengage-chat-comparison-special{background:#fffbeb;border:1px solid #fde68a;border-radius:12px;padding:12px 16px;margin-bottom:12px;font-size:13px;color:#92400e}.gengage-chat-comparison-special summary{cursor:pointer;font-weight:600}.gengage-chat-comparison-special ul{margin:8px 0 0;padding-left:18px;line-height:1.6}.gengage-chat-comparison-table{width:100%;border-collapse:collapse;font-size:13px;margin-top:12px}.gengage-chat-comparison-table th,.gengage-chat-comparison-table td{padding:10px 12px;text-align:center;border-bottom:1px solid #f1f5f9;vertical-align:top}.gengage-chat-comparison-table th{font-weight:600;font-size:12px;color:#334155}.gengage-chat-comparison-table th img{width:60px;height:60px;object-fit:contain;border-radius:6px;background:#f8fafc;margin-bottom:6px}.gengage-chat-comparison-table-price{font-weight:700;color:#0f172a}.gengage-chat-comparison-label{text-align:left;font-weight:600;color:var(--_gengage-text-secondary);white-space:nowrap}.gengage-chat-comparison-selected{background:#f0fdf4}.gengage-chat-comparison-recommended-text{padding:8px 12px;font-size:12px;color:var(--gengage-text-secondary, #475569);font-style:italic;border-top:1px solid var(--gengage-border-color, #e2e8f0);margin-top:8px}.gengage-chat-comparison-product-actions{display:flex;gap:8px;margin-top:12px;flex-wrap:wrap}.gengage-chat-comparison-view-btn{flex:1;min-width:0;padding:8px 12px;border:1px solid var(--gengage-primary-color, #3b82f6);border-radius:6px;background:transparent;color:var(--gengage-primary-color, #3b82f6);font-size:12px;font-weight:500;font-family:inherit;cursor:pointer;transition:background .15s ease,color .15s ease;text-overflow:ellipsis;overflow:hidden;white-space:nowrap}.gengage-chat-comparison-view-btn:hover{background:var(--gengage-primary-color, #3b82f6);color:#fff}.gengage-chat-pills{position:relative;padding:8px 12px;border-top:1px solid #f1f5f9;background:var(--gengage-background-color, #fff)}.gengage-chat-pills-scroll{display:flex;gap:8px;overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch;padding-right:28px}.gengage-chat-pills-scroll::-webkit-scrollbar{display:none}.gengage-chat-pill{flex:0 0 auto;padding:8px 16px;border:none;border-radius:999px;background:var(--gengage-primary-color, #3b82f6);color:var(--gengage-primary-foreground, #fff);font-size:13px;font-weight:600;font-family:inherit;white-space:nowrap;cursor:pointer;transition:filter .15s,transform .1s}.gengage-chat-pill:hover{filter:brightness(.92)}.gengage-chat-pill:active{transform:scale(.97)}.gengage-chat-pill--rich{display:flex;align-items:center;gap:8px;padding:6px 14px 6px 6px;border-radius:20px}.gengage-chat-pill-img{width:32px;height:32px;border-radius:50%;object-fit:cover;flex-shrink:0;background:#ffffff26}.gengage-chat-pill-text{font-size:13px;font-weight:600;line-height:1.2}.gengage-chat-pill-desc{display:none}.gengage-chat-pill--rich .gengage-chat-pill-desc{display:block;font-size:10px;font-weight:400;opacity:.8;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:160px}.gengage-chat-pills-arrow{position:absolute;right:8px;top:50%;transform:translateY(-50%);width:28px;height:28px;border-radius:50%;border:1px solid var(--_gengage-border-color);background:#fff;color:var(--_gengage-text-secondary);font-size:16px;cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:-4px 0 8px #ffffffe6;z-index:1}.gengage-chat-pills-arrow:hover{background:#f8fafc;color:#334155}@media(prefers-reduced-motion:reduce){.gengage-chat-uispec>*,.gengage-chat-action-btn,.gengage-chat-product-card,.gengage-chat-product-card-cta,.gengage-chat-send,.gengage-chat-launcher,.gengage-chat-pill,.gengage-chat-drawer,.gengage-chat-proactive,.gengage-chat-typing-dots span,.gengage-chat-typing-sparkle,.gengage-chat-thinking-step-marker--active,.gengage-chat-bubble,.gengage-chat-panel-skeleton-block,.gengage-chat-ai-toppick-card,.gengage-chat-mic-btn--active,.gengage-chat-ai-toppick-spinner:after,.gengage-chat-panel-shimmer,.gengage-chat-overlay,.gengage-chat-product-details-skeleton-price{animation:none!important;transition:none!important;transform:none!important}}.gengage-chat-bubble--user{position:relative}.gengage-chat-rollback-btn{position:absolute;left:-28px;top:50%;transform:translateY(-50%);width:24px;height:24px;border:none;border-radius:50%;background:var(--gengage-surface-color, #f1f5f9);color:var(--gengage-text-secondary, #64748b);cursor:pointer;display:flex;align-items:center;justify-content:center;opacity:0;transition:opacity .15s ease;padding:0}.gengage-chat-bubble--user:hover .gengage-chat-rollback-btn{opacity:1}.gengage-chat-rollback-btn:hover{background:var(--gengage-primary-color, #3b82f6);color:#fff}.gengage-chat-bubble--hidden{display:none}.gengage-chat-ai-top-picks{display:flex;flex-direction:column;gap:12px;padding:8px 0}.gengage-chat-ai-top-picks-title{font-size:15px;font-weight:600;color:var(--gengage-text-primary, #1e293b);margin:0 0 4px}.gengage-chat-ai-top-picks-cards{display:flex;flex-direction:column;gap:10px}.gengage-chat-ai-toppick-discount-badge{position:absolute;top:8px;left:8px;background:var(--gengage-discount-bg, #ef4444);color:#fff;font-size:11px;font-weight:700;padding:2px 6px;border-radius:4px;z-index:1}.gengage-chat-ai-toppick-card--winner{position:relative;display:flex;flex-direction:column;border:2px solid var(--gengage-primary-color, #3b82f6);border-radius:12px;background:#fff;overflow:hidden;transition:box-shadow .2s ease}.gengage-chat-ai-toppick-card--winner:hover{box-shadow:0 4px 16px #3b82f626}.gengage-chat-ai-toppick-card--winner .gengage-chat-ai-toppick-img{width:100%;height:140px;object-fit:contain;background:#f8fafc}.gengage-chat-ai-toppick-card--compact{position:relative;display:flex;flex-direction:row;align-items:center;gap:12px;border:1px solid var(--gengage-border-color, #e2e8f0);border-radius:10px;background:#fff;padding:10px;transition:box-shadow .2s ease,transform .15s ease}.gengage-chat-ai-toppick-card--compact:hover{box-shadow:0 2px 8px #00000014;transform:translateY(-1px)}.gengage-chat-ai-toppick-card--compact .gengage-chat-ai-toppick-img{width:64px;height:64px;object-fit:contain;border-radius:8px;background:#f8fafc;flex-shrink:0}.gengage-chat-ai-toppick-badge{position:absolute;top:8px;left:8px;background:var(--gengage-primary-color, #3b82f6);color:#fff;font-size:10px;font-weight:700;text-transform:uppercase;padding:2px 8px;border-radius:4px;z-index:1;letter-spacing:.5px}.gengage-chat-ai-toppick-body{display:flex;flex-direction:column;gap:4px;padding:10px;flex:1;min-width:0}.gengage-chat-ai-toppick-card--compact .gengage-chat-ai-toppick-body{padding:0}.gengage-chat-ai-toppick-name{font-size:13px;font-weight:600;color:var(--gengage-text-primary, #1e293b);overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;line-clamp:2;-webkit-box-orient:vertical}.gengage-chat-ai-toppick-role{font-size:11px;font-weight:600;color:var(--gengage-primary-color, #3b82f6);text-transform:uppercase;letter-spacing:.3px}.gengage-chat-ai-toppick-labels{display:flex;flex-wrap:wrap;gap:4px}.gengage-chat-ai-toppick-label{font-size:11px;padding:1px 6px;border-radius:4px;font-weight:500}.gengage-chat-ai-toppick-label[data-sentiment=positive]{background:#dcfce7;color:#166534}.gengage-chat-ai-toppick-label[data-sentiment=negative]{background:#fee2e2;color:#991b1b}.gengage-chat-ai-toppick-label[data-sentiment=neutral]{background:#f1f5f9;color:#475569}.gengage-chat-ai-toppick-score{font-size:12px;font-weight:700;color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-ai-toppick-reason{font-size:12px;color:var(--gengage-chat-text-secondary, #666);line-height:1.4;margin-top:4px}.gengage-chat-ai-toppick-review{font-size:12px;font-style:italic;color:var(--gengage-text-secondary, #64748b);margin:2px 0;padding-left:8px;border-left:2px solid var(--gengage-border-color, #e2e8f0)}.gengage-chat-ai-toppick-price{font-size:14px;font-weight:700;color:var(--gengage-text-primary, #1e293b)}.gengage-chat-ai-toppick-original-price{text-decoration:line-through;color:var(--gengage-text-secondary, #64748b);font-weight:400;font-size:12px}.gengage-chat-ai-toppick-cta{display:block;width:calc(100% - 20px);margin:6px 10px 10px;padding:8px 0;border:none;border-radius:8px;background:var(--gengage-primary-color, #3b82f6);color:#fff;font-size:13px;font-weight:600;cursor:pointer;text-align:center;transition:background .15s ease}.gengage-chat-ai-toppick-cta:hover{filter:brightness(.92)}.gengage-chat-ai-toppick-card--compact .gengage-chat-ai-toppick-cta{width:auto;margin:0;padding:6px 14px;flex-shrink:0;align-self:center}.gengage-chat-ai-toppick-spinner{position:absolute;inset:0;background:#ffffffb3;display:flex;align-items:center;justify-content:center;border-radius:12px;z-index:3}.gengage-chat-ai-toppick-spinner:after{content:"";width:24px;height:24px;border:3px solid var(--gengage-border, #e2e8f0);border-top-color:var(--gengage-accent-primary, #3b82f6);border-radius:50%;animation:gengage-spin .7s linear infinite}@keyframes gengage-spin{to{transform:rotate(360deg)}}@media(max-width:768px){.gengage-chat-ai-top-picks-cards{flex-direction:row;overflow-x:auto;scroll-snap-type:x mandatory;-webkit-overflow-scrolling:touch;gap:10px;padding-bottom:4px}.gengage-chat-ai-toppick-card--winner,.gengage-chat-ai-toppick-card--compact{min-width:280px;max-width:280px;flex-shrink:0;scroll-snap-align:start}.gengage-chat-ai-toppick-card--compact{flex-direction:column;align-items:stretch}.gengage-chat-ai-toppick-card--compact .gengage-chat-ai-toppick-img{width:100%;height:100px;border-radius:8px 8px 0 0}.gengage-chat-ai-toppick-card--compact .gengage-chat-ai-toppick-cta{width:calc(100% - 20px);margin:6px 10px 10px;align-self:stretch}.gengage-chat-rollback-btn{left:-24px}}.gengage-chat-grounding-review{display:flex;align-items:center;gap:12px;padding:12px 16px;background:var(--gengage-surface-color, #f8fafc);border:1px solid var(--gengage-border-color, #e2e8f0);border-radius:10px;transition:background .15s ease,border-color .15s ease}.gengage-chat-grounding-review:hover{background:var(--gengage-hover-color, #f1f5f9);border-color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-grounding-review-icon{font-size:20px;flex-shrink:0}.gengage-chat-grounding-review-body{flex:1;min-width:0}.gengage-chat-grounding-review-title{font-weight:600;font-size:13px;color:var(--gengage-text-color, #1e293b)}.gengage-chat-grounding-review-subtitle{font-size:12px;color:var(--gengage-text-muted, #64748b);margin-top:2px}.gengage-chat-grounding-review-cta{font-size:13px;font-weight:500;color:var(--gengage-primary-color, #3b82f6);white-space:nowrap;flex-shrink:0}.gengage-chat-grouping-cards{display:flex;flex-direction:column;gap:6px}.gengage-chat-grouping-card{display:flex;align-items:center;gap:10px;padding:8px 12px;background:var(--gengage-surface-color, #f8fafc);border:1px solid var(--gengage-border-color, #e2e8f0);border-radius:8px;transition:background .15s ease,border-color .15s ease}.gengage-chat-grouping-card:hover{background:var(--gengage-hover-color, #f1f5f9);border-color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-grouping-card-arrow{display:none;font-size:14px;color:var(--gengage-primary-color, #3b82f6);flex-shrink:0}.gengage-chat-grouping-card-img{width:20px;height:20px;border-radius:4px;object-fit:cover;flex-shrink:0}.gengage-chat-grouping-card-body{flex:1;min-width:0;display:flex;align-items:baseline;gap:6px;flex-wrap:wrap}.gengage-chat-grouping-card-name{font-weight:600;font-size:13px;color:var(--gengage-text-color, #1e293b)}.gengage-chat-grouping-card-desc{font-size:12px;color:var(--gengage-text-muted, #64748b)}.gengage-chat-grouping-card-labels{display:block;font-size:11px;color:var(--gengage-chat-text-secondary, #888);margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.gengage-chat-root--mobile .gengage-chat-grouping-card-img{display:none}.gengage-chat-root--mobile .gengage-chat-grouping-card-arrow{display:inline}.gengage-chat-suggested-search-cards{display:flex;flex-direction:column;gap:8px}.gengage-chat-suggested-search-card{display:flex;align-items:flex-start;gap:12px;padding:10px 14px;background:var(--gengage-surface-color, #f8fafc);border:1px solid var(--gengage-border-color, #e2e8f0);border-radius:10px;transition:background .15s ease,border-color .15s ease}.gengage-chat-suggested-search-card:hover{background:var(--gengage-hover-color, #f1f5f9);border-color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-suggested-search-card-img{width:40px;height:40px;border-radius:6px;object-fit:cover;flex-shrink:0}.gengage-chat-suggested-search-card-body{flex:1;min-width:0}.gengage-chat-suggested-search-card-name{font-weight:600;font-size:13px;color:var(--gengage-text-color, #1e293b)}.gengage-chat-suggested-search-card-desc{font-size:12px;color:var(--gengage-text-secondary, #475569);margin-top:2px}.gengage-chat-suggested-search-card-diff{font-size:11px;color:var(--gengage-text-muted, #64748b);margin-top:2px;font-style:italic}.gengage-chat-product-details-gallery{position:relative}.gengage-chat-product-details-gallery .gengage-chat-product-details-img{touch-action:pan-y}.gengage-chat-product-gallery-thumbs{display:flex;gap:8px;padding:10px 0 4px;overflow-x:auto;scrollbar-width:thin;justify-content:center;width:100%}.gengage-chat-product-gallery-thumb{width:56px;height:56px;object-fit:cover;border-radius:8px;border:2px solid transparent;cursor:pointer;flex-shrink:0;transition:border-color .15s ease;background:#fff}.gengage-chat-product-gallery-thumb:hover{border-color:var(--gengage-border-color, #cbd5e1)}.gengage-chat-product-gallery-thumb--active{border-color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-product-variants{margin-top:12px}.gengage-chat-product-variants-label{font-size:12px;font-weight:600;color:var(--gengage-text-muted, #64748b);margin-bottom:6px;text-transform:uppercase;letter-spacing:.5px}.gengage-chat-product-variants-list{display:flex;flex-wrap:wrap;gap:6px}.gengage-chat-product-variant-btn{padding:6px 12px;border:1px solid var(--gengage-border-color, #e2e8f0);border-radius:6px;background:var(--gengage-surface-color, #f8fafc);color:var(--gengage-text-color, #1e293b);font-size:12px;cursor:pointer;transition:background .15s ease,border-color .15s ease}.gengage-chat-product-variant-btn:hover{background:var(--gengage-hover-color, #f1f5f9);border-color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-product-grid-wrapper{display:flex;flex-direction:column;gap:8px}.gengage-chat-product-sort-toolbar{display:flex;gap:4px;padding:4px;background:var(--gengage-surface-color, #f8fafc);border-radius:8px;border:1px solid var(--gengage-border-color, #e2e8f0)}.gengage-chat-product-sort-btn{flex:1;padding:6px 10px;border:none;border-radius:6px;background:transparent;color:var(--gengage-text-muted, #64748b);font-size:12px;font-weight:500;cursor:pointer;transition:background .15s ease,color .15s ease}.gengage-chat-product-sort-btn:hover{background:var(--gengage-hover-color, #f1f5f9);color:var(--gengage-text-color, #1e293b)}.gengage-chat-product-sort-btn--active,.gengage-chat-product-sort-btn--active:hover{background:var(--gengage-primary-color, #3b82f6);color:#fff}.gengage-chat-product-sort-separator{width:1px;background:var(--gengage-border-color, #e2e8f0);margin:2px}.gengage-chat-comparison-toggle-btn{flex:none;padding:6px 10px;border:none;border-radius:6px;background:transparent;color:var(--gengage-text-muted, #64748b);font-size:12px;font-weight:500;cursor:pointer;transition:background .15s ease,color .15s ease;white-space:nowrap}.gengage-chat-comparison-toggle-btn:hover{background:var(--gengage-hover-color, #f1f5f9);color:var(--gengage-text-color, #1e293b)}.gengage-chat-comparison-toggle-btn--active,.gengage-chat-comparison-toggle-btn--active:hover{background:var(--gengage-primary-color, #3b82f6);color:#fff}.gengage-chat-comparison-select-wrapper{position:relative}.gengage-chat-comparison-checkbox{position:absolute;top:8px;left:8px;z-index:2;width:18px;height:18px;cursor:pointer;accent-color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-comparison-floating-btn{display:block;width:100%;margin-top:8px;padding:10px 16px;border:none;border-radius:8px;background:var(--gengage-primary-color, #3b82f6);color:#fff;font-size:14px;font-weight:600;cursor:pointer;transition:background .15s ease;text-align:center}.gengage-chat-comparison-floating-btn:hover{background:var(--gengage-primary-hover, #2563eb)}.gengage-chat-panel-topbar{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--_gengage-border-color);background:#f8fafc;min-height:44px;flex-shrink:0;position:sticky;top:0;z-index:3}.gengage-chat-panel-topbar-back,.gengage-chat-panel-topbar-forward{width:28px;height:28px;min-width:28px;padding:0;border:1px solid #d1d5db;border-radius:6px;background:transparent;color:#374151;font-size:14px;font-family:inherit;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s ease,border-color .15s ease,opacity .15s ease}.gengage-chat-panel-topbar-back:hover:not(:disabled),.gengage-chat-panel-topbar-forward:hover:not(:disabled){background:#f3f4f6;border-color:#9ca3af}.gengage-chat-panel-topbar-back:disabled,.gengage-chat-panel-topbar-forward:disabled{opacity:.3;cursor:default}.gengage-chat-panel-topbar-title{flex:1;font-size:14px;font-weight:600;color:#1f2937;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:center}@keyframes gengage-typewriter-fade-in{0%{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}.gengage-chat-typewriter-block{display:block;animation:gengage-typewriter-fade-in .15s ease both}@media(prefers-reduced-motion:reduce){.gengage-chat-typewriter-block{animation:none}}.gengage-product-mention{color:var(--gengage-primary-color, #3b82f6);text-decoration:none;cursor:pointer;font-weight:500;border-bottom:1px dashed var(--gengage-primary-color, #3b82f6);transition:border-color .15s}.gengage-product-mention:hover{border-bottom-style:solid}@keyframes gengage-skeleton-pulse{0%,to{opacity:.4}50%{opacity:.8}}.gengage-chat-panel-skeleton-block{animation:gengage-skeleton-pulse 1.5s ease-in-out infinite}@media(prefers-reduced-motion:reduce){.gengage-chat-panel-skeleton-block{animation:none}}.gengage-chat-input-chips{display:flex;gap:6px;padding:4px 12px 2px;flex-wrap:wrap}.gengage-chat-input-chip{display:inline-flex;align-items:center;padding:4px 10px;border-radius:12px;border:1px solid var(--_gengage-border-color);background:#f9fafb;color:#374151;font-size:12px;font-weight:500;font-family:inherit;cursor:pointer;transition:background .12s,border-color .12s;white-space:nowrap}.gengage-chat-input-chip:hover{background:#f3f4f6;border-color:#d1d5db}.gengage-chat-icon{width:14px;height:14px;flex-shrink:0}.gengage-chat-input-chip-icon,.gengage-chat-pill-icon{display:inline-flex;align-items:center;margin-right:4px}.gengage-chat-product-card-img-wrapper,.gengage-chat-product-details-img-wrap{position:relative;overflow:hidden}.gengage-chat-product-card-discount-badge{position:absolute;top:6px;left:6px;padding:2px 6px;border-radius:4px;background:var(--_gengage-discount-color);color:#fff;font-size:11px;font-weight:700;line-height:1.3;z-index:1}.gengage-chat-product-card-stock{font-size:11px;font-weight:600;margin-top:2px}.gengage-chat-product-card-stock.is-in-stock{color:var(--_gengage-success-color)}.gengage-chat-product-card-stock.is-out-of-stock{color:#dc2626}.gengage-chat-find-similar-pill{position:absolute;top:8px;right:8px;opacity:0;pointer-events:none;transition:opacity .2s ease;padding:4px 10px;font-size:11px;font-weight:500;font-family:inherit;border:none;border-radius:12px;background:var(--gengage-chat-pill-bg, rgba(0, 0, 0, .7));color:var(--gengage-chat-pill-text, #fff);cursor:pointer;white-space:nowrap;z-index:2}.gengage-chat-product-card-img-wrapper:hover .gengage-chat-find-similar-pill,.gengage-chat-product-details-img-wrap:hover .gengage-chat-find-similar-pill{opacity:1;pointer-events:auto}.gengage-chat-favorite-btn{position:absolute;top:8px;right:8px;background:#ffffffe6;border:none;border-radius:50%;width:28px;height:28px;display:flex;align-items:center;justify-content:center;cursor:pointer;color:var(--gengage-text-secondary, #64748b);z-index:3;transition:color .2s;padding:0}.gengage-chat-favorite-btn:hover,.gengage-chat-favorite-btn--active{color:var(--gengage-accent-primary, #ef4444)}.gengage-chat-product-card-promos,.gengage-chat-product-details-promos{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px}.gengage-chat-product-card-promo-badge,.gengage-chat-product-details-promo-badge{display:inline-block;padding:2px 6px;font-size:10px;font-weight:500;border-radius:4px;background:var(--gengage-chat-promo-bg, #e8f5e9);color:var(--gengage-chat-promo-text, #2e7d32);white-space:nowrap}.gengage-chat-thumbnails-column{position:absolute;right:4px;top:50%;transform:translateY(-50%);display:flex;flex-direction:column;gap:4px;z-index:2;pointer-events:auto}.gengage-chat-thumbnail-btn{display:flex;align-items:center;justify-content:center;width:40px;height:40px;padding:0;border:2px solid #e5e7eb;border-radius:6px;background:#fff;cursor:pointer;overflow:hidden;transition:border-color .15s ease}.gengage-chat-thumbnail-btn:hover{border-color:var(--gengage-primary-color, #3b82f6)}.gengage-chat-thumbnail-img{width:100%;height:100%;object-fit:cover}.gengage-chat-choice-prompter{position:absolute;bottom:12px;right:12px;width:200px;padding:12px 14px;background:#fff;border:1px solid var(--_gengage-border-color);border-radius:10px;box-shadow:0 4px 12px #0000001a;z-index:10;animation:gengage-choice-prompter-in .2s ease}@keyframes gengage-choice-prompter-in{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.gengage-chat-choice-prompter-heading{font-size:13px;font-weight:600;color:#1f2937;margin-bottom:4px}.gengage-chat-choice-prompter-suggestion{font-size:12px;color:#6b7280;margin-bottom:10px;line-height:1.4}.gengage-chat-choice-prompter-cta{display:block;width:100%;padding:6px 12px;border:none;border-radius:6px;background:var(--gengage-primary-color, #3b82f6);color:#fff;font-size:12px;font-weight:600;font-family:inherit;cursor:pointer;text-align:center;transition:opacity .15s ease}.gengage-chat-choice-prompter-cta:hover{opacity:.9}.gengage-chat-choice-prompter-dismiss{position:absolute;top:4px;right:6px;padding:2px 6px;border:none;background:none;color:#6b7280;font-size:16px;cursor:pointer;line-height:1}.gengage-chat-choice-prompter-dismiss:hover{color:#6b7280}@media(prefers-reduced-motion:reduce){.gengage-chat-choice-prompter{animation:none}}.gengage-chat-pros-cons{padding:12px 14px;background:#f8fafc;border-radius:8px;margin:8px 0}.gengage-chat-pros-cons-heading{margin:0 0 10px;font-size:14px;font-weight:600;color:#0f172a}.gengage-chat-pros-cons-list{list-style:none;margin:0 0 8px;padding:0}.gengage-chat-pros-cons-list:last-child{margin-bottom:0}.gengage-chat-pros-cons-item{display:flex;align-items:flex-start;gap:8px;padding:4px 0;font-size:13px;line-height:1.5;color:#334155}.gengage-chat-pros-cons-icon{flex-shrink:0;width:18px;height:18px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;border-radius:50%}.gengage-chat-pros-cons-icon--pro{color:#16a34a;background:#dcfce7}.gengage-chat-pros-cons-icon--con{color:#dc2626;background:#fee2e2}.gengage-chat-categories{display:flex;flex-direction:column;gap:8px}.gengage-chat-categories-tabs{display:flex;gap:4px;overflow-x:auto;padding:4px 0;-webkit-overflow-scrolling:touch}.gengage-chat-categories-tab{padding:6px 14px;border:1px solid var(--gengage-border-color, #e5e7eb);border-radius:20px;background:var(--gengage-bg, #fff);color:var(--gengage-text, #374151);cursor:pointer;white-space:nowrap;font-size:13px;transition:background .15s,color .15s}.gengage-chat-categories-tab:hover{background:var(--gengage-bg-hover, #f3f4f6)}.gengage-chat-categories-tab--active{background:var(--gengage-primary, #2563eb);color:#fff;border-color:var(--gengage-primary, #2563eb)}.gengage-chat-categories-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:8px}.gengage-chat-categories-filter-tags{display:flex;gap:6px;flex-wrap:wrap;margin-top:4px}.gengage-chat-categories-filter-tag{padding:4px 10px;border:1px solid var(--gengage-border-color, #e5e7eb);border-radius:14px;background:var(--gengage-bg, #fff);color:var(--gengage-text-secondary, #6b7280);font-size:12px;cursor:pointer;transition:background .15s}.gengage-chat-categories-filter-tag:hover{background:var(--gengage-bg-hover, #f3f4f6)}.gengage-chat-product-grid-view-more{display:block;width:100%;padding:10px;margin-top:8px;border:1px solid var(--gengage-border-color, #e5e7eb);border-radius:8px;background:var(--gengage-bg, #fff);color:var(--gengage-primary, #2563eb);font-size:14px;font-weight:500;cursor:pointer;text-align:center;transition:background .15s;grid-column:1 / -1}.gengage-chat-product-grid-view-more:hover{background:var(--gengage-bg-hover, #f3f4f6)}.gengage-chat-product-grid--mobile{display:flex;overflow-x:auto;gap:8px;padding:8px 0;-webkit-overflow-scrolling:touch}.gengage-chat-product-grid--mobile .gengage-chat-product-card{min-width:160px;max-width:180px;flex-shrink:0}.gengage-chat-comparison--mobile{overflow-x:auto;-webkit-overflow-scrolling:touch}.gengage-chat-comparison--mobile .gengage-chat-comparison-table{min-width:480px}.gengage-chat-comparison-key-differences{margin-top:12px;padding:12px;background:var(--gengage-bg-secondary, #f9fafb);border-radius:8px}.gengage-chat-comparison-key-differences h4{margin:0 0 8px;font-size:14px;font-weight:600;color:var(--gengage-text, #374151)}.gengage-chat-comparison-key-differences-content{font-size:13px;color:var(--gengage-text-secondary, #6b7280);line-height:1.5}.gengage-chat-comparison-key-differences-content ul{margin:0;padding-left:18px}.gengage-chat-comparison-key-differences-content li{margin-bottom:4px}.gengage-chat-product-details-similars-heading{margin:16px 0 8px;font-size:15px;font-weight:600;color:var(--gengage-text, #374151)}.gengage-chat-product-details-similars{margin-top:8px}.gengage-chat-handoff-notice{display:flex;flex-direction:column;align-items:center;gap:6px;padding:16px;margin:8px 0;background:#fef3c7;border:1px solid #fcd34d;border-radius:8px;text-align:center}.gengage-chat-handoff-notice-icon{font-size:24px}.gengage-chat-handoff-notice-heading{margin:0;font-size:14px;font-weight:600;color:#92400e}.gengage-chat-handoff-notice-summary{margin:0;font-size:13px;line-height:1.5;color:#78350f}.gengage-qty-stepper{display:inline-flex;align-items:center;gap:0;border:1px solid #d1d5db;border-radius:8px;overflow:hidden;background:#fff}.gengage-qty-btn{width:var(--_gengage-qty-btn-size);height:var(--_gengage-qty-btn-size);border:none;background:transparent;color:#374151;font-size:14px;font-weight:600;font-family:inherit;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background-color .12s}.gengage-qty-btn:hover:not(:disabled){background:#f3f4f6}.gengage-qty-btn:disabled{opacity:.35;cursor:default}.gengage-qty-value{min-width:24px;text-align:center;font-size:13px;font-weight:600;color:#1f2937;-webkit-user-select:none;user-select:none}.gengage-qty-submit{border:none;border-left:1px solid #d1d5db;background:var(--_gengage-success-color);color:#fff;font-size:13px;font-weight:700;font-family:inherit;cursor:pointer;padding:6px 12px;transition:filter .12s ease,transform .12s ease}.gengage-qty-submit:hover{filter:brightness(1.08)}.gengage-qty-submit:active{transform:translateY(1px)}.gengage-qty-stepper--compact{border-radius:14px;box-shadow:0 2px 6px #0000001f}.gengage-qty-stepper--compact .gengage-qty-btn{width:var(--_gengage-qty-btn-size-compact);height:var(--_gengage-qty-btn-size-compact);font-size:12px}.gengage-qty-stepper--compact .gengage-qty-value{min-width:18px;font-size:12px}.gengage-qty-stepper--compact .gengage-qty-submit{padding:4px 8px;font-size:13px;border-radius:0 14px 14px 0}.gengage-chat-product-details-atc-stepper{border-radius:10px}.gengage-chat-product-details-atc-stepper .gengage-qty-btn{width:32px;height:32px}.gengage-chat-product-details-atc-stepper .gengage-qty-value{min-width:28px;font-size:14px}.gengage-chat-product-details-atc-stepper .gengage-qty-submit{padding:8px 18px;font-size:14px;border-radius:0 10px 10px 0}.gengage-chat-product-details-share{display:inline-flex;align-items:center;justify-content:center;width:36px;height:36px;border:1px solid #d1d5db;border-radius:10px;background:transparent;color:#6b7280;cursor:pointer;transition:color .12s,border-color .12s,background-color .12s;position:relative;flex-shrink:0}.gengage-chat-product-details-share:hover{color:var(--gengage-primary-color, #3b82f6);border-color:var(--gengage-primary-color, #3b82f6);background:#f0f7ff}.gengage-chat-product-details-share:before{content:attr(aria-label);position:absolute;bottom:calc(100% + 6px);left:50%;transform:translate(-50%);padding:4px 8px;border-radius:4px;background:#1e293b;color:#fff;font-size:11px;font-weight:500;white-space:nowrap;pointer-events:none;opacity:0;transition:opacity .15s ease;z-index:2}.gengage-chat-product-details-share:hover:before{opacity:1}.gengage-chat-product-details-share--copied:after{content:"✓";position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:var(--_gengage-success-color);color:#fff;border-radius:10px;font-size:16px;font-weight:700}.gengage-chat-launcher:focus-visible,.gengage-chat-close:focus-visible,.gengage-chat-header-btn:focus-visible,.gengage-chat-header-powered:focus-visible,.gengage-chat-proactive-accept:focus-visible,.gengage-chat-proactive-dismiss:focus-visible,.gengage-chat-send:focus-visible,.gengage-chat-action-btn:focus-visible,.gengage-chat-pill:focus-visible,.gengage-chat-input-chip:focus-visible,.gengage-chat-pills-arrow:focus-visible,.gengage-chat-error-retry:focus-visible,.gengage-chat-product-card-cta:focus-visible,.gengage-chat-product-details-cta:focus-visible,.gengage-chat-product-details-atc:focus-visible,.gengage-chat-product-detail-tab:focus-visible,.gengage-chat-panel-divider-toggle:focus-visible,.gengage-chat-panel-topbar-back:focus-visible,.gengage-chat-panel-topbar-forward:focus-visible,.gengage-chat-rollback-btn:focus-visible,.gengage-chat-ai-toppick-cta:focus-visible,.gengage-chat-comparison-view-btn:focus-visible,.gengage-chat-comparison-toggle-btn:focus-visible,.gengage-chat-comparison-floating-btn:focus-visible,.gengage-chat-comparison-checkbox:focus-visible,.gengage-chat-product-sort-btn:focus-visible,.gengage-chat-product-variant-btn:focus-visible,.gengage-chat-product-gallery-thumb:focus-visible,.gengage-chat-thumbnail-btn:focus-visible,.gengage-chat-find-similar-pill:focus-visible,.gengage-chat-favorite-btn:focus-visible,.gengage-chat-attach-btn:focus-visible,.gengage-chat-mic-btn:focus-visible,.gengage-chat-attachment-remove:focus-visible,.gengage-chat-kvkk-dismiss:focus-visible,.gengage-chat-choice-prompter-cta:focus-visible,.gengage-chat-choice-prompter-dismiss:focus-visible,.gengage-chat-categories-tab:focus-visible,.gengage-chat-categories-filter-tag:focus-visible,.gengage-chat-product-grid-view-more:focus-visible,.gengage-chat-product-details-share:focus-visible,.gengage-qty-btn:focus-visible,.gengage-qty-submit:focus-visible{outline:2px solid var(--gengage-primary-color, #3b82f6);outline-offset:2px}@media(max-width:768px){.gengage-chat-choice-prompter{left:12px;right:12px;width:auto;max-width:none;bottom:calc(var(--_gengage-chat-launcher-bottom) + var(--_gengage-chat-launcher-size) + 12px + env(safe-area-inset-bottom,0px))}.gengage-chat-product-sort-btn,.gengage-chat-comparison-toggle-btn{min-height:40px}.gengage-chat-input-chip{min-height:40px;padding:8px 12px}.gengage-chat-choice-prompter-dismiss{width:32px;height:32px}.gengage-chat-panel-divider-toggle{min-height:44px}.gengage-chat-product-details-atc-stepper .gengage-qty-btn{width:44px;height:44px}.gengage-chat-product-details-atc-stepper .gengage-qty-submit,.gengage-qty-stepper--compact .gengage-qty-submit{min-height:44px}.gengage-qty-stepper--compact .gengage-qty-submit{min-width:44px;padding:0 10px}.gengage-qty-stepper--compact .gengage-qty-btn{width:44px;height:44px;font-size:14px}.gengage-qty-stepper--compact .gengage-qty-value{min-width:24px;font-size:13px}.gengage-chat-product-card-cta,.gengage-chat-choice-prompter-cta,.gengage-chat-product-grid-view-more{min-height:44px;display:flex;align-items:center;justify-content:center}.gengage-chat-panel-topbar-back,.gengage-chat-panel-topbar-forward,.gengage-chat-favorite-btn,.gengage-chat-product-details-share{width:44px;height:44px}}', Ka = M({
3172
- role: we(["user", "assistant"]),
3173
- content: v(),
3174
- timestamp: Q().optional()
3175
- }), Wa = M({
3176
- sku: v(),
3177
- name: v(),
3178
- imageUrl: v().url().optional(),
3179
- price: v().optional(),
3180
- originalPrice: v().optional(),
3181
- url: v().url(),
3182
- /** Override CTA label (default: "View product") */
3183
- ctaLabel: v().optional()
3184
- }), Ya = M({
3185
- buttons: D(
3186
- M({
3187
- label: v(),
3188
- /** Opaque action payload forwarded to the backend when clicked. */
3189
- action: M({
3190
- title: v(),
3191
- type: v(),
3192
- payload: K().optional()
3193
- })
3194
- })
3195
- )
3196
- }), Qa = M({}), Xa = M({
3197
- label: v().optional()
3198
- }), xe = M({
3199
- sku: v(),
3200
- name: v(),
3201
- price: v(),
3202
- imageUrl: v().optional(),
3203
- rating: Q().optional(),
3204
- reviewCount: Q().optional()
3205
- }), Ja = M({
3206
- recommended: xe,
3207
- products: D(xe),
3208
- attributes: D(
3209
- M({
3210
- label: v(),
3211
- values: D(v())
3212
- })
3213
- ),
3214
- highlights: D(v()),
3215
- specialCases: D(v()).optional(),
3216
- recommendedText: v().optional(),
3217
- winnerHits: ae(
3218
- v(),
3219
- M({
3220
- positive: D(v()).optional(),
3221
- negative: D(v()).optional()
3222
- })
3223
- ).optional(),
3224
- productActions: ae(
3225
- v(),
3226
- M({
3227
- title: v(),
3228
- type: v(),
3229
- payload: K().optional()
3230
- })
3231
- ).optional()
3232
- }), Za = M({
3233
- label: v(),
3234
- sentiment: we(["positive", "negative", "neutral"]).optional()
3235
- }), en = M({
3236
- product: ae(v(), K()),
3237
- role: v().optional(),
3238
- reason: v().optional(),
3239
- labels: D(Za).optional(),
3240
- expertQualityScore: Q().optional(),
3241
- reviewHighlight: v().optional(),
3242
- action: M({
3243
- title: v(),
3244
- type: v(),
3245
- payload: K().optional()
3246
- }).optional()
3247
- }), tn = M({
3248
- suggestions: D(en)
3249
- }), an = M({
3250
- title: v().optional(),
3251
- text: v().optional(),
3252
- reviewCount: v().optional(),
3253
- action: M({ title: v(), type: v(), payload: K().optional() })
3254
- }), nn = M({
3255
- entries: D(
3256
- M({
3257
- name: v(),
3258
- image: v().optional(),
3259
- description: v().optional(),
3260
- action: M({ title: v(), type: v(), payload: K().optional() })
3261
- })
3262
- )
3263
- }), on = M({
3264
- entries: D(
3265
- M({
3266
- shortName: v(),
3267
- detailedMessage: v().optional(),
3268
- whyDifferent: v().optional(),
3269
- image: v().optional(),
3270
- action: M({ title: v(), type: v(), payload: K().optional() })
3271
- })
3272
- )
3273
- }), Be = M({
3274
- title: v(),
3275
- type: v(),
3276
- payload: K().optional()
3277
- }), rn = M({
3278
- name: v().optional(),
3279
- variant_name: v().optional(),
3280
- sku: v().optional(),
3281
- price: re([Q(), v()]).optional()
3282
- }), sn = M({
3283
- product: M({
3284
- sku: v().optional(),
3285
- name: v().optional(),
3286
- images: D(v()).optional(),
3287
- imageUrl: v().optional(),
3288
- rating: Q().optional(),
3289
- reviewCount: Q().optional(),
3290
- price: v().optional(),
3291
- originalPrice: v().optional(),
3292
- price_async: oe().optional(),
3293
- inStock: oe().optional(),
3294
- promotions: D(v()).optional(),
3295
- variants: D(rn).optional(),
3296
- url: v().optional(),
3297
- cartCode: v().optional(),
3298
- description: v().optional(),
3299
- specifications: re([ae(v(), v()), D(M({ key: v(), value: v() }))]).optional()
3300
- }).optional(),
3301
- action: Be.optional()
3302
- }), cn = M({
3303
- endOfList: oe().optional()
3304
- }), ln = M({
3305
- review_class: v().optional(),
3306
- review_text: v().optional(),
3307
- review_rating: re([v(), Q()]).optional(),
3308
- review_tag: v().optional()
3309
- }), gn = M({
3310
- reviews: D(ln).optional()
3311
- }), dn = M({
3312
- productName: v().optional(),
3313
- pros: D(v()).optional(),
3314
- cons: D(v()).optional()
3315
- }), pn = M({
3316
- groups: D(
3317
- M({
3318
- groupName: v(),
3319
- products: D(ae(v(), K())).optional()
3320
- })
3321
- ).optional(),
3322
- filterTags: D(
3323
- M({
3324
- title: v(),
3325
- action: Be.optional()
3326
- })
3327
- ).optional()
3328
- }), hn = M({
3329
- summary: v().optional(),
3330
- products_discussed: D(v()).optional(),
3331
- user_sentiment: v().optional()
3332
- }), xn = {
3333
- components: {
3334
- MessageBubble: {
3335
- schema: Ka,
3336
- description: "A single chat message bubble for user or assistant turns."
3337
- },
3338
- ProductCard: {
3339
- schema: Wa,
3340
- description: "A product card rendered inline in the chat stream."
3341
- },
3342
- ActionButtons: {
3343
- schema: Ya,
3344
- description: "A horizontal row of quick-reply action buttons."
3345
- },
3346
- TypingIndicator: {
3347
- schema: Qa,
3348
- description: "An animated indicator shown while the assistant is typing."
3349
- },
3350
- Divider: {
3351
- schema: Xa,
3352
- description: "A horizontal rule with an optional label."
3353
- },
3354
- ComparisonTable: {
3355
- schema: Ja,
3356
- description: "A product comparison table with recommended pick, attribute rows, and highlights."
3357
- },
3358
- AITopPicks: {
3359
- schema: tn,
3360
- description: "Rich AI-curated product suggestion cards with roles, sentiment labels, scores, and review quotes."
3361
- },
3362
- GroundingReviewCard: {
3363
- schema: an,
3364
- description: "A card showing review grounding data with review count and CTA."
3365
- },
3366
- AIGroupingCards: {
3367
- schema: nn,
3368
- description: "Category grouping cards with images and labels for product discovery."
3369
- },
3370
- AISuggestedSearchCards: {
3371
- schema: on,
3372
- description: "Suggested search cards with images, descriptions, and differentiation."
3373
- },
3374
- ProductDetailsPanel: {
3375
- schema: sn,
3376
- description: "Full product detail view with images, specs, variants, and purchase actions."
3377
- },
3378
- ProductGrid: {
3379
- schema: cn,
3380
- description: 'A scrollable grid of ProductCard children with optional "more" pagination.'
3381
- },
3382
- ReviewHighlights: {
3383
- schema: gn,
3384
- description: "A list of highlighted customer reviews with sentiment and ratings."
3385
- },
3386
- ProsAndCons: {
3387
- schema: dn,
3388
- description: "A pros and cons list for a product."
3389
- },
3390
- CategoriesContainer: {
3391
- schema: pn,
3392
- description: "Tabbed product groups with optional filter tag buttons."
3393
- },
3394
- HandoffNotice: {
3395
- schema: hn,
3396
- description: "A notice shown when the conversation is escalated to a human agent."
3397
- }
3398
- }
3399
- };
3400
- function un(o) {
3401
- return o.length > 120 ? !1 : /^[a-zA-Z0-9#(),.\s%/\-]+$/.test(o);
3402
- }
3403
- function te(o) {
3404
- return typeof o == "object" && o !== null && typeof o.type == "string";
3405
- }
3406
- class mn extends qe {
3407
- constructor() {
3408
- super(...arguments), this._shadow = null, this._rootEl = null, this._launcher = null, this._drawer = null, this._bridge = null, this._activityTracker = null, this._heartbeat = null, this._proactiveShown = !1, this._drawerVisible = !1, this._messages = [], this._currentMessageId = 0, this._abortControllers = /* @__PURE__ */ new Set(), this._currentThreadId = null, this._lastThreadId = null, this._chatCreatedAt = "", this._lastBackendContext = null, this._productSort = { type: "related" }, this._comparisonSelectMode = !1, this._comparisonSelectedSkus = [], this._thumbnailEntries = [], this._choicePrompterEl = null, this._openState = "full", this._mobileBreakpoint = 768, this._isMobileViewport = !1, this._pdpLaunched = !1, this._pdpPrimingInFlight = !1, this._queuedUserMessages = [], this._productContextUnavailableSku = null, this._i18n = ce, this._extendedModeManager = null, this._activeTypewriter = null, this._activeTtsHandle = null, this._activeRequestThreadId = null, this._skuToProductItem = {}, this._conversationMode = null, this._initComplete = !1, this._pendingActions = [], this._bridgeContext = null, this._cartQuantity = null, this._threadsWithFirstBot = /* @__PURE__ */ new Set(), this._panel = null, this._session = null, this._eventCallbacks = /* @__PURE__ */ new Map();
3409
- }
3410
- async onInit(e) {
3411
- this._i18n = this._resolveI18n(e), this._chatCreatedAt = (/* @__PURE__ */ new Date()).toISOString(), this._shadow = this.root.attachShadow({ mode: "open" });
3412
- const t = document.createElement("style");
3413
- t.textContent = Ga, this._shadow.appendChild(t);
3414
- const a = document.createElement("div");
3415
- a.className = "gengage-chat-root", this._rootEl = a, this._shadow.appendChild(a);
3416
- const n = e.variant ?? "floating";
3417
- if (n === "floating") {
3418
- const p = {
3419
- onClick: () => this.open(),
3420
- ariaLabel: this._i18n.openButton
3421
- };
3422
- e.launcherSvg !== void 0 && (p.svgMarkup = e.launcherSvg), e.hideMobileLauncher !== void 0 && (p.hideMobile = e.hideMobileLauncher), e.mobileBreakpoint !== void 0 && (p.mobileBreakpoint = e.mobileBreakpoint), e.launcherTooltip !== void 0 && (p.tooltip = e.launcherTooltip), this._launcher = Ut(p), a.appendChild(this._launcher.container);
3423
- }
3424
- n === "overlay" && a.classList.add("gengage-chat--overlay");
3425
- const i = document.createElement("div");
3426
- a.appendChild(i), this._drawer = new Dt(i, {
3427
- i18n: this._i18n,
3428
- onSend: (p, d) => this._sendMessage(p, d),
3429
- onClose: () => this.close(),
3430
- onAttachment: (p) => this._handleAttachment(p),
3431
- onPanelToggle: () => {
3432
- this._drawer?.persistPanelState(e.accountId);
3433
- },
3434
- onRollback: (p) => this._handleRollback(p),
3435
- onPanelBack: () => this._panel?.navigateBack(),
3436
- onPanelForward: () => this._panel?.navigateForward(),
3437
- headerTitle: e.headerTitle,
3438
- headerAvatarUrl: e.headerAvatarUrl,
3439
- headerBadge: e.headerBadge,
3440
- headerCartUrl: e.headerCartUrl,
3441
- headerFavoritesToggle: e.headerFavoritesToggle,
3442
- onFavoritesClick: () => {
3443
- He(), e.onFavoritesClick?.();
3444
- },
3445
- onThumbnailClick: (p) => this._rollbackToThread(p),
3446
- onLinkClick: (p) => {
3447
- this._saveSessionAndOpenURL(p);
3448
- },
3449
- voiceEnabled: e.voiceEnabled,
3450
- voiceLang: e.locale ? `${e.locale.split("-")[0] ?? "tr"}-${(e.locale.split("-")[1] ?? e.locale.split("-")[0] ?? "TR").toUpperCase()}` : void 0
3451
- }), this._extendedModeManager = new Ra({
3452
- onChange: (p) => this._panel?.notifyExtension(p),
3453
- productDetailsInPanel: e.isDemoWebsite ?? !1
3454
- }), this._panel = new Ua({
3455
- drawer: () => this._drawer,
3456
- shadow: () => this._shadow,
3457
- currentThreadId: () => this._currentThreadId,
3458
- bridge: () => this._bridge,
3459
- extendedModeManager: () => this._extendedModeManager,
3460
- i18n: () => this._i18n,
3461
- rollbackToThread: (p) => this._rollbackToThread(p)
3462
- }), n !== "inline" && this._drawer.getElement().classList.add("gengage-chat-drawer--hidden");
3463
- const s = this._drawer.restorePanelState(e.accountId), l = e.panelMode ?? "auto";
3464
- l === "collapsed" ? this._drawer.setPanelCollapsed(!0) : l === "expanded" ? this._drawer.setForceExpanded() : s || this._drawer.expandPanel();
3465
- const r = sessionStorage.getItem("gengage_restore_session_id"), c = sessionStorage.getItem("gengage_restore_sku"), g = !!(r && c);
3466
- g && (sessionStorage.removeItem("gengage_restore_session_id"), sessionStorage.removeItem("gengage_restore_sku"));
3467
- try {
3468
- const p = new za();
3469
- await p.open(), this._session = new fe(p), await this._restoreFromIndexedDB(g);
3470
- } catch {
3471
- this._session = new fe(null);
3472
- }
3473
- this._registerPublicAPI(), e.mobileInitialState !== void 0 && (this._openState = e.mobileInitialState), this._mobileBreakpoint = e.mobileBreakpoint ?? 768, this._syncViewportState();
3474
- const h = () => this._syncViewportState();
3475
- if (window.addEventListener("resize", h, { passive: !0 }), this.addCleanup(() => window.removeEventListener("resize", h)), window.visualViewport) {
3476
- const p = () => {
3477
- if (!this._drawerVisible || !this._isMobileViewport) return;
3478
- const d = this._drawer?.getElement();
3479
- if (!d) return;
3480
- const f = window.innerHeight - (window.visualViewport?.height ?? window.innerHeight);
3481
- d.style.setProperty("--gengage-keyboard-offset", `${Math.max(0, f)}px`);
3482
- };
3483
- window.visualViewport.addEventListener("resize", p), this.addCleanup(() => window.visualViewport?.removeEventListener("resize", p));
3484
- }
3485
- n === "inline" && (this._drawerVisible = !0, this.isVisible = !0, this._applyOpenStateClasses()), this._bridge = new dt({
3486
- namespace: "chat",
3487
- onMessage: (p) => this._handleBridgeMessage(p)
3488
- }), this._activityTracker = new Ht({
3489
- idleThresholdMs: e.proactiveDelayMs ?? 3e4,
3490
- onActivity: (p) => {
3491
- if (p.type === "idle" && !this._proactiveShown && !this._drawerVisible) {
3492
- const d = e.proactiveMinScrollDepth ?? 0;
3493
- if (d > 0 && (this._activityTracker?.maxScrollDepth ?? 0) < d * 100)
3494
- return;
3495
- try {
3496
- if (sessionStorage.getItem("gengage_proactive_shown")) return;
3497
- } catch {
3498
- }
3499
- if (this._isProactiveCooldownActive()) return;
3500
- e.proactiveFetchActions ? this._fetchAndShowProactive() : e.proactiveMessage && this._showProactivePopup(e.proactiveMessage);
3501
- }
3502
- }
3503
- }), this.addCleanup(() => this._activityTracker?.destroy()), e.enableHeartbeat && (this._heartbeat = new jt({
3504
- middlewareUrl: e.middlewareUrl,
3505
- accountId: e.accountId,
3506
- sessionId: e.session?.sessionId ?? "",
3507
- locale: e.locale ?? "tr",
3508
- intervalMs: e.heartbeatIntervalMs ?? 3e4,
3509
- getPageType: () => this.config.pageContext?.pageType ?? "other",
3510
- getCurrentSku: () => this.config.pageContext?.sku ?? "",
3511
- onMessage: (p) => {
3512
- if (!this._proactiveShown && !this._drawerVisible && p.message) {
3513
- const d = [];
3514
- if (p.suggested_actions && Array.isArray(p.suggested_actions))
3515
- for (const f of p.suggested_actions)
3516
- f.title && te(f.requestDetails) && d.push({
3517
- title: f.title,
3518
- onSelect: () => {
3519
- this.openWithAction(f.requestDetails);
3520
- }
3521
- });
3522
- this._showProactivePopup(p.message, d.length > 0 ? d : void 0);
3523
- }
3524
- }
3525
- }), this._heartbeat.start(), this.addCleanup(() => this._heartbeat?.destroy())), this._lastSku = this.config.pageContext?.sku, this._initComplete = !0;
3526
- for (const p of this._pendingActions)
3527
- this._sendAction(p.action, p.options);
3528
- this._pendingActions = [], j("gengage:chat:ready", {}), Fe("chat"), e.onReady?.();
3529
- }
3530
- onUpdate(e) {
3531
- e.sku !== void 0 && e.sku !== this._lastSku && (this._lastSku = e.sku, this._resetForNewPage());
3532
- }
3533
- onShow() {
3534
- this._showDrawer(), this.emit("open"), j("gengage:chat:open", { state: this._openState }), Oe("chat"), this.config.onOpen?.(), !this._pdpLaunched && this.config.pageContext?.sku && (this._pdpLaunched = !0, this._pdpPrimingInFlight = !0, this._sendAction(
3535
- {
3536
- title: "",
3537
- type: "launchSingleProduct",
3538
- payload: { sku: this.config.pageContext.sku }
3539
- },
3540
- { silent: !0, isPdpPrime: !0 }
3541
- ));
3542
- }
3543
- onHide() {
3544
- (this.config.variant ?? "floating") === "floating" && (this.root.style.display = ""), this._hideDrawer(), this.emit("close"), j("gengage:chat:close", {}), this.config.onClose?.();
3545
- }
3546
- onDestroy() {
3547
- this._abortControllers.forEach((e) => e.abort()), this._abortControllers.clear(), this._activeTypewriter?.cancel(), this._activeTypewriter = null, this._activeTtsHandle?.stop(), this._activeTtsHandle = null, this._bridge?.destroy(), this._bridge = null, this._extendedModeManager = null, this._panel?.destroy(), this._panel = null, this._session?.close(), this._session = null, window.gengage && delete window.gengage.chat, this._shadow && (this._shadow.innerHTML = "", this._shadow = null), this._rootEl = null;
3548
- }
3549
- // ---------------------------------------------------------------------------
3550
- // Public API
3551
- // ---------------------------------------------------------------------------
3552
- open(e) {
3553
- e?.state !== void 0 && (this._openState = e.state, this._drawerVisible && this._applyOpenStateClasses()), this.show(), e?.initialMessage !== void 0 && this._sendMessage(e.initialMessage);
3554
- }
3555
- openWithAction(e, t) {
3556
- t?.sku !== void 0 && this.update({ sku: t.sku }), this._pdpLaunched = !0, t?.state !== void 0 ? this._openState = t.state : this._isMobileViewport && (this._openState = "half"), this.show(), this._drawerVisible && this._applyOpenStateClasses(), this._sendAction(e);
3557
- }
3558
- /** Send a user message programmatically (same flow as typing + submit). */
3559
- sendMessage(e) {
3560
- this._sendMessage(e);
3561
- }
3562
- /** Send a backend action programmatically. */
3563
- sendAction(e, t) {
3564
- this._sendAction(e, t);
3565
- }
3566
- close() {
3567
- this.hide();
3568
- }
3569
- saveSession(e, t) {
3570
- sessionStorage.setItem("gengage_restore_session_id", e), sessionStorage.setItem("gengage_restore_sku", t);
3571
- }
3572
- get isOpen() {
3573
- return this._drawerVisible;
3574
- }
3575
- /**
3576
- * Register a callback for a GA4 event name (e.g. 'gengage-cart-add').
3577
- * The callback receives the event detail and should return true (success) or false (failure).
3578
- * For add-to-cart, failure triggers an error message in the chat.
3579
- * @returns unsubscribe function
3580
- */
3581
- addCallback(e, t) {
3582
- let a = this._eventCallbacks.get(e);
3583
- return a || (a = /* @__PURE__ */ new Set(), this._eventCallbacks.set(e, a)), a.add(t), () => {
3584
- a.delete(t), a.size === 0 && this._eventCallbacks.delete(e);
3585
- };
3586
- }
3587
- // ---------------------------------------------------------------------------
3588
- // Private
3589
- // ---------------------------------------------------------------------------
3590
- /** Reset all chat state when navigating to a different SKU/page. */
3591
- _resetForNewPage() {
3592
- this._abortControllers.forEach((e) => e.abort()), this._abortControllers.clear(), this._activeTypewriter?.cancel(), this._activeTypewriter = null, this._activeTtsHandle?.stop(), this._activeTtsHandle = null, this._messages.length = 0, this._drawer?.clearMessages(), this._drawer?.clearPanel(), this._panel.snapshots.clear(), this._panel.threads = [], this._thumbnailEntries = [], this._drawer?.setThumbnails([]), this._comparisonSelectMode = !1, this._comparisonSelectedSkus = [], this._currentThreadId = null, this._lastThreadId = null, this._lastBackendContext = null, this._chatCreatedAt = (/* @__PURE__ */ new Date()).toISOString(), this._pdpLaunched = !1, this._pdpPrimingInFlight = !1, this._queuedUserMessages = [], this._productContextUnavailableSku = null;
3593
- }
3594
- _handleBridgeMessage(e) {
3595
- switch (e.type) {
3596
- case "openChat":
3597
- this.open();
3598
- break;
3599
- case "closeChat":
3600
- this.close();
3601
- break;
3602
- case "startNewChatWithLauncherAction": {
3603
- const t = e.payload, a = t?.action, n = te(a) ? a : te(t) ? t : null;
3604
- n && this._sendAction(n, { silent: !0 }), this.open();
3605
- break;
3606
- }
3607
- case "startNewChatWithDetailContext": {
3608
- const t = e.payload;
3609
- if (t && typeof t == "object") {
3610
- this._bridgeContext = t;
3611
- const a = t.sku;
3612
- if (a && this.update({ sku: a }), te(t.action)) {
3613
- this._pdpLaunched = !0, this.open(), this._sendAction(t.action);
3614
- break;
3615
- }
3616
- }
3617
- this.open();
3618
- break;
3619
- }
3620
- case "launcherAction": {
3621
- const a = e.payload?.action;
3622
- a && typeof a == "object" && "type" in a && this._sendAction(a);
3623
- break;
3624
- }
3625
- case "scrollToBottom":
3626
- this._drawer?.scrollToBottomIfNeeded();
3627
- break;
3628
- case "addToCardHandler": {
3629
- this._bridge?.send("addToCardResult", e.payload);
3630
- break;
3631
- }
3632
- case "cartQuantityHandler": {
3633
- const t = e.payload;
3634
- t && "quantity" in t && typeof t.quantity == "number" && (this._cartQuantity = t.quantity);
3635
- break;
3636
- }
3637
- case "minimizeRequestedByUser":
3638
- this._extendedModeManager?.setHiddenByUser(!0);
3639
- break;
3640
- case "bgColorChange": {
3641
- const a = e.payload?.color;
3642
- typeof a == "string" && un(a) && this._shadow && this._shadow.host.style.setProperty("--gengage-chat-bg", a);
3643
- break;
3644
- }
3645
- }
3646
- }
3647
- _registerPublicAPI() {
3648
- window.gengage || (window.gengage = {}), window.gengage.chat = {
3649
- open: (e) => this.open(e),
3650
- openWithAction: (e, t) => this.openWithAction(e, t),
3651
- sendMessage: (e) => this.sendMessage(e),
3652
- sendAction: (e, t) => this.sendAction(e, t),
3653
- close: () => this.close(),
3654
- saveSession: (e, t) => this.saveSession(e, t),
3655
- get isOpen() {
3656
- return !1;
3657
- },
3658
- // Placeholder, overridden below
3659
- on: (e, t) => this.on(e, t),
3660
- trackCheckout: (e, t) => this.trackCheckout(e, t),
3661
- flushMeteringSummary: (e) => this.flushMeteringSummary(e),
3662
- addCallback: (e, t) => this.addCallback(e, t)
3663
- }, Object.defineProperty(window.gengage.chat, "isOpen", {
3664
- get: () => this._drawerVisible
3665
- });
3666
- }
3667
- _showDrawer() {
3668
- if (this._drawerVisible) return;
3669
- this._drawerVisible = !0;
3670
- const e = this._drawer?.getElement();
3671
- e && e.classList.remove("gengage-chat-drawer--hidden"), this._applyOpenStateClasses(), this._isMobileViewport && this._openState === "half" || this._drawer?.focusInput(), this._extendedModeManager?.setChatShown(!0);
3672
- }
3673
- _showProactivePopup(e, t) {
3674
- if (this._proactiveShown || !this._rootEl) return;
3675
- this._proactiveShown = !0;
3676
- try {
3677
- sessionStorage.setItem("gengage_proactive_shown", "1");
3678
- } catch {
3679
- }
3680
- this._setProactiveCooldown();
3681
- const a = {
3682
- message: e,
3683
- onAccept: () => this.open(),
3684
- onDismiss: () => {
3685
- },
3686
- ...t && t.length > 0 && { actionButtons: t }
3687
- };
3688
- this.config.proactiveAcceptLabel !== void 0 && (a.acceptLabel = this.config.proactiveAcceptLabel);
3689
- const n = qt(a);
3690
- this._rootEl.appendChild(n);
3691
- }
3692
- /** Fetch proactive actions from backend and show popup with per-action buttons. */
3693
- async _fetchAndShowProactive() {
3694
- if (!this._proactiveShown)
3695
- try {
3696
- const e = {
3697
- middlewareUrl: this.config.middlewareUrl,
3698
- accountId: this.config.accountId,
3699
- backendType: this.config.backendType ?? "v1"
3700
- }, t = this.config.pageContext?.sku, a = this.config.pageContext?.pageType, n = this.config.locale, i = await Et(
3701
- {
3702
- account_id: this.config.accountId,
3703
- ...t && { sku: t },
3704
- ...a && { page_type: a },
3705
- ...n && { output_language: n }
3706
- },
3707
- e
3708
- );
3709
- if (!i) return;
3710
- const s = i.question ?? i.title ?? "";
3711
- if (!s) return;
3712
- const l = [];
3713
- if (i.actions && Array.isArray(i.actions))
3714
- for (const r of i.actions) {
3715
- const c = r, g = c.title;
3716
- if (g && te(c.requestDetails)) {
3717
- const h = c.requestDetails;
3718
- l.push({
3719
- title: g,
3720
- onSelect: () => {
3721
- this.openWithAction(h);
3722
- }
3723
- });
3724
- }
3725
- }
3726
- this._showProactivePopup(s, l);
3727
- } catch {
3728
- }
3729
- }
3730
- _proactiveCooldownKey() {
3731
- return `gengage_proactive_time_${this.config.accountId}`;
3732
- }
3733
- _isProactiveCooldownActive() {
3734
- try {
3735
- const e = localStorage.getItem(this._proactiveCooldownKey());
3736
- if (e) {
3737
- const t = Date.now() - parseInt(e, 10), a = this.config.proactiveCooldownMs ?? 36e5;
3738
- return t < a;
3739
- }
3740
- } catch {
3741
- }
3742
- return !1;
3743
- }
3744
- _setProactiveCooldown() {
3745
- try {
3746
- localStorage.setItem(this._proactiveCooldownKey(), String(Date.now()));
3747
- } catch {
3748
- }
3749
- }
3750
- _hideDrawer() {
3751
- if (!this._drawerVisible) return;
3752
- this._activeTypewriter?.cancel(), this._activeTypewriter = null, this._activeTtsHandle?.stop(), this._activeTtsHandle = null, this._drawerVisible = !1, this._openState = "full";
3753
- const e = this._drawer?.getElement();
3754
- e && e.classList.add("gengage-chat-drawer--hidden"), this._applyOpenStateClasses(), this._extendedModeManager?.setChatShown(!1);
3755
- }
3756
- _syncViewportState() {
3757
- if (this._rootEl) {
3758
- if (this._isMobileViewport = window.innerWidth <= this._mobileBreakpoint, this._rootEl.classList.toggle("gengage-chat-root--mobile", this._isMobileViewport), this._launcher) {
3759
- const e = this._isMobileViewport && this.config.hideMobileLauncher === !0;
3760
- this._launcher.container.classList.toggle("gengage-chat-launcher--hidden-mobile", e);
3761
- }
3762
- this._applyOpenStateClasses();
3763
- }
3764
- }
3765
- _applyOpenStateClasses() {
3766
- if (!this._rootEl) return;
3767
- const e = this._drawerVisible && this._isMobileViewport && this._openState === "half", t = this._drawerVisible && this._isMobileViewport && this._openState === "full";
3768
- this._rootEl.classList.toggle("gengage-chat-root--open", this._drawerVisible), this._rootEl.classList.toggle("gengage-chat-root--mobile-half", e), this._rootEl.classList.toggle("gengage-chat-root--mobile-full", t);
3769
- }
3770
- _handleAttachment(e) {
3771
- const t = vt(e);
3772
- if (!t.ok) {
3773
- const a = t.reason === "invalid_type" ? this._i18n.invalidFileType : this._i18n.fileTooLarge;
3774
- j("gengage:global:error", {
3775
- message: a,
3776
- source: "chat"
3777
- });
3778
- return;
3779
- }
3780
- this._drawer?.stageAttachment(e);
3781
- }
3782
- _sendMessage(e, t) {
3783
- if (this._pdpPrimingInFlight) {
3784
- this._queuedUserMessages.push(t !== void 0 ? { text: e, attachment: t } : { text: e });
3785
- return;
3786
- }
3787
- je(), this._messages.some((i) => i.role === "user") || Ve();
3788
- const n = {
3789
- title: e,
3790
- type: "user_message",
3791
- payload: e
3792
- };
3793
- t !== void 0 ? this._sendAction(n, { attachment: t }) : this._sendAction(n);
3794
- }
3795
- _flushQueuedUserMessages() {
3796
- if (this._pdpPrimingInFlight || this._queuedUserMessages.length === 0) return;
3797
- const e = [...this._queuedUserMessages];
3798
- this._queuedUserMessages = [];
3799
- for (const t of e)
3800
- this._sendMessage(t.text, t.attachment);
3801
- }
3802
- _sendAction(e, t) {
3803
- if (this._activeTypewriter?.cancel(), this._activeTypewriter = null, this._activeTtsHandle?.stop(), this._activeTtsHandle = null, !this._initComplete) {
3804
- this._pendingActions.length < 10 && this._pendingActions.push({ action: e, options: t });
3805
- return;
3806
- }
3807
- if (this._choicePrompterEl?.remove(), this._choicePrompterEl = null, this._currentThreadId && this._lastThreadId && this._lastThreadId > this._currentThreadId) {
3808
- const u = this._currentThreadId, E = this._messages.filter((m) => m.threadId !== void 0 && m.threadId > u);
3809
- this._messages = this._messages.filter((m) => !m.threadId || m.threadId <= u);
3810
- for (const m of E)
3811
- this._shadow?.querySelector(`[data-message-id="${CSS.escape(m.id)}"]`)?.remove(), this._panel.snapshots.delete(m.id), this._panel.snapshotTypes.delete(m.id);
3812
- this._shadow?.querySelectorAll("[data-thread-id]")?.forEach((m) => {
3813
- m instanceof HTMLElement && m.dataset.threadId && m.dataset.threadId > u && m.remove();
3814
- });
3815
- }
3816
- this._drawer?.setPills([]), this._drawer?.clearInputAreaChips(), this._bridge?.send("isResponding", !0);
3817
- const a = gt();
3818
- this._currentThreadId = a, this._lastThreadId = a, this._panel && e.type !== "launchSingleProduct" && (this._panel.lastActionType = e.type);
3819
- const n = t?.preservePanel === !0, i = e.type === "launchSingleProduct" && t?.silent === !0 && t?.isPdpPrime === !0;
3820
- if (n || (this._activeRequestThreadId = a), !t?.silent) {
3821
- const u = this._createMessage("user", typeof e.payload == "string" ? e.payload : e.title);
3822
- u.threadId = a, t?.attachment !== void 0 && (u.attachment = t.attachment), this._drawer?.addMessage(u), this._messages.push(u);
3823
- }
3824
- if (!t?.silent && this._hasUnavailableProductContext() && (e.type === "user_message" || e.type === "inputText")) {
3825
- const u = this._i18n.productNotFoundMessage, E = this._createMessage("assistant", u);
3826
- E.threadId = a, E.status = "done", this._messages.push(E), this._ensureAssistantMessageRendered(E), this._drawer?.updateBotMessage(E.id, u), this._bridge?.send("isResponding", !1), this.emit("message", E), this._persistToIndexedDB().catch(() => {
3827
- });
3828
- return;
3829
- }
3830
- t?.preservePanel || (this._drawer?.hasPanelContent() ? this._drawer.showPanelLoading() : this._drawer?.clearPanel()), this._drawer?.showTypingIndicator();
3831
- let l = "";
3832
- const r = this._createMessage("assistant", "");
3833
- r.threadId = a, r.status = "streaming", t?.silent && (r.silent = !0), this._messages.push(r), t?.preservePanel || (this._abortControllers.forEach((u) => u.abort()), this._abortControllers.clear());
3834
- const c = {
3835
- middlewareUrl: this.config.middlewareUrl,
3836
- ...this.config.backendType ? { backendType: this.config.backendType } : {},
3837
- ...this.config.accountId ? { accountId: this.config.accountId } : {}
3838
- };
3839
- t?.attachment !== void 0 && (c.attachment = t.attachment);
3840
- const h = this._getVisibleMessages().filter((u) => u.content).slice(-50).map((u) => ({
3841
- role: u.role === "user" ? "user" : "model",
3842
- content: u.content ?? ""
3843
- })), p = {
3844
- outputLanguage: $a(this.config.locale),
3845
- parentUrl: window.location.href,
3846
- windowWidth: String(window.innerWidth),
3847
- windowHeight: String(window.innerHeight),
3848
- selfUrl: "",
3849
- id: this.config.session?.sessionId ?? "",
3850
- userId: this.config.session?.userId ?? "",
3851
- appId: this.config.accountId,
3852
- threads: [],
3853
- createdAt: this._chatCreatedAt,
3854
- kvkkApproved: be(this.config.accountId),
3855
- voiceEnabled: this.config.voiceEnabled ?? !1,
3856
- threadId: a,
3857
- isControlGroup: this.config.session?.abTestVariant === "control",
3858
- isMobile: this._isMobileViewport
3859
- };
3860
- this.config.session?.viewId !== void 0 && (p.viewId = this.config.session.viewId);
3861
- const d = wt(e, {
3862
- pageContext: this.config.pageContext,
3863
- backendContext: this._lastBackendContext,
3864
- isMobile: this._isMobileViewport
3865
- }), f = {
3866
- account_id: this.config.accountId,
3867
- session_id: this.config.session?.sessionId ?? "",
3868
- correlation_id: this.config.session?.sessionId ?? "",
3869
- type: d.type,
3870
- locale: this.config.locale ?? "tr",
3871
- meta: p,
3872
- context: {
3873
- // Spread backend context (panel, message_id, etc.) but preserve FE's
3874
- // authoritative chatHistory — the backend's stale `messages` must not
3875
- // overwrite the up-to-date conversation history built by the widget.
3876
- ...this._lastBackendContext ?? {},
3877
- messages: h,
3878
- // V1 backend reads session_id from context (not top-level).
3879
- // Include here for V1 compatibility; V2 uses thread_id from meta.
3880
- session_id: this.config.session?.sessionId ?? ""
3881
- }
3882
- };
3883
- this.config.session?.userId !== void 0 && (f.user_id = this.config.session.userId), this.config.session?.viewId !== void 0 && (f.view_id = this.config.session.viewId), d.payload !== void 0 && (f.payload = d.payload), this.config.pageContext?.sku !== void 0 && (f.sku = this.config.pageContext.sku), this.config.pageContext?.pageType !== void 0 && (f.page_type = this.config.pageContext.pageType);
3884
- const k = crypto.randomUUID(), _ = Date.now();
3885
- let P = 0, S = !1, T = !1;
3886
- this.track(
3887
- $e(this.analyticsContext(), {
3888
- endpoint: "process_action",
3889
- request_id: k,
3890
- widget: "chat"
3891
- })
3892
- );
3893
- let w = null;
3894
- w = Ct(
3895
- f,
3896
- {
3897
- onTextChunk: (u, E, I) => {
3898
- if (!n && a !== this._activeRequestThreadId || (l += u, this._drawer?.removeTypingIndicator(), I?.skuToProductItem && (this._skuToProductItem = { ...this._skuToProductItem, ...I.skuToProductItem }), I?.conversationMode && (this._conversationMode = I.conversationMode), this.track(
3899
- lt(this.analyticsContext(), {
3900
- request_id: k,
3901
- chunk_index: P++,
3902
- widget: "chat"
3903
- })
3904
- ), !this._drawer)) return;
3905
- let m = l;
3906
- if (E && le(m)) {
3907
- const y = this.config.accountId;
3908
- if (!be(y)) {
3909
- const b = ja(m);
3910
- b && this._drawer?.showKvkkBanner(b, () => {
3911
- this._drawer?.hideKvkkBanner();
3912
- }), Fa(y);
3913
- }
3914
- m = Oa(m);
3915
- }
3916
- const x = this._shadow?.querySelector(
3917
- `[data-message-id="${r.id}"] .gengage-chat-bubble-text`
3918
- );
3919
- if (x ? x.innerHTML = $(m) : (r.content = m, r.role === "assistant" && r.threadId && !this._threadsWithFirstBot.has(r.threadId) && (this._threadsWithFirstBot.add(r.threadId), this._drawer.markFirstBotMessage(r.id)), this._drawer.addMessage(r)), E) {
3920
- r.content = m, r.status = "done", de();
3921
- const y = this._shadow?.querySelector(
3922
- `[data-message-id="${r.id}"] .gengage-chat-bubble-text`
3923
- );
3924
- if (y) {
3925
- this._activeTypewriter?.cancel();
3926
- const b = I?.productMentions;
3927
- this._activeTypewriter = Sa({
3928
- container: y,
3929
- html: $(m),
3930
- onTick: () => this._drawer?.scrollToBottomIfNeeded(),
3931
- onComplete: () => {
3932
- this._activeTypewriter = null, b && b.length > 0 && y && Ta({
3933
- container: y,
3934
- mentions: b,
3935
- onProductClick: (A) => {
3936
- this._sendAction({
3937
- title: b.find((C) => C.sku === A)?.short_name ?? A,
3938
- type: "launchSingleProduct",
3939
- payload: { sku: A }
3940
- });
3941
- }
3942
- });
3943
- }
3944
- });
3945
- }
3946
- }
3947
- },
3948
- onUISpec: (u, E, I) => {
3949
- if (!n && a !== this._activeRequestThreadId || E !== "chat") return;
3950
- const m = u.elements[u.root], x = m?.type ?? "unknown";
3951
- this.track(
3952
- rt(this.analyticsContext(), {
3953
- request_id: k,
3954
- chunk_index: P,
3955
- component_type: x,
3956
- widget: "chat"
3957
- })
3958
- );
3959
- const y = this._buildRenderContext();
3960
- if (x === "ComparisonTable") {
3961
- const C = m?.props?.products;
3962
- st(Array.isArray(C) ? C.length : 0);
3963
- }
3964
- if (x === "ProductGrid") {
3965
- const C = m?.children?.length ?? 0;
3966
- ct(void 0, C);
3967
- }
3968
- const b = I === "panel" && this._panel ? this._panel.toPanelSpec(u) : u, A = !r.silent && (I !== "panel" || x === "ProductCard") && x !== "ActionButtons";
3969
- if (I === "panel" && this._panel) {
3970
- T = !0, m?.props?.similarsAppend === !0 && this._panel.currentType === "ProductDetailsPanel" && this._drawer?.hasPanelContent() && !this._drawer.isPanelLoading() ? this._appendSimilarsToPanel(b, y) : x === "ProductGrid" && this._drawer?.hasPanelContent() && !this._drawer.isPanelLoading() ? this._drawer.appendPanelContent(this._renderUISpec(b, y)) : (this._comparisonSelectMode = !1, this._comparisonSelectedSkus = [], this._drawer?.setPanelContent(this._renderUISpec(b, y)), this._panel.currentType = x), x === "ProductDetailsPanel" && e.type === "launchSingleProduct" && this._clearUnavailableProductContext(), r.threadId && !this._panel.threads.includes(r.threadId) && this._panel.threads.push(r.threadId);
3971
- const C = this._panel.currentType ?? x, L = m?.props?.panelTitle;
3972
- this._panel.updateTopBar(C, L), this._panel.updateExtendedMode(x);
3973
- }
3974
- if (x === "ProductDetailsPanel" && !r.silent && I === "panel") {
3975
- const C = m?.props?.product;
3976
- if (C) {
3977
- const L = {
3978
- root: "root",
3979
- elements: {
3980
- root: {
3981
- type: "ProductSummaryCard",
3982
- props: { product: C }
3983
- }
3984
- }
3985
- }, B = this._shadow?.querySelector(".gengage-chat-messages");
3986
- if (B) {
3987
- const N = this._renderUISpec(L, y);
3988
- r.threadId && (N.dataset.threadId = r.threadId), B.appendChild(N), N.scrollIntoView({ behavior: "auto", block: "end" });
3989
- }
3990
- }
3991
- }
3992
- if (A) {
3993
- const C = this._shadow?.querySelector(".gengage-chat-messages");
3994
- if (C) {
3995
- const L = this._renderUISpec(u, y);
3996
- r.threadId && (L.dataset.threadId = r.threadId), C.appendChild(L), L.scrollIntoView({ behavior: "auto", block: "end" });
3997
- }
3998
- }
3999
- if ((x === "ProductGrid" || x === "ProductCard") && r.threadId) {
4000
- const C = m?.children ?? [], L = x === "ProductGrid" ? C.map((B) => u.elements[B]?.props?.product).filter(Boolean) : [m?.props?.product].filter(Boolean);
4001
- for (const B of L) {
4002
- const N = B.sku, z = B.imageUrl;
4003
- N && z && this._thumbnailEntries.push({ sku: N, imageUrl: z, threadId: r.threadId });
4004
- }
4005
- this._drawer?.setThumbnails(this._thumbnailEntries);
4006
- }
4007
- if (x === "ProductGrid" || x === "ProductDetailsPanel") {
4008
- const L = (x === "ProductGrid" ? (m?.children ?? []).map((B) => u.elements[B]?.props?.product).filter(Boolean) : [
4009
- m?.props?.product ?? m?.props
4010
- ].filter(Boolean)).map((B) => B.imageUrl).filter((B) => typeof B == "string").slice(0, 5);
4011
- L.length > 0 && this._bridge?.send("previewImages", { images: L });
4012
- }
4013
- if (x === "ProductGrid" && I === "panel" && !this._comparisonSelectMode && !Aa()) {
4014
- this._choicePrompterEl?.remove(), this._shadow?.querySelectorAll(".gengage-chat-choice-prompter").forEach((N) => N.remove()), this._choicePrompterEl = Pa({
4015
- heading: this._i18n.choicePrompterHeading,
4016
- suggestion: this._i18n.choicePrompterSuggestion,
4017
- ctaLabel: this._i18n.choicePrompterCta,
4018
- onCtaClick: () => {
4019
- this._comparisonSelectMode = !0, this._choicePrompterEl = null, this._refreshComparisonUI();
4020
- },
4021
- onDismiss: () => {
4022
- this._choicePrompterEl = null;
4023
- }
4024
- });
4025
- const L = this._isMobileViewport || this._drawer?.isPanelCollapsed() ? ".gengage-chat-conversation" : ".gengage-chat-panel", B = this._shadow?.querySelector(L);
4026
- B ? B.appendChild(this._choicePrompterEl) : this._choicePrompterEl = null;
4027
- }
4028
- if (x === "ActionButtons") {
4029
- const C = m?.props?.buttons;
4030
- if (C && C.length > 0) {
4031
- const L = [], B = [];
4032
- for (const N of C)
4033
- if (Na(N)) {
4034
- const z = {
4035
- label: N.label,
4036
- action: N.action
4037
- };
4038
- N.icon && (z.icon = N.icon), L.push(z);
4039
- } else
4040
- B.push(N);
4041
- L.length > 0 && this._drawer?.setInputAreaChips(
4042
- L.map((N) => ({
4043
- label: N.label,
4044
- onAction: () => this._sendAction(N.action),
4045
- ...N.icon ? { icon: N.icon } : {}
4046
- }))
4047
- ), B.length > 0 && this._drawer?.setPills(
4048
- B.map((N) => {
4049
- const z = {
4050
- label: N.label,
4051
- onAction: () => this._sendAction(N.action)
4052
- };
4053
- return N.icon && (z.icon = N.icon), N.image && (z.image = N.image), N.description && (z.description = N.description), z;
4054
- })
4055
- );
4056
- }
4057
- }
4058
- r.uiSpec = u;
4059
- },
4060
- onAction: (u) => {
4061
- if (!(!n && a !== this._activeRequestThreadId) && u.type === "action") {
4062
- const E = {};
4063
- this.config.actionHandling?.unknownActionPolicy !== void 0 && (E.unknownActionPolicy = this.config.actionHandling.unknownActionPolicy), this.config.actionHandling?.allowScriptCall !== void 0 && (E.allowScriptCall = this.config.actionHandling.allowScriptCall), ut(
4064
- u,
4065
- {
4066
- openChat: () => this.open(),
4067
- navigate: (I) => {
4068
- this._bridge?.send("navigate", I), I.newTab ? window.open(I.url, "_blank", "noopener,noreferrer") : window.location.href = I.url;
4069
- },
4070
- saveSession: (I) => this.saveSession(I.sessionId, I.sku),
4071
- addToCart: (I) => {
4072
- j("gengage:similar:add-to-cart", I);
4073
- },
4074
- scriptCall: (I) => {
4075
- j("gengage:chat:script-call", I), this.config.onScriptCall?.(I);
4076
- }
4077
- },
4078
- E
4079
- );
4080
- }
4081
- },
4082
- onMetadata: (u) => {
4083
- if (!(!n && a !== this._activeRequestThreadId) && u.type === "metadata" && u.meta) {
4084
- if ((u.meta.panel !== void 0 || u.meta.messages !== void 0 || u.meta.message_id !== void 0) && (this._lastBackendContext = u.meta), u.meta.panelLoading) {
4085
- S = !0, T = !1;
4086
- const I = typeof u.meta.panelPendingType == "string" ? u.meta.panelPendingType : void 0;
4087
- this._panel && (this._panel.currentType = null), this._drawer?.showPanelLoading(I), I && this._panel?.updateTopBarForLoading(I);
4088
- }
4089
- if (u.meta.voice) {
4090
- const I = new CustomEvent("gengage:chat:voice", {
4091
- detail: { payload: u.meta.voice },
4092
- bubbles: !1,
4093
- cancelable: !0
4094
- }), m = window.dispatchEvent(I);
4095
- if (it(), m) {
4096
- const x = u.meta.voice;
4097
- x.audio_base64 && (this._activeTtsHandle?.stop(), this._activeTtsHandle = Ot(
4098
- x.audio_base64,
4099
- x.content_type ?? "audio/ogg"
4100
- ));
4101
- }
4102
- }
4103
- (u.meta.redirectTarget || u.meta.redirect) && j("gengage:chat:redirect", {
4104
- target: u.meta.redirectTarget ?? null,
4105
- payload: u.meta.redirect ?? null
4106
- }), u.meta.analyzeAnimation && (S = !0, T = !1, this._panel && (this._panel.currentType = null), this._drawer?.showPanelLoading(), this._panel?.updateTopBarForLoading("productDetails")), u.meta.loading && typeof u.meta.loadingText == "string" && (this._drawer?.addThinkingStep(u.meta.loadingText), this._bridge?.send("loadingMessage", { text: u.meta.loadingText })), u.meta.visitorDataResponse && this._bridge?.send("engagingMessage", u.meta.visitorDataResponse), u.meta.formType && this._bridge?.send("glovOtokoc", {
4107
- type: u.meta.formType,
4108
- data: u.meta.formPayload
4109
- }), u.meta.launcherContent && this._bridge?.send("launcherContent", u.meta.launcherContent), j("gengage:chat:metadata", { payload: u.meta });
4110
- const E = u.meta;
4111
- typeof E.prompt_tokens == "number" && typeof E.completion_tokens == "number" && this.track(
4112
- ot(this.analyticsContext(), {
4113
- model: u.model ?? "unknown",
4114
- prompt_tokens: E.prompt_tokens,
4115
- completion_tokens: E.completion_tokens,
4116
- total_tokens: E.total_tokens ?? E.prompt_tokens + E.completion_tokens
4117
- })
4118
- );
4119
- }
4120
- },
4121
- onError: (u) => {
4122
- if (w && this._abortControllers.delete(w), !n && a !== this._activeRequestThreadId) return;
4123
- this._bridge?.send("isResponding", !1), this._bridge?.send("loadingMessage", { text: null }), this._drawer?.removeTypingIndicator();
4124
- const E = T;
4125
- if (S && !T && this._drawer?.isPanelLoading() && this._drawer.clearPanel(), S = !1, T = !1, !(r.silent || r.content != null && r.content.length > 0 || l.length > 0 || E))
4126
- if (i || this._hasUnavailableProductContext()) {
4127
- const m = this._i18n.productNotFoundMessage;
4128
- r.content = m, r.status = "done", this._ensureAssistantMessageRendered(r), this._drawer?.updateBotMessage(r.id, m), this._markUnavailableProductContext();
4129
- } else
4130
- this.emit("error", u), this._drawer?.showError(this._i18n.errorMessage);
4131
- i && (this._pdpPrimingInFlight = !1, this._flushQueuedUserMessages()), r.status === "streaming" && (r.status = "error"), this.track(
4132
- nt(this.analyticsContext(), {
4133
- request_id: k,
4134
- error_code: "STREAM_ERROR",
4135
- error_message: u.message,
4136
- widget: "chat"
4137
- })
4138
- );
4139
- },
4140
- onDone: () => {
4141
- if (w && this._abortControllers.delete(w), !(!n && a !== this._activeRequestThreadId)) {
4142
- if (this._activeRequestThreadId = null, this._bridge?.send("isResponding", !1), this._bridge?.send("loadingMessage", { text: null }), this._drawer?.removeTypingIndicator(), S && !T && this._drawer?.isPanelLoading() && this._drawer.clearPanel(), S = !1, T = !1, i && !l && !T) {
4143
- const u = this._i18n.productNotFoundMessage;
4144
- r.content = u, this._ensureAssistantMessageRendered(r), this._drawer?.updateBotMessage(r.id, u), this._markUnavailableProductContext();
4145
- }
4146
- i && (this._pdpPrimingInFlight = !1, this._flushQueuedUserMessages()), r.status === "streaming" && (r.status = "done", de()), this.emit("message", r), this._panel?.snapshotForMessage(r.id), this._panel?.attachClickHandler(r.id), this.track(
4147
- et(this.analyticsContext(), {
4148
- request_id: k,
4149
- latency_ms: Date.now() - _,
4150
- chunk_count: P,
4151
- widget: "chat"
4152
- })
4153
- ), this.track(
4154
- tt(this.analyticsContext(), {
4155
- meter_key: "chat_request",
4156
- quantity: 1,
4157
- unit: "request"
4158
- })
4159
- ), this.track(
4160
- at(this.analyticsContext(), {
4161
- message_count: this._messages.length,
4162
- history_ref: this.config.session?.sessionId ?? "",
4163
- redaction_level: "none"
4164
- })
4165
- ), this._persistToIndexedDB().catch(() => {
4166
- });
4167
- }
4168
- }
4169
- },
4170
- c
4171
- ), this._abortControllers.add(w);
4172
- }
4173
- /** Return messages visible at the current thread cursor. */
4174
- _getVisibleMessages() {
4175
- const e = this._messages.filter((a) => !a.silent);
4176
- if (!this._currentThreadId) return e;
4177
- const t = this._currentThreadId;
4178
- return e.filter((a) => !a.threadId || a.threadId <= t);
4179
- }
4180
- /** Handle rollback-on-click from a user message bubble. */
4181
- _appendSimilarsToPanel(e, t) {
4182
- if (!this._drawer) return;
4183
- const a = this._drawer.getPanelContentElement();
4184
- if (!a) return;
4185
- const n = document.createElement("h3");
4186
- n.className = "gengage-chat-product-details-similars-heading", n.textContent = this._i18n.similarProductsLabel ?? "Benzer Ürünler", a.appendChild(n);
4187
- const i = this._renderUISpec(e, t);
4188
- i.classList.add("gengage-chat-product-details-similars"), a.appendChild(i);
4189
- }
4190
- _handleRollback(e) {
4191
- const t = this._messages.find((a) => a.id === e);
4192
- t?.threadId && this._rollbackToThread(t.threadId);
4193
- }
4194
- /** Rewind the conversation to the given thread. */
4195
- _rollbackToThread(e) {
4196
- this._currentThreadId = e, this._extendedModeManager?.setHiddenByUser(!1);
4197
- for (const i of this._messages) {
4198
- const s = this._shadow?.querySelector(`[data-message-id="${CSS.escape(i.id)}"]`);
4199
- s && (i.threadId && i.threadId > e ? s.classList.add("gengage-chat-bubble--hidden") : s.classList.remove("gengage-chat-bubble--hidden"));
4200
- }
4201
- this._shadow?.querySelectorAll("[data-thread-id]").forEach((i) => {
4202
- i instanceof HTMLElement && i.dataset.threadId && i.dataset.threadId > e ? i.classList.add("gengage-chat-bubble--hidden") : i instanceof HTMLElement && i.classList.remove("gengage-chat-bubble--hidden");
4203
- });
4204
- const t = this._messages.find((i) => i.role === "assistant" && i.threadId === e);
4205
- t && this._panel?.restoreForMessage(t.id) || this._drawer?.clearPanel();
4206
- const n = this._panel.currentType ?? "";
4207
- this._panel?.updateTopBar(n), this._drawer?.setPills([]), this._session?.db && this.config.session?.sessionId && this._session?.db.loadContext(this.config.session.sessionId, e).then((i) => {
4208
- i && (this._lastBackendContext = i.context);
4209
- }).catch(() => {
4210
- }), this._session?.db && this.config.session?.sessionId && this._session?.db.deleteContextsAfterThread(this.config.session.sessionId, e).catch(() => {
4211
- });
4212
- }
4213
- // ---------------------------------------------------------------------------
4214
- // IndexedDB persistence (delegates to SessionPersistence)
4215
- // ---------------------------------------------------------------------------
4216
- async _persistToIndexedDB() {
4217
- !this._session || !this.config.session?.sessionId || await this._session.persist({
4218
- userId: this.config.session.userId ?? "",
4219
- appId: this.config.accountId,
4220
- sessionId: this.config.session.sessionId,
4221
- messages: this._messages,
4222
- currentThreadId: this._currentThreadId,
4223
- lastThreadId: this._lastThreadId,
4224
- chatCreatedAt: this._chatCreatedAt,
4225
- panelSnapshots: this._panel?.snapshots ?? /* @__PURE__ */ new Map(),
4226
- panelThreads: this._panel?.threads ?? [],
4227
- thumbnailEntries: this._thumbnailEntries,
4228
- lastBackendContext: this._lastBackendContext,
4229
- sku: this.config.pageContext?.sku
4230
- });
4231
- }
4232
- _isSameOriginUrl(e) {
4233
- try {
4234
- return e.trim() ? new URL(e, window.location.href).origin === window.location.origin : !1;
4235
- } catch {
4236
- return !1;
4237
- }
4238
- }
4239
- _markUnavailableProductContext() {
4240
- this._productContextUnavailableSku = this.config.pageContext?.sku ?? null;
4241
- }
4242
- _clearUnavailableProductContext() {
4243
- this._productContextUnavailableSku = null;
4244
- }
4245
- _hasUnavailableProductContext() {
4246
- const e = this.config.pageContext?.sku;
4247
- return e !== void 0 && e.length > 0 && this._productContextUnavailableSku === e;
4248
- }
4249
- _ensureAssistantMessageRendered(e) {
4250
- if (!(this._shadow?.querySelector(`[data-message-id="${CSS.escape(e.id)}"]`) || !this._drawer)) {
4251
- if (e.role === "assistant" && e.threadId && !this._threadsWithFirstBot.has(e.threadId)) {
4252
- this._threadsWithFirstBot.add(e.threadId), this._drawer.addMessage(e), this._drawer.markFirstBotMessage(e.id);
4253
- return;
4254
- }
4255
- this._drawer.addMessage(e);
4256
- }
4257
- }
4258
- async _saveSessionAndOpenURL(e) {
4259
- this._session && await this._session.saveAndOpenURL(e, () => this._persistToIndexedDB(), this._bridge);
4260
- }
4261
- async _loadPayload(e, t) {
4262
- return this._session ? this._session.loadPayload(e, t) : null;
4263
- }
4264
- /**
4265
- * Attempt to restore chat session from IndexedDB.
4266
- * Always restores when IDB has session data for the current sessionId.
4267
- * Best-effort — failures are silently ignored.
4268
- */
4269
- async _restoreFromIndexedDB(e) {
4270
- if (!this._session?.db) return;
4271
- const t = this.config.session?.sessionId;
4272
- if (!t) return;
4273
- const a = this.config.session?.userId ?? "", n = this.config.accountId;
4274
- if (await this._session.loadFavorites(a, n), !e) return;
4275
- const i = await this._session.db?.loadSession(a, n, t);
4276
- if (!i || i.messages.length === 0) return;
4277
- const s = this.config.pageContext?.sku;
4278
- if (s && i.sku && i.sku !== s) return;
4279
- if (this._pdpLaunched = !0, this._drawer?.lockScrollForRestore(), this._currentThreadId = i.currentThreadId, this._lastThreadId = i.lastThreadId, this._chatCreatedAt = i.createdAt, i.panelThreads && (this._panel.threads = i.panelThreads), i.thumbnailEntries && (this._thumbnailEntries = i.thumbnailEntries, this._drawer?.setThumbnails(this._thumbnailEntries)), i.panelSnapshotHtml)
4280
- for (const [r, c] of Object.entries(i.panelSnapshotHtml)) {
4281
- const g = document.createElement("div");
4282
- g.innerHTML = $(c), this._panel.snapshots.set(r, g);
4283
- }
4284
- let l = 0;
4285
- for (const r of i.messages) {
4286
- const c = {
4287
- id: r.id,
4288
- role: r.role,
4289
- timestamp: r.timestamp,
4290
- status: r.status
4291
- };
4292
- if (r.threadId !== void 0 && (c.threadId = r.threadId), r.content !== void 0 && (c.content = r.content), r.silent && (c.silent = !0), this._messages.push(c), c.silent) continue;
4293
- c.role === "assistant" && c.threadId && !this._threadsWithFirstBot.has(c.threadId) && (this._threadsWithFirstBot.add(c.threadId), this._drawer?.markFirstBotMessage(c.id)), this._drawer?.addMessage(c);
4294
- const g = parseInt(r.id.replace("msg-", ""), 10);
4295
- if (!isNaN(g) && g > l && (l = g), c.role === "assistant" && c.threadId) {
4296
- const h = await this._loadPayload(c.threadId, c.id);
4297
- h && (c.uiSpec = h, this._restoreInlineUISpec(c), this._panel?.attachClickHandler(c.id), delete c.uiSpec);
4298
- }
4299
- }
4300
- if (l > this._currentMessageId && (this._currentMessageId = l), this._currentThreadId) {
4301
- let r = await this._session.db?.loadContext(t, this._currentThreadId);
4302
- r || (r = await this._session.db?.loadLatestContext(t)), r && (this._lastBackendContext = r.context);
4303
- }
4304
- if (this._currentThreadId) {
4305
- const r = [...this._messages].reverse().find((c) => c.role === "assistant" && c.threadId === this._currentThreadId && !c.silent);
4306
- r && this._panel.snapshots.has(r.id) && this._panel?.restoreForMessage(r.id);
4307
- }
4308
- if (this._currentThreadId) {
4309
- const r = this._currentThreadId;
4310
- for (const c of this._messages)
4311
- c.threadId && c.threadId > r && this._shadow?.querySelector(`[data-message-id="${CSS.escape(c.id)}"]`)?.classList.add("gengage-chat-bubble--hidden");
4312
- this._shadow?.querySelectorAll("[data-thread-id]").forEach((c) => {
4313
- c instanceof HTMLElement && c.dataset.threadId && c.dataset.threadId > r && c.classList.add("gengage-chat-bubble--hidden");
4314
- });
4315
- }
4316
- if (this._panel.threads.length > 0 && this._currentThreadId) {
4317
- const r = this._panel.threads[this._panel.threads.length - 1];
4318
- if (r) {
4319
- const c = [...this._messages].reverse().find((g) => g.role === "assistant" && g.threadId === r);
4320
- if (c?.threadId) {
4321
- const g = await this._loadPayload(c.threadId, c.id);
4322
- if (g) {
4323
- const h = g.elements[g.root];
4324
- h && this._panel?.updateTopBar(h.type);
4325
- }
4326
- }
4327
- }
4328
- }
4329
- setTimeout(() => {
4330
- this._drawer?.scrollToLastThread();
4331
- }, 550);
4332
- }
4333
- /**
4334
- * Toggle comparison mode or individual SKU selection, then refresh the DOM.
4335
- * Extracted so both the render-context callback and DOM-created checkboxes
4336
- * share the same state-mutation + refresh path.
4337
- */
4338
- _toggleComparisonSku(e) {
4339
- e === "" ? (this._comparisonSelectMode = !this._comparisonSelectMode, this._comparisonSelectMode || (this._comparisonSelectedSkus = [], Ge())) : this._comparisonSelectedSkus.indexOf(e) >= 0 ? this._comparisonSelectedSkus = this._comparisonSelectedSkus.filter((a) => a !== e) : (this._comparisonSelectedSkus = [...this._comparisonSelectedSkus, e], Ke(e)), this._refreshComparisonUI();
4340
- }
4341
- /**
4342
- * Refresh the panel DOM to reflect the current comparison state without
4343
- * full re-render. Updates: toggle button active class, checkbox overlays
4344
- * on product cards, and the floating comparison button.
4345
- */
4346
- _refreshComparisonUI() {
4347
- const e = this._shadow?.querySelector(".gengage-chat-panel");
4348
- if (!e) return;
4349
- const t = e.querySelector(".gengage-chat-product-grid-wrapper");
4350
- if (!t) return;
4351
- const a = t.querySelector(".gengage-chat-product-grid");
4352
- if (!a) return;
4353
- const n = t.querySelector(".gengage-chat-comparison-toggle-btn");
4354
- if (n && n.classList.toggle("gengage-chat-comparison-toggle-btn--active", this._comparisonSelectMode), this._comparisonSelectMode) {
4355
- const s = a.querySelectorAll(".gengage-chat-product-card[data-sku]");
4356
- for (const l of s) {
4357
- if (l.parentElement?.classList.contains("gengage-chat-comparison-select-wrapper")) {
4358
- const h = l.parentElement.querySelector(".gengage-chat-comparison-checkbox");
4359
- h && (h.checked = this._comparisonSelectedSkus.includes(l.dataset.sku));
4360
- continue;
4361
- }
4362
- const r = l.dataset.sku, c = document.createElement("div");
4363
- c.className = "gengage-chat-comparison-select-wrapper";
4364
- const g = document.createElement("input");
4365
- g.type = "checkbox", g.className = "gengage-chat-comparison-checkbox", g.checked = this._comparisonSelectedSkus.includes(r), g.addEventListener("change", () => {
4366
- this._toggleComparisonSku(r);
4367
- }), l.parentNode.insertBefore(c, l), c.appendChild(g), c.appendChild(l);
4368
- }
4369
- } else {
4370
- const s = a.querySelectorAll(".gengage-chat-comparison-select-wrapper");
4371
- for (const l of s) {
4372
- const r = l.querySelector(".gengage-chat-product-card");
4373
- r && l.parentNode && (l.parentNode.insertBefore(r, l), l.remove());
4374
- }
4375
- }
4376
- const i = t.querySelector(".gengage-chat-comparison-floating-btn");
4377
- if (this._comparisonSelectMode && this._comparisonSelectedSkus.length >= 2) {
4378
- const s = this._i18n.compareSelected ?? "Karşılaştır", l = `${s} (${this._comparisonSelectedSkus.length})`;
4379
- if (i)
4380
- i.textContent = l;
4381
- else {
4382
- const r = document.createElement("button");
4383
- r.className = "gengage-chat-comparison-floating-btn", r.type = "button", r.textContent = l, r.addEventListener("click", () => {
4384
- ge(this._comparisonSelectedSkus), this._sendAction({
4385
- title: s,
4386
- type: "getComparisonTable",
4387
- payload: { sku_list: [...this._comparisonSelectedSkus] }
4388
- });
4389
- }), t.appendChild(r);
4390
- }
4391
- } else
4392
- i?.remove();
4393
- }
4394
- /**
4395
- * Build a ChatUISpecRenderContext with all callbacks wired up.
4396
- * Used both during streaming and during session restore.
4397
- */
4398
- _buildRenderContext() {
4399
- const e = {
4400
- onAction: (t) => {
4401
- if (Je(t.title, t.type), t.type === "findSimilar") {
4402
- const n = typeof t.payload == "object" && t.payload !== null && "sku" in t.payload ? String(t.payload.sku) : "";
4403
- Ze(n);
4404
- }
4405
- t.type === "getComparisonTable" && ge(this._comparisonSelectedSkus);
4406
- const a = t.type === "addToCart" || t.type === "like";
4407
- this._sendAction(t, a ? { preservePanel: !0 } : void 0);
4408
- },
4409
- onProductClick: (t) => {
4410
- Xe(t.sku), this.config.isDemoWebsite !== !0 && this._isSameOriginUrl(t.url) ? (j("gengage:similar:product-click", {
4411
- sku: t.sku,
4412
- url: t.url,
4413
- sessionId: this.config.session?.sessionId ?? null
4414
- }), this._saveSessionAndOpenURL(t.url)) : this._sendAction({
4415
- title: t.sku,
4416
- type: "launchSingleProduct",
4417
- payload: { sku: t.sku }
4418
- });
4419
- },
4420
- onAddToCart: (t) => {
4421
- Qe(t.sku, t.quantity);
4422
- const a = {
4423
- ...t,
4424
- sessionId: this.config.session?.sessionId ?? null
4425
- };
4426
- j("gengage:chat:add-to-cart", a), this._bridge?.send("addToCart", t), this._runEventCallbacks("gengage-cart-add", a), this._sendAction(
4427
- {
4428
- title: "Sepete Ekle",
4429
- type: "addToCart",
4430
- payload: { sku: t.sku, cart_code: t.cartCode, quantity: t.quantity }
4431
- },
4432
- { preservePanel: !0 }
4433
- );
4434
- },
4435
- onProductSelect: (t) => {
4436
- const a = {
4437
- root: "root",
4438
- elements: {
4439
- root: {
4440
- type: "ProductDetailsPanel",
4441
- props: { product: t }
4442
- }
4443
- }
4444
- };
4445
- this._drawer?.setPanelContent(this._renderUISpec(a, e));
4446
- },
4447
- i18n: this._i18n,
4448
- pricing: this.config.pricing,
4449
- productSort: this._productSort,
4450
- onSortChange: (t) => {
4451
- this._productSort = t;
4452
- },
4453
- comparisonSelectMode: this._comparisonSelectMode,
4454
- comparisonSelectedSkus: this._comparisonSelectedSkus,
4455
- onToggleComparisonSku: (t) => {
4456
- this._toggleComparisonSku(t);
4457
- },
4458
- favoritedSkus: this._session?.favoritedSkus ?? /* @__PURE__ */ new Set(),
4459
- onFavoriteToggle: (t, a) => {
4460
- Ye(t), this._toggleFavorite(t, a);
4461
- const n = a.name ?? t;
4462
- this._sendAction(
4463
- {
4464
- title: n,
4465
- type: "like",
4466
- payload: { sku: t }
4467
- },
4468
- { preservePanel: !0 }
4469
- );
4470
- }
4471
- };
4472
- return e;
4473
- }
4474
- async _toggleFavorite(e, t) {
4475
- if (!this._session) return;
4476
- const a = this.config.session?.userId ?? "", n = this.config.accountId;
4477
- await this._session.toggleFavorite(a, n, e, t);
4478
- }
4479
- /**
4480
- * Run registered callbacks for a GA4 event.
4481
- * If any callback returns false or throws, handle the failure (e.g. show error for cart-add).
4482
- */
4483
- async _runEventCallbacks(e, t) {
4484
- const a = this._eventCallbacks.get(e);
4485
- if (!(!a || a.size === 0))
4486
- for (const n of a)
4487
- try {
4488
- const i = n(t);
4489
- if ((i instanceof Promise ? await i : i) === !1) {
4490
- this._handleCallbackFailure(e, t);
4491
- return;
4492
- }
4493
- } catch {
4494
- this._handleCallbackFailure(e, t);
4495
- return;
4496
- }
4497
- }
4498
- /**
4499
- * Handle a callback failure — for add-to-cart, show an error message in chat.
4500
- */
4501
- _handleCallbackFailure(e, t) {
4502
- if (e === "gengage-cart-add") {
4503
- const n = this._createMessage("assistant", "Üzgünüm sepete ekleyemedim, bir sorunla karşılaştım.");
4504
- this._currentThreadId && (n.threadId = this._currentThreadId), this._messages.push(n), this._drawer?.addMessage(n);
4505
- }
4506
- }
4507
- /**
4508
- * Re-render inline UISpec elements for a restored bot message.
4509
- * Inserts them into the messages container after the message bubble.
4510
- */
4511
- _restoreInlineUISpec(e) {
4512
- if (!e.uiSpec || !this._drawer) return;
4513
- const t = e.uiSpec, a = t.elements[t.root];
4514
- if (!a) return;
4515
- const n = a.type;
4516
- if (n === "ActionButtons" || n === "ComparisonTable" || n === "ProductGrid" && a.props?.similarsAppend === !0) return;
4517
- const i = this._buildRenderContext(), s = this._shadow?.querySelector(".gengage-chat-messages");
4518
- if (!s) return;
4519
- if (n === "ProductDetailsPanel") {
4520
- const r = a.props?.product;
4521
- if (!r) return;
4522
- const c = {
4523
- root: "root",
4524
- elements: { root: { type: "ProductSummaryCard", props: { product: r } } }
4525
- }, g = this._renderUISpec(c, i);
4526
- e.threadId && (g.dataset.threadId = e.threadId), s.appendChild(g);
4527
- return;
4528
- }
4529
- const l = this._renderUISpec(t, i);
4530
- e.threadId && (l.dataset.threadId = e.threadId), s.appendChild(l);
4531
- }
4532
- _createMessage(e, t) {
4533
- return this._currentMessageId++, {
4534
- id: `msg-${this._currentMessageId}`,
4535
- role: e,
4536
- content: t,
4537
- timestamp: Date.now(),
4538
- status: "done"
4539
- };
4540
- }
4541
- _resolveI18n(e) {
4542
- return { ...It(e.locale), ...e.i18n };
4543
- }
4544
- _resolveUISpecRegistry() {
4545
- const e = da();
4546
- return We(e, this.config.renderer?.registry);
4547
- }
4548
- _renderUISpec(e, t) {
4549
- const a = this._resolveUISpecRegistry(), n = this.config.renderer?.unknownRenderer ?? Ne, i = (r, c) => pa(r, c, a, n), s = this.config.renderer?.renderUISpec;
4550
- return s ? s(e, t, {
4551
- registry: a,
4552
- unknownRenderer: n,
4553
- defaultRender: i
4554
- }) : i(e, t);
4555
- }
4556
- }
4557
- function vn() {
4558
- return new mn();
4559
- }
4560
- export {
4561
- mn as G,
4562
- Nt as V,
4563
- da as a,
4564
- pa as b,
4565
- vn as c,
4566
- Ne as d,
4567
- xn as e,
4568
- Lt as i,
4569
- ut as r
4570
- };
4571
- //# sourceMappingURL=index-CERWfDdF.js.map