@gengage/assistant-fe 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/LICENSE +61 -0
  2. package/README.md +232 -0
  3. package/dist/assistant-fe.css +1 -0
  4. package/dist/chat/api.d.ts +87 -0
  5. package/dist/chat/api.d.ts.map +1 -0
  6. package/dist/chat/attachment-utils.d.ts +10 -0
  7. package/dist/chat/attachment-utils.d.ts.map +1 -0
  8. package/dist/chat/catalog.d.ts +1114 -0
  9. package/dist/chat/catalog.d.ts.map +1 -0
  10. package/dist/chat/components/AIGroupingCards.d.ts +4 -0
  11. package/dist/chat/components/AIGroupingCards.d.ts.map +1 -0
  12. package/dist/chat/components/AISuggestedSearchCards.d.ts +4 -0
  13. package/dist/chat/components/AISuggestedSearchCards.d.ts.map +1 -0
  14. package/dist/chat/components/AITopPicks.d.ts +4 -0
  15. package/dist/chat/components/AITopPicks.d.ts.map +1 -0
  16. package/dist/chat/components/CategoriesContainer.d.ts +4 -0
  17. package/dist/chat/components/CategoriesContainer.d.ts.map +1 -0
  18. package/dist/chat/components/ChatDrawer.d.ts +140 -0
  19. package/dist/chat/components/ChatDrawer.d.ts.map +1 -0
  20. package/dist/chat/components/ChoicePrompter.d.ts +16 -0
  21. package/dist/chat/components/ChoicePrompter.d.ts.map +1 -0
  22. package/dist/chat/components/ComparisonTable.d.ts +47 -0
  23. package/dist/chat/components/ComparisonTable.d.ts.map +1 -0
  24. package/dist/chat/components/FloatingComparisonButton.d.ts +11 -0
  25. package/dist/chat/components/FloatingComparisonButton.d.ts.map +1 -0
  26. package/dist/chat/components/GroundingReviewCard.d.ts +4 -0
  27. package/dist/chat/components/GroundingReviewCard.d.ts.map +1 -0
  28. package/dist/chat/components/KvkkBanner.d.ts +6 -0
  29. package/dist/chat/components/KvkkBanner.d.ts.map +1 -0
  30. package/dist/chat/components/Launcher.d.ts +25 -0
  31. package/dist/chat/components/Launcher.d.ts.map +1 -0
  32. package/dist/chat/components/PanelTopBar.d.ts +20 -0
  33. package/dist/chat/components/PanelTopBar.d.ts.map +1 -0
  34. package/dist/chat/components/ProactivePopup.d.ts +11 -0
  35. package/dist/chat/components/ProactivePopup.d.ts.map +1 -0
  36. package/dist/chat/components/ProsAndCons.d.ts +9 -0
  37. package/dist/chat/components/ProsAndCons.d.ts.map +1 -0
  38. package/dist/chat/components/ReviewHighlights.d.ts +3 -0
  39. package/dist/chat/components/ReviewHighlights.d.ts.map +1 -0
  40. package/dist/chat/components/ThumbnailsColumn.d.ts +23 -0
  41. package/dist/chat/components/ThumbnailsColumn.d.ts.map +1 -0
  42. package/dist/chat/components/actionClassifier.d.ts +13 -0
  43. package/dist/chat/components/actionClassifier.d.ts.map +1 -0
  44. package/dist/chat/components/productMentionLinker.d.ts +26 -0
  45. package/dist/chat/components/productMentionLinker.d.ts.map +1 -0
  46. package/dist/chat/components/renderUISpec.d.ts +15 -0
  47. package/dist/chat/components/renderUISpec.d.ts.map +1 -0
  48. package/dist/chat/components/typewriter.d.ts +25 -0
  49. package/dist/chat/components/typewriter.d.ts.map +1 -0
  50. package/dist/chat/extendedModeManager.d.ts +33 -0
  51. package/dist/chat/extendedModeManager.d.ts.map +1 -0
  52. package/dist/chat/index.d.ts +192 -0
  53. package/dist/chat/index.d.ts.map +1 -0
  54. package/dist/chat/locales/en.d.ts +3 -0
  55. package/dist/chat/locales/en.d.ts.map +1 -0
  56. package/dist/chat/locales/index.d.ts +6 -0
  57. package/dist/chat/locales/index.d.ts.map +1 -0
  58. package/dist/chat/locales/tr.d.ts +3 -0
  59. package/dist/chat/locales/tr.d.ts.map +1 -0
  60. package/dist/chat/types.d.ts +212 -0
  61. package/dist/chat/types.d.ts.map +1 -0
  62. package/dist/chat.cjs +2 -0
  63. package/dist/chat.cjs.map +1 -0
  64. package/dist/chat.iife.js +59 -0
  65. package/dist/chat.iife.js.map +1 -0
  66. package/dist/chat.js +11 -0
  67. package/dist/chat.js.map +1 -0
  68. package/dist/common/action-router.d.ts +30 -0
  69. package/dist/common/action-router.d.ts.map +1 -0
  70. package/dist/common/activity-tracker.d.ts +38 -0
  71. package/dist/common/activity-tracker.d.ts.map +1 -0
  72. package/dist/common/analytics-events.d.ts +90 -0
  73. package/dist/common/analytics-events.d.ts.map +1 -0
  74. package/dist/common/analytics.d.ts +58 -0
  75. package/dist/common/analytics.d.ts.map +1 -0
  76. package/dist/common/api-paths.d.ts +14 -0
  77. package/dist/common/api-paths.d.ts.map +1 -0
  78. package/dist/common/client.d.ts +20 -0
  79. package/dist/common/client.d.ts.map +1 -0
  80. package/dist/common/communication-bridge.d.ts +51 -0
  81. package/dist/common/communication-bridge.d.ts.map +1 -0
  82. package/dist/common/config-schema.d.ts +241 -0
  83. package/dist/common/config-schema.d.ts.map +1 -0
  84. package/dist/common/context.d.ts +28 -0
  85. package/dist/common/context.d.ts.map +1 -0
  86. package/dist/common/customization-factories.d.ts +63 -0
  87. package/dist/common/customization-factories.d.ts.map +1 -0
  88. package/dist/common/events.d.ts +47 -0
  89. package/dist/common/events.d.ts.map +1 -0
  90. package/dist/common/global-error-toast.d.ts +6 -0
  91. package/dist/common/global-error-toast.d.ts.map +1 -0
  92. package/dist/common/index.d.ts +36 -0
  93. package/dist/common/index.d.ts.map +1 -0
  94. package/dist/common/indexed-db.d.ts +74 -0
  95. package/dist/common/indexed-db.d.ts.map +1 -0
  96. package/dist/common/overlay.d.ts +64 -0
  97. package/dist/common/overlay.d.ts.map +1 -0
  98. package/dist/common/preflight.d.ts +12 -0
  99. package/dist/common/preflight.d.ts.map +1 -0
  100. package/dist/common/renderer/dom.d.ts +4 -0
  101. package/dist/common/renderer/dom.d.ts.map +1 -0
  102. package/dist/common/renderer/index.d.ts +5 -0
  103. package/dist/common/renderer/index.d.ts.map +1 -0
  104. package/dist/common/renderer/overrides.d.ts +24 -0
  105. package/dist/common/renderer/overrides.d.ts.map +1 -0
  106. package/dist/common/renderer/registry.d.ts +3 -0
  107. package/dist/common/renderer/registry.d.ts.map +1 -0
  108. package/dist/common/renderer/types.d.ts +20 -0
  109. package/dist/common/renderer/types.d.ts.map +1 -0
  110. package/dist/common/safe-html.d.ts +19 -0
  111. package/dist/common/safe-html.d.ts.map +1 -0
  112. package/dist/common/streaming.d.ts +32 -0
  113. package/dist/common/streaming.d.ts.map +1 -0
  114. package/dist/common/theme-utils.d.ts +16 -0
  115. package/dist/common/theme-utils.d.ts.map +1 -0
  116. package/dist/common/types.d.ts +298 -0
  117. package/dist/common/types.d.ts.map +1 -0
  118. package/dist/common/ui-theme.d.ts +10 -0
  119. package/dist/common/ui-theme.d.ts.map +1 -0
  120. package/dist/common/uuidv7.d.ts +8 -0
  121. package/dist/common/uuidv7.d.ts.map +1 -0
  122. package/dist/common/v1-protocol-adapter.d.ts +66 -0
  123. package/dist/common/v1-protocol-adapter.d.ts.map +1 -0
  124. package/dist/common/widget-base.d.ts +75 -0
  125. package/dist/common/widget-base.d.ts.map +1 -0
  126. package/dist/common.cjs +2 -0
  127. package/dist/common.cjs.map +1 -0
  128. package/dist/common.js +584 -0
  129. package/dist/common.js.map +1 -0
  130. package/dist/index-CFA70IGF.js +3626 -0
  131. package/dist/index-CFA70IGF.js.map +1 -0
  132. package/dist/index-Dfl89zpe.cjs +13 -0
  133. package/dist/index-Dfl89zpe.cjs.map +1 -0
  134. package/dist/index.cjs +2 -0
  135. package/dist/index.cjs.map +1 -0
  136. package/dist/index.d.ts +24 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +59 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/qna/api.d.ts +22 -0
  141. package/dist/qna/api.d.ts.map +1 -0
  142. package/dist/qna/catalog.d.ts +140 -0
  143. package/dist/qna/catalog.d.ts.map +1 -0
  144. package/dist/qna/components/ButtonRow.d.ts +16 -0
  145. package/dist/qna/components/ButtonRow.d.ts.map +1 -0
  146. package/dist/qna/components/TextInput.d.ts +12 -0
  147. package/dist/qna/components/TextInput.d.ts.map +1 -0
  148. package/dist/qna/components/renderUISpec.d.ts +8 -0
  149. package/dist/qna/components/renderUISpec.d.ts.map +1 -0
  150. package/dist/qna/index.d.ts +34 -0
  151. package/dist/qna/index.d.ts.map +1 -0
  152. package/dist/qna/locales/en.d.ts +3 -0
  153. package/dist/qna/locales/en.d.ts.map +1 -0
  154. package/dist/qna/locales/index.d.ts +6 -0
  155. package/dist/qna/locales/index.d.ts.map +1 -0
  156. package/dist/qna/locales/tr.d.ts +3 -0
  157. package/dist/qna/locales/tr.d.ts.map +1 -0
  158. package/dist/qna/types.d.ts +62 -0
  159. package/dist/qna/types.d.ts.map +1 -0
  160. package/dist/qna.cjs +2 -0
  161. package/dist/qna.cjs.map +1 -0
  162. package/dist/qna.css +1 -0
  163. package/dist/qna.iife.js +48 -0
  164. package/dist/qna.iife.js.map +1 -0
  165. package/dist/qna.js +435 -0
  166. package/dist/qna.js.map +1 -0
  167. package/dist/simrel/api.d.ts +26 -0
  168. package/dist/simrel/api.d.ts.map +1 -0
  169. package/dist/simrel/catalog.d.ts +319 -0
  170. package/dist/simrel/catalog.d.ts.map +1 -0
  171. package/dist/simrel/components/GroupTabs.d.ts +17 -0
  172. package/dist/simrel/components/GroupTabs.d.ts.map +1 -0
  173. package/dist/simrel/components/ProductCard.d.ts +17 -0
  174. package/dist/simrel/components/ProductCard.d.ts.map +1 -0
  175. package/dist/simrel/components/ProductGrid.d.ts +17 -0
  176. package/dist/simrel/components/ProductGrid.d.ts.map +1 -0
  177. package/dist/simrel/components/renderUISpec.d.ts +8 -0
  178. package/dist/simrel/components/renderUISpec.d.ts.map +1 -0
  179. package/dist/simrel/index.d.ts +36 -0
  180. package/dist/simrel/index.d.ts.map +1 -0
  181. package/dist/simrel/locales/en.d.ts +3 -0
  182. package/dist/simrel/locales/en.d.ts.map +1 -0
  183. package/dist/simrel/locales/index.d.ts +6 -0
  184. package/dist/simrel/locales/index.d.ts.map +1 -0
  185. package/dist/simrel/locales/tr.d.ts +3 -0
  186. package/dist/simrel/locales/tr.d.ts.map +1 -0
  187. package/dist/simrel/types.d.ts +111 -0
  188. package/dist/simrel/types.d.ts.map +1 -0
  189. package/dist/simrel.cjs +2 -0
  190. package/dist/simrel.cjs.map +1 -0
  191. package/dist/simrel.css +1 -0
  192. package/dist/simrel.iife.js +48 -0
  193. package/dist/simrel.iife.js.map +1 -0
  194. package/dist/simrel.js +620 -0
  195. package/dist/simrel.js.map +1 -0
  196. package/dist/types-CeON7iBO.cjs +48 -0
  197. package/dist/types-CeON7iBO.cjs.map +1 -0
  198. package/dist/types-yxW8WA7u.js +4132 -0
  199. package/dist/types-yxW8WA7u.js.map +1 -0
  200. package/package.json +100 -0
