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