@gengage/assistant-fe 0.3.37 → 0.3.39

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 (36) hide show
  1. package/dist/assistant-fe.css +1 -1
  2. package/dist/chat/catalog.d.ts +2 -0
  3. package/dist/chat/components/ChatDrawer.d.ts +7 -2
  4. package/dist/chat/components/ConsultingStylePicker.d.ts +8 -0
  5. package/dist/chat/features/beauty-consulting/consulting-grid.d.ts +10 -7
  6. package/dist/chat/index.d.ts +33 -3
  7. package/dist/{chat-BJu5cvMq.js → chat-BdYYhBg0.js} +2374 -2188
  8. package/dist/chat.iife.js +21 -21
  9. package/dist/chat.js +1 -1
  10. package/dist/common/ga-datalayer.d.ts +29 -1
  11. package/dist/common/native-webview.d.ts +1 -1
  12. package/dist/common/types.d.ts +13 -1
  13. package/dist/{common-DxR7wUEx.js → common-DmixzWHZ.js} +2 -2
  14. package/dist/common.js +44 -44
  15. package/dist/{connection-warning-nm_yulO-.js → connection-warning-n88bjkqL.js} +5 -5
  16. package/dist/index.js +38 -38
  17. package/dist/{ga-datalayer-BUM5z5Pq.js → locale-MM0U5eeR.js} +361 -304
  18. package/dist/{native-webview-BFWh8f-u.js → native-webview-DkvOte_j.js} +132 -127
  19. package/dist/native.iife.js +23 -23
  20. package/dist/native.js +1 -1
  21. package/dist/{qna-6_XrdLG_.js → qna-DrlYm1d8.js} +15 -15
  22. package/dist/qna.iife.js +7 -7
  23. package/dist/qna.js +1 -1
  24. package/dist/{schemas-ZYhTx11k.js → schemas-DnAo0x7A.js} +491 -470
  25. package/dist/{simbut--wBhTxId.js → simbut-Cb5RfaAp.js} +17 -17
  26. package/dist/simbut.css +1 -1
  27. package/dist/simbut.iife.js +3 -3
  28. package/dist/simbut.js +1 -1
  29. package/dist/simrel/components/GroupTabs.d.ts +5 -0
  30. package/dist/simrel/index.d.ts +1 -0
  31. package/dist/simrel/types.d.ts +5 -0
  32. package/dist/simrel-BjNqBbmw.js +736 -0
  33. package/dist/simrel.iife.js +17 -17
  34. package/dist/simrel.js +1 -1
  35. package/package.json +1 -1
  36. package/dist/simrel-jN_YPfC7.js +0 -710