package/dist/simrel.js ADDED
@@ -0,0 +1,620 @@
1
+ import { b as k, n as x, p as U, c as S, a as T, r as L, o as m, s as g, d as G, g as M, f as P, q as y, B as O, j as v, t as B, h as j, i as q, w as z, k as D, l as H, m as F } from "./types-yxW8WA7u.js";
2
+ function A(n) {
3
+ const e = n.headers.get("Content-Type") ?? "";
4
+ return e.includes("application/x-ndjson") || e.includes("text/event-stream");
5
+ }
6
+ async function $(n, e) {
7
+ const t = [], r = {
8
+ onEvent: (i) => {
9
+ const o = T(i);
10
+ if (!(!o || o.type !== "ui_spec")) {
11
+ for (const s of Object.values(o.spec.elements))
12
+ if (s.type === "ProductCard" && s.props) {
13
+ const a = s.props.product ?? s.props;
14
+ typeof a.sku == "string" && typeof a.name == "string" && t.push(a);
15
+ }
16
+ }
17
+ }
18
+ };
19
+ return e !== void 0 && (r.signal = e), await S(n, r), t;
20
+ }
21
+ async function J(n, e, t) {
22
+ const r = k("similar_products", e), i = {
23
+ method: "POST",
24
+ headers: { "Content-Type": "application/json" },
25
+ body: JSON.stringify(n)
26
+ };
27
+ t !== void 0 && (i.signal = t);
28
+ const o = await fetch(r, i);
29
+ if (!o.ok)
30
+ throw new Error(`HTTP ${o.status}: ${o.statusText}`);
31
+ if (A(o))
32
+ return $(o, t);
33
+ const s = await o.text();
34
+ return s ? x(JSON.parse(s)) : [];
35
+ }
36
+ async function W(n, e) {
37
+ const t = [];
38
+ let r = null;
39
+ const i = {
40
+ onEvent: (o) => {
41
+ const s = T(o);
42
+ if (s) {
43
+ if (s.type === "metadata" && s.meta) {
44
+ const a = s.meta.group_name;
45
+ if (typeof a == "string") {
46
+ r = { name: a, products: [] };
47
+ const d = s.meta.highlight;
48
+ typeof d == "string" && (r.highlight = d), t.push(r);
49
+ }
50
+ }
51
+ if (s.type === "ui_spec" && r) {
52
+ for (const a of Object.values(s.spec.elements))
53
+ if (a.type === "ProductCard" && a.props) {
54
+ const d = a.props.product ?? a.props;
55
+ typeof d.sku == "string" && typeof d.name == "string" && r.products.push(d);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ };
61
+ return e !== void 0 && (i.signal = e), await S(n, i), t;
62
+ }
63
+ async function Q(n, e, t) {
64
+ const r = k("product_groupings", e), i = {
65
+ method: "POST",
66
+ headers: { "Content-Type": "application/json" },
67
+ body: JSON.stringify(n)
68
+ };
69
+ t !== void 0 && (i.signal = t);
70
+ const o = await fetch(r, i);
71
+ if (!o.ok)
72
+ throw new Error(`HTTP ${o.status}: ${o.statusText}`);
73
+ if (A(o))
74
+ return W(o, t);
75
+ const s = await o.text();
76
+ return s ? U(JSON.parse(s)) : [];
77
+ }
78
+ function w(n) {
79
+ const { product: e, index: t, discountType: r, onClick: i, onAddToCart: o, renderCard: s } = n, a = n.i18n, d = a?.priceSuffix ?? " TL";
80
+ if (s) {
81
+ const c = document.createElement("div");
82
+ return c.className = "gengage-simrel-card gengage-simrel-card--custom", c.innerHTML = s(e, t), c.addEventListener("click", (h) => {
83
+ h.target.closest(".gengage-simrel-atc") || i(e);
84
+ }), c;
85
+ }
86
+ const l = document.createElement("article");
87
+ l.className = "gengage-simrel-card", l.setAttribute("role", "listitem"), l.dataset.sku = e.sku;
88
+ const u = document.createElement("div");
89
+ if (u.className = "gengage-simrel-card-image", e.imageUrl) {
90
+ const c = document.createElement("img");
91
+ c.src = e.imageUrl, c.alt = e.name, c.loading = "lazy", u.appendChild(c);
92
+ }
93
+ if (r === "badge" && e.discountPercent && e.discountPercent > 0) {
94
+ const c = document.createElement("span");
95
+ c.className = "gengage-simrel-badge", c.textContent = `%${e.discountPercent}`, u.appendChild(c);
96
+ }
97
+ l.appendChild(u);
98
+ const p = document.createElement("div");
99
+ if (p.className = "gengage-simrel-card-info", e.brand) {
100
+ const c = document.createElement("div");
101
+ c.className = "gengage-simrel-card-brand", c.textContent = e.brand, p.appendChild(c);
102
+ }
103
+ const f = document.createElement("div");
104
+ if (f.className = "gengage-simrel-card-name", f.textContent = e.name, p.appendChild(f), e.rating != null && e.rating > 0) {
105
+ const c = document.createElement("div");
106
+ c.className = "gengage-simrel-card-rating";
107
+ const h = "★".repeat(Math.round(e.rating)) + "☆".repeat(5 - Math.round(e.rating));
108
+ if (c.textContent = h, e.reviewCount != null) {
109
+ const b = document.createElement("span");
110
+ b.className = "gengage-simrel-card-review-count", b.textContent = ` (${e.reviewCount})`, c.appendChild(b);
111
+ }
112
+ p.appendChild(c);
113
+ }
114
+ const C = document.createElement("div");
115
+ if (C.className = "gengage-simrel-card-price", e.originalPrice && e.originalPrice !== e.price && (r === "strike-through" || !r)) {
116
+ const c = document.createElement("span");
117
+ c.className = "gengage-simrel-card-price-original", c.textContent = e.originalPrice + d, C.appendChild(c);
118
+ }
119
+ if (e.price) {
120
+ const c = document.createElement("span");
121
+ c.className = "gengage-simrel-card-price-current", c.textContent = e.price + d, C.appendChild(c);
122
+ }
123
+ if (p.appendChild(C), l.appendChild(p), e.cartCode) {
124
+ const c = document.createElement("button");
125
+ c.className = "gengage-simrel-atc", c.type = "button", c.textContent = a?.addToCartButton ?? "Sepete Ekle", c.addEventListener("click", (h) => {
126
+ h.stopPropagation(), o({ sku: e.sku, quantity: 1, cartCode: e.cartCode });
127
+ }), l.appendChild(c);
128
+ }
129
+ return l.addEventListener("click", (c) => {
130
+ c.target.closest(".gengage-simrel-atc") || i(e);
131
+ }), l;
132
+ }
133
+ function E(n) {
134
+ const e = document.createElement("div");
135
+ e.className = "gengage-simrel-grid", e.setAttribute("role", "list"), e.setAttribute("aria-label", n.i18n?.similarProductsAriaLabel ?? "Similar products"), n.columns && e.style.setProperty("--gengage-simrel-columns", String(n.columns));
136
+ for (let t = 0; t < n.products.length; t++) {
137
+ const i = {
138
+ product: n.products[t],
139
+ index: t,
140
+ onClick: n.onClick,
141
+ onAddToCart: n.onAddToCart
142
+ };
143
+ n.i18n !== void 0 && (i.i18n = n.i18n), n.discountType !== void 0 && (i.discountType = n.discountType), n.renderCard !== void 0 && (i.renderCard = n.renderCard);
144
+ const o = w(i);
145
+ e.appendChild(o);
146
+ }
147
+ if (n.products.length === 0) {
148
+ const t = document.createElement("div");
149
+ t.className = "gengage-simrel-empty", t.textContent = n.i18n?.emptyStateMessage ?? "Benzer ürün bulunamadı.", e.appendChild(t);
150
+ }
151
+ return e;
152
+ }
153
+ function V(n) {
154
+ const e = document.createElement("div");
155
+ if (e.className = "gengage-simrel-groups", n.groups.length === 0) {
156
+ const a = document.createElement("div");
157
+ return a.className = "gengage-simrel-empty", a.textContent = n.i18n?.emptyStateMessage ?? "Benzer ürün bulunamadı.", e.appendChild(a), e;
158
+ }
159
+ const t = document.createElement("div");
160
+ t.className = "gengage-simrel-tabs", t.setAttribute("role", "tablist");
161
+ const r = document.createElement("div");
162
+ r.className = "gengage-simrel-tab-content";
163
+ for (let a = 0; a < n.groups.length; a++) {
164
+ const d = n.groups[a], l = document.createElement("button");
165
+ l.className = "gengage-simrel-tab", l.type = "button", l.textContent = d.name, l.setAttribute("role", "tab"), l.setAttribute("aria-selected", a === 0 ? "true" : "false"), a === 0 && l.classList.add("gengage-simrel-tab--active"), l.addEventListener("click", () => {
166
+ const u = t.querySelector(".gengage-simrel-tab--active");
167
+ u?.classList.remove("gengage-simrel-tab--active"), u?.setAttribute("aria-selected", "false"), l.classList.add("gengage-simrel-tab--active"), l.setAttribute("aria-selected", "true"), r.innerHTML = "";
168
+ const p = {
169
+ products: d.products,
170
+ onClick: n.onClick,
171
+ onAddToCart: n.onAddToCart
172
+ };
173
+ n.i18n !== void 0 && (p.i18n = n.i18n), n.discountType !== void 0 && (p.discountType = n.discountType), n.renderCard !== void 0 && (p.renderCard = n.renderCard);
174
+ const f = E(p);
175
+ r.appendChild(f);
176
+ }), t.appendChild(l);
177
+ }
178
+ e.appendChild(t);
179
+ const o = {
180
+ products: n.groups[0].products,
181
+ onClick: n.onClick,
182
+ onAddToCart: n.onAddToCart
183
+ };
184
+ n.i18n !== void 0 && (o.i18n = n.i18n), n.discountType !== void 0 && (o.discountType = n.discountType), n.renderCard !== void 0 && (o.renderCard = n.renderCard);
185
+ const s = E(o);
186
+ return r.appendChild(s), e.appendChild(r), e;
187
+ }
188
+ function _(n) {
189
+ if (!n || typeof n != "object") return null;
190
+ const e = n;
191
+ if (typeof e.sku != "string" || typeof e.name != "string" || typeof e.url != "string")
192
+ return null;
193
+ const t = {
194
+ sku: e.sku,
195
+ name: e.name,
196
+ url: e.url
197
+ }, r = e.imageUrl;
198
+ typeof r == "string" && (t.imageUrl = r);
199
+ const i = e.price;
200
+ typeof i == "string" && (t.price = i);
201
+ const o = e.originalPrice;
202
+ typeof o == "string" && (t.originalPrice = o);
203
+ const s = e.discountPercent;
204
+ typeof s == "number" && (t.discountPercent = s);
205
+ const a = e.brand;
206
+ typeof a == "string" && (t.brand = a);
207
+ const d = e.rating;
208
+ typeof d == "number" && (t.rating = d);
209
+ const l = e.reviewCount;
210
+ typeof l == "number" && (t.reviewCount = l);
211
+ const u = e.cartCode;
212
+ typeof u == "string" && (t.cartCode = u);
213
+ const p = e.inStock;
214
+ return typeof p == "boolean" && (t.inStock = p), t;
215
+ }
216
+ function Y(n) {
217
+ if (!n || typeof n != "object") return null;
218
+ const e = n, t = e.title, r = e.type;
219
+ if (typeof t != "string" || typeof r != "string") return null;
220
+ const i = { title: t, type: r };
221
+ return e.payload !== void 0 && (i.payload = e.payload), i;
222
+ }
223
+ const R = {
224
+ ProductGrid: ({ element: n, renderElement: e }) => {
225
+ const t = document.createElement("div");
226
+ t.className = "gengage-simrel-grid", t.setAttribute("role", "list");
227
+ const r = n.props?.columns;
228
+ typeof r == "number" && Number.isFinite(r) && r > 0 && t.style.setProperty("--gengage-simrel-columns", String(r));
229
+ for (const i of n.children ?? []) {
230
+ const o = e(i);
231
+ o && t.appendChild(o);
232
+ }
233
+ if (t.children.length === 0) {
234
+ const i = document.createElement("div");
235
+ i.className = "gengage-simrel-empty", i.textContent = "Benzer ürün bulunamadı.", t.appendChild(i);
236
+ }
237
+ return t;
238
+ },
239
+ ProductCard: ({ element: n, context: e }) => {
240
+ const t = n.props?.product ?? n.props, r = _(t);
241
+ if (!r) return null;
242
+ const i = n.props?.index, o = typeof i == "number" && Number.isFinite(i) ? i : 0, s = n.props?.discountType, a = s === "strike-through" || s === "badge" ? s : e.discountType, d = {
243
+ product: r,
244
+ index: o,
245
+ onClick: e.onClick,
246
+ onAddToCart: e.onAddToCart,
247
+ i18n: e.i18n
248
+ };
249
+ return a !== void 0 && (d.discountType = a), e.renderCard !== void 0 && (d.renderCard = e.renderCard), w(d);
250
+ },
251
+ GroupTabs: ({ element: n, context: e }) => {
252
+ const t = n.props?.groups;
253
+ if (!Array.isArray(t)) return null;
254
+ const r = [];
255
+ for (const o of t) {
256
+ if (!o || typeof o != "object") continue;
257
+ const s = o;
258
+ if (typeof s.name != "string") continue;
259
+ const a = [];
260
+ if (Array.isArray(s.products))
261
+ for (const l of s.products) {
262
+ const u = _(l);
263
+ u && a.push(u);
264
+ }
265
+ const d = {
266
+ name: s.name,
267
+ products: a
268
+ };
269
+ typeof s.highlight == "string" && (d.highlight = s.highlight), r.push(d);
270
+ }
271
+ const i = {
272
+ groups: r,
273
+ onClick: e.onClick,
274
+ onAddToCart: e.onAddToCart,
275
+ i18n: e.i18n
276
+ };
277
+ return e.discountType !== void 0 && (i.discountType = e.discountType), e.renderCard !== void 0 && (i.renderCard = e.renderCard), V(i);
278
+ },
279
+ EmptyState: ({ element: n, context: e }) => {
280
+ const t = document.createElement("div");
281
+ t.className = "gengage-simrel-empty";
282
+ const r = n.props?.message;
283
+ return t.textContent = typeof r == "string" ? r : e.i18n.emptyStateMessage, t;
284
+ },
285
+ AddToCartButton: ({ element: n, context: e }) => {
286
+ const t = n.props?.sku, r = n.props?.cartCode;
287
+ if (typeof t != "string" || typeof r != "string") return null;
288
+ const i = document.createElement("button");
289
+ i.className = "gengage-simrel-atc", i.type = "button";
290
+ const o = n.props?.label;
291
+ return i.textContent = typeof o == "string" ? o : e.i18n.addToCartButton, i.addEventListener("click", (s) => {
292
+ s.preventDefault(), s.stopPropagation(), e.onAddToCart({ sku: t, quantity: 1, cartCode: r });
293
+ }), i;
294
+ },
295
+ QuickActions: ({ element: n, context: e }) => {
296
+ const t = document.createElement("div");
297
+ t.className = "gengage-simrel-quick-actions";
298
+ const r = n.props?.actions;
299
+ if (!Array.isArray(r) || !e.onAction) return t;
300
+ for (const i of r) {
301
+ if (!i || typeof i != "object") continue;
302
+ const o = i, s = o.label, a = Y(o.action);
303
+ if (typeof s != "string" || !a) continue;
304
+ const d = document.createElement("button");
305
+ d.className = "gengage-simrel-quick-action", d.type = "button", d.textContent = s, d.addEventListener("click", (l) => {
306
+ l.preventDefault(), l.stopPropagation(), e.onAction?.(a);
307
+ }), t.appendChild(d);
308
+ }
309
+ return t;
310
+ }
311
+ }, N = ({
312
+ element: n,
313
+ renderElement: e
314
+ }) => {
315
+ if (!n.children || n.children.length === 0)
316
+ return null;
317
+ const t = document.createElement("div");
318
+ for (const r of n.children) {
319
+ const i = e(r);
320
+ i && t.appendChild(i);
321
+ }
322
+ return t;
323
+ };
324
+ function K() {
325
+ return { ...R };
326
+ }
327
+ function X(n, e, t = R, r = N) {
328
+ return L({
329
+ spec: n,
330
+ context: e,
331
+ registry: t,
332
+ containerClassName: "gengage-simrel-uispec",
333
+ unknownRenderer: r
334
+ });
335
+ }
336
+ const I = {
337
+ similarProductsAriaLabel: "Benzer ürünler",
338
+ emptyStateMessage: "Benzer ürün bulunamadı.",
339
+ addToCartButton: "Sepete Ekle",
340
+ priceSuffix: " TL"
341
+ }, Z = {
342
+ similarProductsAriaLabel: "Similar products",
343
+ emptyStateMessage: "No similar products found.",
344
+ addToCartButton: "Add to cart",
345
+ priceSuffix: ""
346
+ };
347
+ function ee(n) {
348
+ return n ? n.toLowerCase().split("-")[0] ?? "tr" : "tr";
349
+ }
350
+ function te(n) {
351
+ return ee(n) === "en" ? Z : I;
352
+ }
353
+ const ne = m({
354
+ sku: g(),
355
+ name: g(),
356
+ imageUrl: g().url().optional(),
357
+ price: g().optional(),
358
+ originalPrice: g().optional(),
359
+ discountPercent: y().optional(),
360
+ url: g().url(),
361
+ brand: g().optional(),
362
+ rating: y().min(0).max(5).optional(),
363
+ reviewCount: y().int().nonnegative().optional()
364
+ }), re = m({
365
+ layout: P(["grid", "carousel"]).optional(),
366
+ columns: y().int().positive().optional()
367
+ }), ie = m({
368
+ product: ne,
369
+ index: y().int().nonnegative(),
370
+ discountType: P(["strike-through", "badge"]).optional()
371
+ }), oe = m({
372
+ sku: g(),
373
+ label: g().optional(),
374
+ cartCode: g()
375
+ }), se = m({
376
+ actions: G(
377
+ m({
378
+ label: g(),
379
+ action: m({
380
+ title: g(),
381
+ type: g(),
382
+ payload: M().optional()
383
+ })
384
+ })
385
+ )
386
+ }), ae = m({
387
+ message: g().optional()
388
+ }), le = {
389
+ components: {
390
+ ProductGrid: {
391
+ schema: re,
392
+ description: "Outer grid or carousel container for similar products."
393
+ },
394
+ ProductCard: {
395
+ schema: ie,
396
+ description: "A single product card with image, title, price, and actions."
397
+ },
398
+ AddToCartButton: {
399
+ schema: oe,
400
+ description: "Add-to-cart CTA rendered inside or below a product card."
401
+ },
402
+ QuickActions: {
403
+ schema: se,
404
+ description: "A row of quick-action buttons below product info."
405
+ },
406
+ EmptyState: {
407
+ schema: ae,
408
+ description: "Empty state shown when no similar products are available."
409
+ }
410
+ }
411
+ };
412
+ class ce extends O {
413
+ constructor() {
414
+ super(...arguments), this._abortController = null, this._contentEl = null, this._i18n = I;
415
+ }
416
+ async onInit(e) {
417
+ this._i18n = this._resolveI18n(e), this._contentEl = document.createElement("div"), this._contentEl.className = "gengage-simrel-container", this.root.appendChild(this._contentEl), this._lastSku = e.sku, await this._fetchAndRender(e.sku), this.isVisible = !0;
418
+ }
419
+ onUpdate(e) {
420
+ const t = e.sku;
421
+ !t || t === this._lastSku || (this._lastSku = t, this._fetchAndRender(t));
422
+ }
423
+ onShow() {
424
+ this._contentEl && (this._contentEl.style.opacity = "0", this._contentEl.style.transition = "opacity 0.3s ease-in", requestAnimationFrame(() => {
425
+ this._contentEl && (this._contentEl.style.opacity = "1");
426
+ }));
427
+ }
428
+ onHide() {
429
+ }
430
+ onDestroy() {
431
+ this._abort(), this._contentEl && (this._contentEl.remove(), this._contentEl = null);
432
+ }
433
+ // ---------------------------------------------------------------------------
434
+ // Internal event dispatchers
435
+ // ---------------------------------------------------------------------------
436
+ _handleProductClick(e) {
437
+ const t = {
438
+ sku: e.sku,
439
+ name: e.name,
440
+ url: e.url
441
+ };
442
+ 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;
443
+ const r = this.config.session?.sessionId ?? null;
444
+ v("gengage:similar:product-click", {
445
+ sku: e.sku,
446
+ url: e.url,
447
+ sessionId: r
448
+ }), this.config.onProductNavigate?.(e.url, e.sku, r);
449
+ }
450
+ _handleAddToCart(e) {
451
+ this.config.onAddToCart?.(e), v("gengage:similar:add-to-cart", e), this.track(
452
+ B(this.analyticsContext(), {
453
+ attribution_source: "simrel",
454
+ attribution_action_id: crypto.randomUUID(),
455
+ cart_value: 0,
456
+ // Host page should enrich via event listener
457
+ currency: "TRY",
458
+ line_items: e.quantity,
459
+ sku: e.sku
460
+ })
461
+ );
462
+ }
463
+ // ---------------------------------------------------------------------------
464
+ // Private
465
+ // ---------------------------------------------------------------------------
466
+ _abort() {
467
+ this._abortController?.abort(), this._abortController = null;
468
+ }
469
+ async _fetchAndRender(e) {
470
+ if (this._abort(), this._abortController = new AbortController(), !this._contentEl) return;
471
+ this._contentEl.innerHTML = "";
472
+ const t = document.createElement("div");
473
+ t.className = "gengage-simrel-loading";
474
+ const r = document.createElement("div");
475
+ r.className = "gengage-simrel-spinner", t.appendChild(r), this._contentEl.appendChild(t);
476
+ const i = {
477
+ middlewareUrl: this.config.middlewareUrl
478
+ }, o = crypto.randomUUID(), s = Date.now();
479
+ this.track(
480
+ j(this.analyticsContext(), {
481
+ endpoint: "similar_products",
482
+ request_id: o,
483
+ widget: "simrel"
484
+ })
485
+ );
486
+ try {
487
+ const a = {
488
+ account_id: this.config.accountId,
489
+ session_id: this.config.session?.sessionId ?? "",
490
+ correlation_id: this.config.session?.sessionId ?? "",
491
+ sku: e
492
+ };
493
+ this.config.domain !== void 0 && (a.domain = this.config.domain);
494
+ const d = await J(a, i, this._abortController.signal);
495
+ if (!this._contentEl) return;
496
+ if (this._contentEl.innerHTML = "", d.length > 0)
497
+ try {
498
+ const l = d.map((p) => p.sku), u = await Q(
499
+ {
500
+ account_id: this.config.accountId,
501
+ session_id: this.config.session?.sessionId ?? "",
502
+ correlation_id: this.config.session?.sessionId ?? "",
503
+ skus: l
504
+ },
505
+ i,
506
+ this._abortController.signal
507
+ );
508
+ if (u.length > 0 && this._contentEl) {
509
+ const p = this._buildGroupsSpec(u), f = this._renderUISpec(p);
510
+ this._contentEl.appendChild(f);
511
+ return;
512
+ }
513
+ } catch {
514
+ }
515
+ if (this._contentEl) {
516
+ const l = this._buildProductsSpec(d), u = this._renderUISpec(l);
517
+ this._contentEl.appendChild(u);
518
+ }
519
+ this.track(
520
+ q(this.analyticsContext(), {
521
+ request_id: o,
522
+ latency_ms: Date.now() - s,
523
+ chunk_count: d.length,
524
+ widget: "simrel"
525
+ })
526
+ ), this.track(
527
+ z(this.analyticsContext(), {
528
+ message_count: d.length,
529
+ history_ref: o,
530
+ redaction_level: "none",
531
+ widget: "simrel"
532
+ })
533
+ );
534
+ } catch (a) {
535
+ if (a instanceof DOMException && a.name === "AbortError") return;
536
+ v("gengage:global:error", {
537
+ source: "simrel",
538
+ code: "FETCH_ERROR",
539
+ message: D(this.config.locale)
540
+ }), this.track(
541
+ H(this.analyticsContext(), {
542
+ request_id: o,
543
+ error_code: "FETCH_ERROR",
544
+ error_message: a instanceof Error ? a.message : String(a),
545
+ widget: "simrel"
546
+ })
547
+ ), this._contentEl && (this._contentEl.innerHTML = "", this._contentEl.style.display = "none");
548
+ }
549
+ }
550
+ _resolveI18n(e) {
551
+ return { ...te(e.locale), ...e.i18n };
552
+ }
553
+ _resolveUISpecRegistry() {
554
+ const e = K();
555
+ return F(e, this.config.renderer?.registry);
556
+ }
557
+ _buildRenderContext() {
558
+ const e = this.config.renderCard, t = {
559
+ onClick: (r) => this._handleProductClick(r),
560
+ onAddToCart: (r) => this._handleAddToCart(r),
561
+ i18n: this._i18n
562
+ };
563
+ return this.config.discountType !== void 0 && (t.discountType = this.config.discountType), e !== void 0 && (t.renderCard = e), t;
564
+ }
565
+ _renderUISpec(e) {
566
+ const t = this._resolveUISpecRegistry(), r = this._buildRenderContext(), i = this.config.renderer?.unknownRenderer ?? N, o = (d, l) => X(d, l, t, i), s = this.config.renderer?.renderUISpec;
567
+ return s ? s(e, r, {
568
+ registry: t,
569
+ unknownRenderer: i,
570
+ defaultRender: o
571
+ }) : o(e, r);
572
+ }
573
+ _buildProductsSpec(e) {
574
+ const t = {}, r = [];
575
+ for (let i = 0; i < e.length; i++) {
576
+ const o = e[i], s = `product-${i}`;
577
+ r.push(s), t[s] = {
578
+ type: "ProductCard",
579
+ props: {
580
+ product: o,
581
+ index: i,
582
+ discountType: this.config.discountType
583
+ }
584
+ };
585
+ }
586
+ return t.root = {
587
+ type: "ProductGrid",
588
+ props: {
589
+ layout: "grid"
590
+ },
591
+ children: r
592
+ }, {
593
+ root: "root",
594
+ elements: t
595
+ };
596
+ }
597
+ _buildGroupsSpec(e) {
598
+ return {
599
+ root: "root",
600
+ elements: {
601
+ root: {
602
+ type: "GroupTabs",
603
+ props: { groups: e }
604
+ }
605
+ }
606
+ };
607
+ }
608
+ }
609
+ function ue() {
610
+ return new ce();
611
+ }
612
+ export {
613
+ ce as GengageSimRel,
614
+ K as createDefaultSimRelUISpecRegistry,
615
+ ue as createSimRelWidget,
616
+ N as defaultSimRelUnknownUISpecRenderer,
617
+ X as renderSimRelUISpec,
618
+ le as simRelCatalog
619
+ };
620
+ //# sourceMappingURL=simrel.js.map