@gengage/assistant-fe 0.4.21 → 0.5.0

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