@@ -1,710 +0,0 @@
1
- import { S as H, a as T, b as U, c as b, d as M, h as z, m as $, n as W, o as _, p as x, t as O, u as J, w as Q } from "./schemas-ZYhTx11k.js";
2
- import { $ as Y, C as V, F as w, H as Z, Q as K, U as X, Z as P, b as ee, c as te, h as A, p as re, t as ne, tt as L, y as ie, z as se } from "./ga-datalayer-BUM5z5Pq.js";
3
- import { a as ae, n as oe, r as ce, t as R } from "./price-formatter-CR6VT5z4.js";
4
- import { n as de } from "./connection-warning-nm_yulO-.js";
5
- function G(e) {
6
- const t = [];
7
- for (const r of Object.values(e)) if (r.type === "ProductCard" && r.props) {
8
- const n = r.props.product ?? r.props;
9
- typeof n.sku == "string" && typeof n.name == "string" && t.push(n);
10
- }
11
- return t;
12
- }
13
- function B(e) {
14
- const t = e.headers.get("Content-Type") ?? "";
15
- return t.includes("application/x-ndjson") || t.includes("text/event-stream");
16
- }
17
- async function le(e, t) {
18
- const r = [], n = { onEvent: (a) => {
19
- const s = x(a);
20
- !s || s.type !== "ui_spec" || r.push(...G(s.spec.elements));
21
- } };
22
- return t !== void 0 && (n.signal = t), await U(e, n), r;
23
- }
24
- async function ue(e, t, r) {
25
- const n = M("similar_products", t), a = {
26
- method: "POST",
27
- headers: { "Content-Type": "application/json" },
28
- body: JSON.stringify(e)
29
- };
30
- r !== void 0 && (a.signal = r);
31
- const s = await fetch(n, a);
32
- if (!s.ok) throw new Error(`HTTP ${s.status}: ${s.statusText}`);
33
- if (B(s)) return le(s, r);
34
- const o = await s.text();
35
- if (!o) throw new Error("Empty response body from similar_products endpoint");
36
- try {
37
- return z(JSON.parse(o));
38
- } catch {
39
- throw new Error("Invalid JSON from similar_products endpoint");
40
- }
41
- }
42
- async function ge(e, t) {
43
- const r = [];
44
- let n = null;
45
- const a = { onEvent: (s) => {
46
- const o = x(s);
47
- if (o) {
48
- if (o.type === "metadata" && o.meta) {
49
- const c = o.meta.group_name;
50
- if (typeof c == "string") {
51
- n = {
52
- name: c,
53
- products: []
54
- };
55
- const l = o.meta.highlight;
56
- typeof l == "string" && (n.highlight = l), r.push(n);
57
- }
58
- }
59
- o.type === "ui_spec" && n && n.products.push(...G(o.spec.elements));
60
- }
61
- } };
62
- return t !== void 0 && (a.signal = t), await U(e, a), r;
63
- }
64
- async function pe(e, t, r) {
65
- const n = M("product_groupings", t), a = {
66
- method: "POST",
67
- headers: { "Content-Type": "application/json" },
68
- body: JSON.stringify(e)
69
- };
70
- r !== void 0 && (a.signal = r);
71
- const s = await fetch(n, a);
72
- if (!s.ok) throw new Error(`HTTP ${s.status}: ${s.statusText}`);
73
- if (B(s)) return ge(s, r);
74
- const o = await s.text();
75
- if (!o) return [];
76
- try {
77
- return $(JSON.parse(o));
78
- } catch {
79
- throw new Error("Invalid JSON from product_groupings endpoint");
80
- }
81
- }
82
- function q(e) {
83
- const { product: t, index: r, discountType: n, onClick: a, onAddToCart: s, renderCard: o } = e, c = e.i18n, l = e.pricing;
84
- if (e.renderCardElement) {
85
- const i = e.renderCardElement(t, r);
86
- if (i) return i;
87
- }
88
- if (o) {
89
- const i = document.createElement("div");
90
- return i.className = "gengage-simrel-card gengage-simrel-card--custom gds-card gds-product-card gds-card-interactive", i.dataset.gengagePart = "simrel-product-card", i.innerHTML = Z(o(t, r)), i.addEventListener("click", (d) => {
91
- d.target.closest(".gengage-simrel-atc") || d.target.closest(".gengage-chat-product-card-atc") || a(t);
92
- }), i;
93
- }
94
- const u = document.createElement("article");
95
- u.className = "gengage-simrel-card gengage-chat-product-card gds-card gds-product-card gds-card-interactive", u.dataset.gengagePart = "simrel-product-card", t.inStock === !1 && u.classList.add("gengage-simrel-card--out-of-stock"), u.setAttribute("role", "listitem"), u.dataset.sku = t.sku;
96
- const h = document.createElement("div");
97
- if (h.className = "gengage-simrel-card-image gengage-chat-product-card-img-wrapper", h.dataset.gengagePart = "simrel-product-card-image", t.imageUrl && se(t.imageUrl)) {
98
- const i = document.createElement("img");
99
- i.className = "gengage-chat-product-card-img", i.src = t.imageUrl, i.alt = t.name, i.loading = "lazy", oe(i), h.appendChild(i);
100
- }
101
- if (n === "badge" && t.discountPercent && t.discountPercent > 0) {
102
- const i = document.createElement("span");
103
- i.className = "gengage-simrel-badge gengage-chat-product-card-discount-badge", i.textContent = `%${ce(t.discountPercent)}`, h.appendChild(i);
104
- }
105
- u.appendChild(h);
106
- const m = document.createElement("div");
107
- if (m.className = "gengage-simrel-card-info gengage-chat-product-card-body", m.dataset.gengagePart = "simrel-product-card-body", t.brand) {
108
- const i = document.createElement("div");
109
- i.className = "gengage-simrel-card-brand gengage-chat-product-card-brand", i.textContent = t.brand, m.appendChild(i);
110
- }
111
- const p = document.createElement("div");
112
- if (p.className = "gengage-simrel-card-name gengage-chat-product-card-name", p.textContent = t.name, p.title = t.name, m.appendChild(p), t.rating != null && t.rating > 0) {
113
- const i = document.createElement("div");
114
- if (i.className = "gengage-simrel-card-rating gengage-chat-product-card-rating", i.appendChild(ae(t.rating)), t.reviewCount != null) {
115
- const d = document.createElement("span");
116
- d.className = "gengage-simrel-card-review-count gengage-chat-product-card-review-count", d.textContent = ` (${t.reviewCount})`, i.appendChild(d);
117
- }
118
- m.appendChild(i);
119
- }
120
- const v = document.createElement("div");
121
- if (v.className = "gengage-simrel-card-price gengage-chat-product-card-price", t.originalPrice && t.originalPrice !== t.price && (n === "strike-through" || !n)) {
122
- const i = document.createElement("span");
123
- i.className = "gengage-simrel-card-price-original gengage-chat-product-card-original-price", i.textContent = R(t.originalPrice, l), v.appendChild(i);
124
- }
125
- if (t.price && parseFloat(t.price) > 0) {
126
- const i = document.createElement("span");
127
- i.className = "gengage-simrel-card-price-current gengage-chat-product-card-price-current", i.textContent = R(t.price, l), v.appendChild(i);
128
- }
129
- m.appendChild(v), u.appendChild(m);
130
- const C = document.createElement("button");
131
- if (C.className = "gengage-simrel-card-cta gengage-chat-product-card-cta gds-btn gds-btn-secondary", C.type = "button", C.dataset.gengagePart = "simrel-product-card-cta", C.textContent = c?.ctaLabel ?? "View", C.addEventListener("click", (i) => {
132
- i.preventDefault(), i.stopPropagation(), a(t);
133
- }), u.appendChild(C), t.inStock === !1) {
134
- const i = document.createElement("div");
135
- i.className = "gengage-simrel-card-oos", i.textContent = c?.outOfStockLabel ?? "Out of Stock", u.appendChild(i);
136
- } else if (t.cartCode) {
137
- const i = document.createElement("button");
138
- i.className = "gengage-simrel-atc gengage-simrel-atc-button gds-btn gds-btn-secondary", i.type = "button", i.textContent = c?.addToCartButton ?? "Add to Cart", i.addEventListener("click", (d) => {
139
- d.preventDefault(), d.stopPropagation(), s({
140
- sku: t.sku,
141
- quantity: 1,
142
- cartCode: t.cartCode
143
- });
144
- }), u.appendChild(i);
145
- }
146
- return u.addEventListener("click", (i) => {
147
- i.target.closest(".gengage-simrel-atc") || i.target.closest(".gengage-chat-product-card-atc") || i.target.closest(".gengage-chat-product-card-cta") || a(t);
148
- }), u;
149
- }
150
- function N(e) {
151
- const t = document.createElement("div");
152
- t.className = "gengage-simrel-grid", t.setAttribute("role", "list"), t.setAttribute("aria-label", e.i18n?.similarProductsAriaLabel ?? "Similar products"), e.columns && t.style.setProperty("--gengage-simrel-columns", String(e.columns));
153
- for (let r = 0; r < e.products.length; r++) {
154
- const n = {
155
- product: e.products[r],
156
- index: r,
157
- onClick: e.onClick,
158
- onAddToCart: e.onAddToCart
159
- };
160
- e.i18n !== void 0 && (n.i18n = e.i18n), e.discountType !== void 0 && (n.discountType = e.discountType), e.renderCard !== void 0 && (n.renderCard = e.renderCard), e.renderCardElement !== void 0 && (n.renderCardElement = e.renderCardElement);
161
- const a = q(n);
162
- t.appendChild(a);
163
- }
164
- return e.products.length === 0 && (t.style.display = "none", t.dataset.empty = "true"), t;
165
- }
166
- var me = 0;
167
- function fe(e) {
168
- const t = me++, r = document.createElement("div");
169
- if (r.className = "gengage-simrel-groups", r.dataset.gengagePart = "simrel-groups", e.groups.length === 0)
170
- return r.style.display = "none", r.dataset.empty = "true", r;
171
- const n = document.createElement("div");
172
- n.className = "gengage-simrel-tabs gds-toolbar", n.dataset.gengagePart = "simrel-tab-bar", n.setAttribute("role", "tablist");
173
- const a = [], s = [], o = (i) => {
174
- const d = {
175
- products: i.products,
176
- onClick: e.onClick,
177
- onAddToCart: e.onAddToCart
178
- };
179
- return e.i18n !== void 0 && (d.i18n = e.i18n), e.discountType !== void 0 && (d.discountType = e.discountType), e.renderCard !== void 0 && (d.renderCard = e.renderCard), e.renderCardElement !== void 0 && (d.renderCardElement = e.renderCardElement), e.columns !== void 0 && (d.columns = e.columns), d;
180
- }, c = (i) => {
181
- for (let g = 0; g < a.length; g++) {
182
- const y = g === i;
183
- a[g].classList.toggle("gengage-simrel-tab--active", y), a[g].setAttribute("aria-selected", String(y)), a[g].tabIndex = y ? 0 : -1;
184
- }
185
- const d = e.groups[i], f = s[i];
186
- f.innerHTML = "";
187
- const E = N(o(d));
188
- f.appendChild(E);
189
- for (let g = 0; g < s.length; g++) {
190
- const y = g === i;
191
- s[g].style.display = y ? "" : "none", s[g].tabIndex = y ? 0 : -1;
192
- }
193
- };
194
- for (let i = 0; i < e.groups.length; i++) {
195
- const d = e.groups[i], f = `gengage-simrel-tab-${t}-${i}`, E = `gengage-simrel-panel-${t}-${i}`, g = document.createElement("button");
196
- g.className = "gengage-simrel-tab gds-tab", g.type = "button", g.dataset.gengagePart = "simrel-tab", g.id = f, g.textContent = d.name, g.setAttribute("role", "tab"), g.setAttribute("aria-controls", E), g.setAttribute("aria-selected", String(i === 0)), g.tabIndex = i === 0 ? 0 : -1, i === 0 && g.classList.add("gengage-simrel-tab--active"), g.addEventListener("click", () => c(i)), g.addEventListener("keydown", (k) => {
197
- let S = -1;
198
- k.key === "ArrowRight" || k.key === "ArrowDown" ? S = (i + 1) % e.groups.length : k.key === "ArrowLeft" || k.key === "ArrowUp" ? S = (i - 1 + e.groups.length) % e.groups.length : k.key === "Home" ? S = 0 : k.key === "End" && (S = e.groups.length - 1), S >= 0 && (k.preventDefault(), c(S), a[S].focus());
199
- }), a.push(g), n.appendChild(g);
200
- const y = document.createElement("div");
201
- y.className = "gengage-simrel-tab-panel", y.dataset.gengagePart = "simrel-tab-panel", y.id = E, y.setAttribute("role", "tabpanel"), y.setAttribute("aria-labelledby", f), y.tabIndex = i === 0 ? 0 : -1, i !== 0 && (y.style.display = "none"), s.push(y);
202
- }
203
- const l = document.createElement("button");
204
- l.type = "button", l.className = "gengage-simrel-tabs-arrow gengage-simrel-tabs-arrow--left", l.setAttribute("aria-label", e.i18n?.scrollTabsLeft ?? "Scroll tabs left"), l.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>';
205
- const u = document.createElement("button");
206
- u.type = "button", u.className = "gengage-simrel-tabs-arrow gengage-simrel-tabs-arrow--right", u.setAttribute("aria-label", e.i18n?.scrollTabsRight ?? "Scroll tabs right"), u.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>';
207
- const h = 200;
208
- l.addEventListener("click", () => {
209
- n.scrollBy({
210
- left: -h,
211
- behavior: "smooth"
212
- });
213
- }), u.addEventListener("click", () => {
214
- n.scrollBy({
215
- left: h,
216
- behavior: "smooth"
217
- });
218
- });
219
- const m = () => {
220
- const i = n.scrollLeft <= 4, d = n.scrollLeft + n.clientWidth >= n.scrollWidth - 4;
221
- l.style.display = i ? "none" : "", u.style.display = d ? "none" : "", n.classList.toggle("gengage-simrel-tabs--peek-right", !d), n.classList.toggle("gengage-simrel-tabs--peek-left", !i);
222
- };
223
- n.addEventListener("scroll", m, { passive: !0 }), typeof ResizeObserver < "u" && new ResizeObserver(m).observe(n), l.style.display = "none", u.style.display = "none", requestAnimationFrame(m);
224
- const p = document.createElement("div");
225
- p.className = "gengage-simrel-tabs-wrapper", p.appendChild(l), p.appendChild(n), p.appendChild(u), r.appendChild(p);
226
- const v = s[0], C = N(o(e.groups[0]));
227
- v.appendChild(C);
228
- for (const i of s) r.appendChild(i);
229
- return r;
230
- }
231
- function I(e) {
232
- if (!e || typeof e != "object") return null;
233
- const t = e;
234
- if (typeof t.sku != "string" || typeof t.name != "string" || typeof t.url != "string") return null;
235
- const r = {
236
- sku: t.sku,
237
- name: t.name,
238
- url: t.url
239
- }, n = t.imageUrl;
240
- typeof n == "string" && (r.imageUrl = n);
241
- const a = t.price;
242
- typeof a == "string" && (r.price = a);
243
- const s = t.originalPrice;
244
- typeof s == "string" && (r.originalPrice = s);
245
- const o = t.discountPercent;
246
- typeof o == "number" && (r.discountPercent = o);
247
- const c = t.brand;
248
- typeof c == "string" && (r.brand = c);
249
- const l = t.rating;
250
- typeof l == "number" && (r.rating = l);
251
- const u = t.reviewCount;
252
- typeof u == "number" && (r.reviewCount = u);
253
- const h = t.cartCode;
254
- typeof h == "string" && (r.cartCode = h);
255
- const m = t.inStock;
256
- typeof m == "boolean" && (r.inStock = m);
257
- const p = t.extras;
258
- return p != null && typeof p == "object" && (r.extras = p), r;
259
- }
260
- function he(e) {
261
- if (!e || typeof e != "object") return null;
262
- const t = e, r = t.title, n = t.type;
263
- if (typeof r != "string" || typeof n != "string") return null;
264
- const a = {
265
- title: r,
266
- type: n
267
- };
268
- return t.payload !== void 0 && (a.payload = t.payload), a;
269
- }
270
- var D = {
271
- ProductGrid: ({ element: e, renderElement: t, context: r }) => {
272
- const n = document.createElement("div");
273
- n.className = "gengage-simrel-grid", n.setAttribute("role", "list");
274
- const a = e.props?.columns;
275
- let s;
276
- typeof a == "number" && Number.isFinite(a) && a > 0 ? s = Math.floor(a) : typeof r.gridColumns == "number" && Number.isFinite(r.gridColumns) && r.gridColumns > 0 && (s = Math.floor(r.gridColumns)), s !== void 0 && n.style.setProperty("--gengage-simrel-columns", String(s));
277
- for (const o of e.children ?? []) {
278
- const c = t(o);
279
- c && n.appendChild(c);
280
- }
281
- if (n.children.length === 0) {
282
- const o = document.createElement("div");
283
- o.className = "gengage-simrel-empty", o.textContent = r.i18n.emptyStateMessage, n.appendChild(o);
284
- }
285
- return n;
286
- },
287
- ProductCard: ({ element: e, context: t }) => {
288
- const r = I(e.props?.product ?? e.props);
289
- if (!r) return null;
290
- const n = e.props?.index, a = typeof n == "number" && Number.isFinite(n) ? n : 0, s = e.props?.discountType, o = s === "strike-through" || s === "badge" ? s : t.discountType, c = {
291
- product: r,
292
- index: a,
293
- onClick: t.onClick,
294
- onAddToCart: t.onAddToCart,
295
- i18n: t.i18n
296
- };
297
- return o !== void 0 && (c.discountType = o), t.renderCard !== void 0 && (c.renderCard = t.renderCard), t.renderCardElement !== void 0 && (c.renderCardElement = t.renderCardElement), t.pricing !== void 0 && (c.pricing = t.pricing), q(c);
298
- },
299
- GroupTabs: ({ element: e, context: t }) => {
300
- const r = e.props?.groups;
301
- if (!Array.isArray(r)) return null;
302
- const n = [];
303
- for (const o of r) {
304
- if (!o || typeof o != "object") continue;
305
- const c = o;
306
- if (typeof c.name != "string") continue;
307
- const l = [];
308
- if (Array.isArray(c.products)) for (const h of c.products) {
309
- const m = I(h);
310
- m && l.push(m);
311
- }
312
- const u = {
313
- name: c.name,
314
- products: l
315
- };
316
- typeof c.highlight == "string" && (u.highlight = c.highlight), n.push(u);
317
- }
318
- const a = {
319
- groups: n,
320
- onClick: t.onClick,
321
- onAddToCart: t.onAddToCart,
322
- i18n: t.i18n
323
- }, s = e.props?.columns;
324
- return typeof s == "number" && Number.isFinite(s) && s > 0 ? a.columns = Math.floor(s) : typeof t.gridColumns == "number" && Number.isFinite(t.gridColumns) && t.gridColumns > 0 && (a.columns = Math.floor(t.gridColumns)), t.discountType !== void 0 && (a.discountType = t.discountType), t.renderCard !== void 0 && (a.renderCard = t.renderCard), t.renderCardElement !== void 0 && (a.renderCardElement = t.renderCardElement), fe(a);
325
- },
326
- EmptyState: ({ element: e, context: t }) => {
327
- const r = document.createElement("div");
328
- r.className = "gengage-simrel-empty";
329
- const n = e.props?.message;
330
- return r.textContent = typeof n == "string" ? n : t.i18n.emptyStateMessage, r;
331
- },
332
- AddToCartButton: ({ element: e, context: t }) => {
333
- const r = e.props?.sku, n = e.props?.cartCode;
334
- if (typeof r != "string" || typeof n != "string") return null;
335
- const a = document.createElement("button");
336
- a.className = "gengage-simrel-atc gengage-chat-product-card-cta", a.type = "button";
337
- const s = e.props?.label;
338
- return a.textContent = typeof s == "string" ? s : t.i18n.addToCartButton, a.addEventListener("click", (o) => {
339
- o.preventDefault(), o.stopPropagation(), t.onAddToCart({
340
- sku: r,
341
- quantity: 1,
342
- cartCode: n
343
- });
344
- }), a;
345
- },
346
- QuickActions: ({ element: e, context: t }) => {
347
- const r = document.createElement("div");
348
- r.className = "gengage-simrel-quick-actions";
349
- const n = e.props?.actions;
350
- if (!Array.isArray(n) || !t.onAction) return r;
351
- for (const a of n) {
352
- if (!a || typeof a != "object") continue;
353
- const s = a, o = s.label, c = he(s.action);
354
- if (typeof o != "string" || !c) continue;
355
- const l = document.createElement("button");
356
- l.className = "gengage-simrel-quick-action", l.type = "button", l.textContent = o, l.addEventListener("click", (u) => {
357
- u.preventDefault(), u.stopPropagation(), t.onAction?.(c);
358
- }), r.appendChild(l);
359
- }
360
- return r;
361
- }
362
- }, j = ({ element: e, renderElement: t }) => {
363
- if (!e.children || e.children.length === 0) return null;
364
- const r = document.createElement("div");
365
- for (const n of e.children) {
366
- const a = t(n);
367
- a && r.appendChild(a);
368
- }
369
- return r;
370
- };
371
- function ye() {
372
- return { ...D };
373
- }
374
- function Ce(e, t, r = D, n = j) {
375
- return Q({
376
- spec: e,
377
- context: t,
378
- registry: r,
379
- containerClassName: "gengage-simrel-uispec",
380
- unknownRenderer: n
381
- });
382
- }
383
- var F = {
384
- similarProductsAriaLabel: "Benzer ürünler",
385
- emptyStateMessage: "Benzer ürün bulunamadı.",
386
- addToCartButton: "Sepete Ekle",
387
- ctaLabel: "İncele",
388
- outOfStockLabel: "Stokta Yok",
389
- decreaseLabel: "Azalt",
390
- increaseLabel: "Artır",
391
- errorLoadingMessage: "Benzer ürünler yüklenemedi.",
392
- retryButtonText: "Tekrar dene",
393
- priceSuffix: " TL",
394
- scrollTabsLeft: "Sola kaydır",
395
- scrollTabsRight: "Sağa kaydır"
396
- }, be = {
397
- similarProductsAriaLabel: "Similar products",
398
- emptyStateMessage: "No similar products found.",
399
- addToCartButton: "Add to cart",
400
- ctaLabel: "View",
401
- outOfStockLabel: "Out of Stock",
402
- decreaseLabel: "Decrease",
403
- increaseLabel: "Increase",
404
- errorLoadingMessage: "Could not load similar products.",
405
- retryButtonText: "Try again",
406
- priceSuffix: "",
407
- scrollTabsLeft: "Scroll tabs left",
408
- scrollTabsRight: "Scroll tabs right"
409
- };
410
- function ve(e) {
411
- return e ? e.toLowerCase().split("-")[0] ?? "tr" : "tr";
412
- }
413
- function Ee(e) {
414
- return ve(e) === "en" ? be : F;
415
- }
416
- var _e = _({
417
- sku: b(),
418
- name: b(),
419
- imageUrl: b().url().optional(),
420
- price: b().optional(),
421
- originalPrice: b().optional(),
422
- discountPercent: T().optional(),
423
- url: b().url(),
424
- brand: b().optional(),
425
- rating: T().min(0).max(5).optional(),
426
- reviewCount: T().int().nonnegative().optional()
427
- }), ke = _({
428
- layout: O(["grid", "carousel"]).optional(),
429
- columns: T().int().positive().optional()
430
- }), Se = _({
431
- product: _e,
432
- index: T().int().nonnegative(),
433
- discountType: O(["strike-through", "badge"]).optional()
434
- }), Te = _({
435
- sku: b(),
436
- label: b().optional(),
437
- cartCode: b()
438
- }), we = _({ actions: W(_({
439
- label: b(),
440
- action: _({
441
- title: b(),
442
- type: b(),
443
- payload: J().optional()
444
- })
445
- })) }), Pe = _({ message: b().optional() }), xe = { components: {
446
- ProductGrid: {
447
- schema: ke,
448
- description: "Outer grid or carousel container for similar products."
449
- },
450
- ProductCard: {
451
- schema: Se,
452
- description: "A single product card with image, title, price, and actions."
453
- },
454
- AddToCartButton: {
455
- schema: Te,
456
- description: "Add-to-cart CTA rendered inside or below a product card."
457
- },
458
- QuickActions: {
459
- schema: we,
460
- description: "A row of quick-action buttons below product info."
461
- },
462
- EmptyState: {
463
- schema: Pe,
464
- description: "Empty state shown when no similar products are available."
465
- }
466
- } }, Ae = 12e4;
467
- function Le(e) {
468
- return e instanceof DOMException && e.name === "AbortError";
469
- }
470
- var Re = class extends ee {
471
- constructor(...e) {
472
- super(...e), this._abortController = null, this._contentEl = null, this._lastResultCount = -1, this._i18n = F;
473
- }
474
- async onInit(e) {
475
- this._i18n = this._resolveI18n(e), this._contentEl = document.createElement("div"), this._contentEl.className = "gengage-simrel-container", this._contentEl.dataset.gengagePart = "simrel-container", this._contentEl.lang = ie(e.locale);
476
- const t = this._clampGridColumns(e.gridColumns);
477
- t !== void 0 && this._contentEl.style.setProperty("--gengage-simrel-columns", String(t)), this.root.appendChild(this._contentEl), this._lastSku = e.sku, await this._fetchAndRender(e.sku), te("simrel");
478
- }
479
- onUpdate(e) {
480
- const t = e.sku;
481
- !t || t === this._lastSku && this._lastResultCount !== 0 || (this._lastSku = t, this._fetchAndRender(t));
482
- }
483
- onShow() {
484
- this._contentEl && (this._contentEl.style.opacity = "0", this._contentEl.style.transition = "opacity 0.3s ease-in", requestAnimationFrame(() => {
485
- this._contentEl && (this._contentEl.style.opacity = "1");
486
- }));
487
- }
488
- onHide() {
489
- }
490
- onDestroy() {
491
- this._abort(), this._contentEl && (this._contentEl.remove(), this._contentEl = null);
492
- }
493
- _handleProductClick(e) {
494
- const t = {
495
- sku: e.sku,
496
- name: e.name,
497
- url: e.url
498
- };
499
- if (e.imageUrl !== void 0 && (t.imageUrl = e.imageUrl), e.price !== void 0 && (t.price = e.price), e.originalPrice !== void 0 && (t.originalPrice = e.originalPrice), e.discountPercent !== void 0 && (t.discountPercent = e.discountPercent), e.brand !== void 0 && (t.brand = e.brand), e.rating !== void 0 && (t.rating = e.rating), e.reviewCount !== void 0 && (t.reviewCount = e.reviewCount), e.cartCode !== void 0 && (t.cartCode = e.cartCode), e.inStock !== void 0 && (t.inStock = e.inStock), this.config.onProductClick?.(t) === !1) return;
500
- re(e.sku, e.name);
501
- const r = this.config.session?.sessionId ?? null;
502
- w("gengage:similar:product-click", {
503
- sku: e.sku,
504
- url: e.url,
505
- sessionId: r
506
- }), this.config.onProductNavigate?.(e.url, e.sku, r);
507
- }
508
- _handleAddToCart(e) {
509
- ne(e.sku, e.quantity), this.config.onAddToCart?.(e), w("gengage:similar:add-to-cart", e), this.track(X(this.analyticsContext(), {
510
- attribution_source: "simrel",
511
- attribution_action_id: crypto.randomUUID(),
512
- cart_value: 0,
513
- currency: this.config.pricing?.currencyCode ?? "TRY",
514
- line_items: e.quantity,
515
- sku: e.sku
516
- }));
517
- }
518
- _abort() {
519
- this._abortController?.abort(), this._abortController = null;
520
- }
521
- _isSuperseded(e) {
522
- return this._abortController?.signal !== e;
523
- }
524
- _resolveRequestTimeoutMs() {
525
- const e = this.config.requestTimeoutMs;
526
- return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? Ae : Math.floor(e);
527
- }
528
- async _fetchAndRender(e) {
529
- this._abort();
530
- const t = new AbortController();
531
- this._abortController = t;
532
- const r = t.signal;
533
- let n = !1;
534
- const a = setTimeout(() => {
535
- n = !0, t.abort();
536
- }, this._resolveRequestTimeoutMs());
537
- if (r.addEventListener("abort", () => clearTimeout(a), { once: !0 }), !this._contentEl) return;
538
- this._contentEl.innerHTML = "", this._contentEl.style.display = "";
539
- const s = document.createElement("div");
540
- s.className = "gengage-simrel-loading", s.dataset.gengagePart = "simrel-loading";
541
- const o = document.createElement("div");
542
- o.className = "gengage-simrel-spinner", o.dataset.gengagePart = "simrel-loading-spinner", s.appendChild(o), this._contentEl.appendChild(s);
543
- const c = { middlewareUrl: this.config.middlewareUrl }, l = crypto.randomUUID(), u = Date.now(), h = de({
544
- source: "simrel",
545
- locale: this.config.locale
546
- });
547
- this.track(Y(this.analyticsContext(), {
548
- endpoint: "similar_products",
549
- request_id: l,
550
- widget: "simrel"
551
- }));
552
- try {
553
- const m = {
554
- account_id: this.config.accountId,
555
- session_id: this.config.session?.sessionId ?? "",
556
- correlation_id: this.config.session?.sessionId ?? "",
557
- sku: e
558
- };
559
- this.config.domain !== void 0 && (m.domain = this.config.domain);
560
- const p = await ue(m, c, r);
561
- if (this._lastResultCount = p.length, !this._contentEl) return;
562
- if (this._contentEl.innerHTML = "", p.length > 0) try {
563
- const v = p.map((d) => d.sku), C = new Map(p.map((d) => [d.sku, d])), i = (await pe({
564
- account_id: this.config.accountId,
565
- session_id: this.config.session?.sessionId ?? "",
566
- correlation_id: this.config.session?.sessionId ?? "",
567
- skus: v
568
- }, c, r)).map((d) => ({
569
- ...d,
570
- products: d.products.map((f) => ({
571
- ...C.get(f.sku),
572
- ...f
573
- })).filter((f) => typeof f.sku == "string" && typeof f.name == "string" && typeof f.url == "string")
574
- })).filter((d) => d.products.length > 0);
575
- if (i.length > 0 && this._contentEl) {
576
- const d = this._buildGroupsSpec(i), f = this._renderUISpec(d);
577
- this._contentEl.appendChild(f), A("simrel"), this.track(P(this.analyticsContext(), {
578
- request_id: l,
579
- latency_ms: Date.now() - u,
580
- chunk_count: i.reduce((E, g) => E + g.products.length, 0),
581
- widget: "simrel"
582
- })), this.track(L(this.analyticsContext(), {
583
- message_count: i.reduce((E, g) => E + g.products.length, 0),
584
- history_ref: l,
585
- redaction_level: "none",
586
- widget: "simrel"
587
- }));
588
- return;
589
- }
590
- } catch {
591
- }
592
- if (this._isSuperseded(r)) return;
593
- if (this._contentEl) {
594
- const v = this._buildProductsSpec(p), C = this._renderUISpec(v);
595
- this._contentEl.appendChild(C);
596
- }
597
- p.length > 0 && A("simrel"), this.track(P(this.analyticsContext(), {
598
- request_id: l,
599
- latency_ms: Date.now() - u,
600
- chunk_count: p.length,
601
- widget: "simrel"
602
- })), this.track(L(this.analyticsContext(), {
603
- message_count: p.length,
604
- history_ref: l,
605
- redaction_level: "none",
606
- widget: "simrel"
607
- }));
608
- } catch (m) {
609
- const p = Le(m);
610
- if (p && this._isSuperseded(r)) return;
611
- const v = p && n ? "REQUEST_TIMEOUT" : "FETCH_ERROR", C = p && n ? "request_timeout" : m instanceof Error ? m.message : String(m);
612
- if (w("gengage:global:error", {
613
- source: "simrel",
614
- code: v,
615
- message: V(this.config.locale, m)
616
- }), this.track(K(this.analyticsContext(), {
617
- request_id: l,
618
- error_code: v,
619
- error_message: C,
620
- widget: "simrel"
621
- })), this._contentEl) {
622
- this._contentEl.innerHTML = "";
623
- const i = document.createElement("div");
624
- i.className = "gengage-simrel-error";
625
- const d = document.createElement("span");
626
- d.textContent = this._i18n.errorLoadingMessage, i.appendChild(d);
627
- const f = document.createElement("button");
628
- f.className = "gengage-simrel-retry", f.textContent = this._i18n.retryButtonText, f.addEventListener("click", () => {
629
- this._fetchAndRender(this.config.sku);
630
- }), i.appendChild(f), this._contentEl.appendChild(i);
631
- }
632
- } finally {
633
- clearTimeout(a), h();
634
- }
635
- }
636
- _clampGridColumns(e) {
637
- if (!(e === void 0 || typeof e != "number" || !Number.isFinite(e)))
638
- return Math.max(1, Math.min(12, Math.floor(e)));
639
- }
640
- _resolveI18n(e) {
641
- return {
642
- ...Ee(e.locale),
643
- ...e.i18n
644
- };
645
- }
646
- _resolveUISpecRegistry() {
647
- return H(ye(), this.config.renderer?.registry);
648
- }
649
- _buildRenderContext() {
650
- const e = this.config.renderCard, t = {
651
- onClick: (n) => this._handleProductClick(n),
652
- onAddToCart: (n) => this._handleAddToCart(n),
653
- i18n: this._i18n
654
- };
655
- this.config.discountType !== void 0 && (t.discountType = this.config.discountType), e !== void 0 && (t.renderCard = e), this.config.renderCardElement !== void 0 && (t.renderCardElement = this.config.renderCardElement), this.config.pricing !== void 0 && (t.pricing = this.config.pricing);
656
- const r = this._clampGridColumns(this.config.gridColumns);
657
- return r !== void 0 && (t.gridColumns = r), t;
658
- }
659
- _renderUISpec(e) {
660
- const t = this._resolveUISpecRegistry(), r = this._buildRenderContext(), n = this.config.renderer?.unknownRenderer ?? j, a = (o, c) => Ce(o, c, t, n), s = this.config.renderer?.renderUISpec;
661
- return s ? s(e, r, {
662
- registry: t,
663
- unknownRenderer: n,
664
- defaultRender: a
665
- }) : a(e, r);
666
- }
667
- _buildProductsSpec(e) {
668
- const t = {}, r = [];
669
- for (let s = 0; s < e.length; s++) {
670
- const o = e[s], c = `product-${s}`;
671
- r.push(c), t[c] = {
672
- type: "ProductCard",
673
- props: {
674
- product: o,
675
- index: s,
676
- discountType: this.config.discountType
677
- }
678
- };
679
- }
680
- const n = { layout: "grid" }, a = this._clampGridColumns(this.config.gridColumns);
681
- return a !== void 0 && (n.columns = a), t.root = {
682
- type: "ProductGrid",
683
- props: n,
684
- children: r
685
- }, {
686
- root: "root",
687
- elements: t
688
- };
689
- }
690
- _buildGroupsSpec(e) {
691
- return {
692
- root: "root",
693
- elements: { root: {
694
- type: "GroupTabs",
695
- props: { groups: e }
696
- } }
697
- };
698
- }
699
- };
700
- function Oe() {
701
- return new Re();
702
- }
703
- export {
704
- j as a,
705
- ye as i,
706
- Oe as n,
707
- Ce as o,
708
- xe as r,
709
- Re as t
710
- };