@getspot/spot-widget 3.0.4 → 3.0.5
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.
- package/CHANGELOG.md +7 -0
- package/dist/index.es.js +139 -139
- package/dist/index.umd.js +4 -4
- package/dist/ui.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## @getspot/spot-widget [3.0.5](https://gitlab.com/getspot/spot-widget/compare/@getspot/spot-widget@3.0.4...@getspot/spot-widget@3.0.5) (2025-10-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **core:** always show items covered for batch requests ([13b7379](https://gitlab.com/getspot/spot-widget/commit/13b73794d1b07046d8e1865b09020a329109223b))
|
|
7
|
+
|
|
1
8
|
## @getspot/spot-widget [3.0.4](https://gitlab.com/getspot/spot-widget/compare/@getspot/spot-widget@3.0.3...@getspot/spot-widget@3.0.4) (2025-10-29)
|
|
2
9
|
|
|
3
10
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
async function x(m, t,
|
|
1
|
+
async function x(m, t, r) {
|
|
2
2
|
try {
|
|
3
3
|
const s = await fetch(m, {
|
|
4
4
|
method: "POST",
|
|
@@ -6,18 +6,18 @@ async function x(m, t, e) {
|
|
|
6
6
|
"Content-Type": "application/json",
|
|
7
7
|
"X-Spot-Partner-Id": t
|
|
8
8
|
},
|
|
9
|
-
body: JSON.stringify(
|
|
9
|
+
body: JSON.stringify(r)
|
|
10
10
|
}), i = await s.json();
|
|
11
11
|
if (!s.ok) {
|
|
12
|
-
const
|
|
13
|
-
throw
|
|
12
|
+
const e = new Error((i == null ? void 0 : i.message) || "Failed to fetch quote");
|
|
13
|
+
throw e.status = s.status, e.responseBody = i, e;
|
|
14
14
|
}
|
|
15
15
|
return i;
|
|
16
16
|
} catch (s) {
|
|
17
17
|
throw s instanceof Error ? s : new Error("Unknown error occurred while fetching quote");
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
async function H(m, t,
|
|
20
|
+
async function H(m, t, r) {
|
|
21
21
|
try {
|
|
22
22
|
const s = m.replace("/quote", "/quote/batch"), i = await fetch(s, {
|
|
23
23
|
method: "POST",
|
|
@@ -25,25 +25,25 @@ async function H(m, t, e) {
|
|
|
25
25
|
"Content-Type": "application/json",
|
|
26
26
|
"X-Spot-Partner-Id": t
|
|
27
27
|
},
|
|
28
|
-
body: JSON.stringify(
|
|
29
|
-
}),
|
|
28
|
+
body: JSON.stringify(r)
|
|
29
|
+
}), e = await i.json();
|
|
30
30
|
if (!i.ok) {
|
|
31
|
-
const n = new Error((
|
|
32
|
-
throw n.status = i.status, n.responseBody =
|
|
31
|
+
const n = new Error((e == null ? void 0 : e.message) || "Failed to fetch batch quote");
|
|
32
|
+
throw n.status = i.status, n.responseBody = e, n;
|
|
33
33
|
}
|
|
34
|
-
return
|
|
34
|
+
return e;
|
|
35
35
|
} catch (s) {
|
|
36
36
|
throw s instanceof Error ? s : new Error("Unknown error occurred while fetching batch quote");
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
async function
|
|
39
|
+
async function I(m, t, r) {
|
|
40
40
|
var s;
|
|
41
41
|
try {
|
|
42
42
|
const i = {
|
|
43
|
-
cartId:
|
|
44
|
-
cartName:
|
|
45
|
-
currencyCode:
|
|
46
|
-
items:
|
|
43
|
+
cartId: r.cartInfo.cartId,
|
|
44
|
+
cartName: r.cartInfo.cartName,
|
|
45
|
+
currencyCode: r.cartInfo.currencyCode,
|
|
46
|
+
items: r.items.map((a, u) => ({
|
|
47
47
|
cartItemId: a.cartItemId || `item-${u + 1}`,
|
|
48
48
|
productPrice: a.productPrice,
|
|
49
49
|
productType: a.productType,
|
|
@@ -55,36 +55,36 @@ async function D(m, t, e) {
|
|
|
55
55
|
startDate: a.startDate,
|
|
56
56
|
endDate: a.endDate
|
|
57
57
|
}))
|
|
58
|
-
},
|
|
59
|
-
if (
|
|
58
|
+
}, e = await H(m, t, i);
|
|
59
|
+
if (e.status !== "QUOTES_AVAILABLE" && e.status !== "QUOTE_AVAILABLE")
|
|
60
60
|
return { status: "NO_MATCHING_QUOTE" };
|
|
61
|
-
const n =
|
|
62
|
-
const u =
|
|
61
|
+
const n = e.quotes.map((a) => {
|
|
62
|
+
const u = r.items.find(
|
|
63
63
|
(h, f) => (h.cartItemId || `item-${f + 1}`) === a.cartItemId
|
|
64
64
|
);
|
|
65
65
|
return u ? u.participantDescription ? `${u.productName} - ${u.participantDescription}` : u.productName : `Item ${a.id}`;
|
|
66
|
-
}),
|
|
66
|
+
}), o = Math.round((e.totalSpotPrice || e.spotPrice || 0) * 100) / 100;
|
|
67
67
|
return {
|
|
68
68
|
status: "QUOTE_AVAILABLE",
|
|
69
69
|
data: {
|
|
70
|
-
id:
|
|
71
|
-
spotPrice:
|
|
72
|
-
currencyCode:
|
|
70
|
+
id: e.quotes ? e.quotes.map((a) => a.id).join(",") : ((s = e.data) == null ? void 0 : s.id) || "",
|
|
71
|
+
spotPrice: o,
|
|
72
|
+
currencyCode: e.currencyCode || "",
|
|
73
73
|
communication: {
|
|
74
|
-
...
|
|
75
|
-
yesOptionText:
|
|
76
|
-
String(
|
|
77
|
-
String(
|
|
74
|
+
...e.communication,
|
|
75
|
+
yesOptionText: e.communication.yesOptionText.replace(
|
|
76
|
+
String(e.totalSpotPrice),
|
|
77
|
+
String(o)
|
|
78
78
|
)
|
|
79
79
|
},
|
|
80
|
-
payoutSchedule:
|
|
80
|
+
payoutSchedule: e.payoutSchedule.map((a) => ({
|
|
81
81
|
...a,
|
|
82
82
|
amount: a.amount !== void 0 ? a.amount : 0
|
|
83
83
|
})),
|
|
84
84
|
coveredItems: n,
|
|
85
|
-
originalQuotes:
|
|
85
|
+
originalQuotes: e.quotes || (e.data ? [e.data] : [])
|
|
86
86
|
},
|
|
87
|
-
spotPrice:
|
|
87
|
+
spotPrice: o,
|
|
88
88
|
coveredItems: n
|
|
89
89
|
};
|
|
90
90
|
} catch (i) {
|
|
@@ -96,23 +96,23 @@ const z = {
|
|
|
96
96
|
production: "https://api.getspot.com/v1/quote",
|
|
97
97
|
local: "http://localhost:3999/api/v1/quote"
|
|
98
98
|
};
|
|
99
|
-
function
|
|
99
|
+
function D(m) {
|
|
100
100
|
const {
|
|
101
101
|
apiConfig: t = {},
|
|
102
|
-
quoteRequestData:
|
|
102
|
+
quoteRequestData: r,
|
|
103
103
|
callbacks: s = {},
|
|
104
104
|
location: i,
|
|
105
|
-
theme:
|
|
105
|
+
theme: e
|
|
106
106
|
} = m, {
|
|
107
107
|
environment: n = "sandbox",
|
|
108
|
-
partnerId:
|
|
108
|
+
partnerId: o,
|
|
109
109
|
customEndpoint: a
|
|
110
110
|
} = t;
|
|
111
|
-
if (!
|
|
111
|
+
if (!o || typeof o != "string")
|
|
112
112
|
throw new Error("Invalid or missing partnerId in apiConfig");
|
|
113
113
|
if (!(a || z[n]))
|
|
114
114
|
throw new Error(`Invalid environment in apiConfig: ${n}`);
|
|
115
|
-
if (!
|
|
115
|
+
if (!r || typeof r != "object" && !Array.isArray(r))
|
|
116
116
|
throw new Error("quoteRequestData must be a non-null object or array");
|
|
117
117
|
const h = [
|
|
118
118
|
"startDate",
|
|
@@ -166,8 +166,8 @@ function I(m) {
|
|
|
166
166
|
if (typeof c.productName != "string")
|
|
167
167
|
throw new Error(`${l}.productName must be a string`);
|
|
168
168
|
}
|
|
169
|
-
if ("cartInfo" in
|
|
170
|
-
const c =
|
|
169
|
+
if ("cartInfo" in r && "items" in r) {
|
|
170
|
+
const c = r, { cartInfo: d, items: l } = c;
|
|
171
171
|
if (!d || typeof d != "object")
|
|
172
172
|
throw new Error("quoteRequestData.cartInfo must be a non-null object");
|
|
173
173
|
if (!d.cartId || typeof d.cartId != "string")
|
|
@@ -222,16 +222,16 @@ function I(m) {
|
|
|
222
222
|
if (typeof g.productName != "string")
|
|
223
223
|
throw new Error(`${v}.productName must be a string`);
|
|
224
224
|
});
|
|
225
|
-
} else if (Array.isArray(
|
|
226
|
-
if (
|
|
225
|
+
} else if (Array.isArray(r)) {
|
|
226
|
+
if (r.length === 0)
|
|
227
227
|
throw new Error("quoteRequestData array cannot be empty");
|
|
228
|
-
|
|
228
|
+
r.forEach((c, d) => {
|
|
229
229
|
if (!c || typeof c != "object")
|
|
230
230
|
throw new Error(`quoteRequestData[${d}] must be a non-null object`);
|
|
231
231
|
f(c, d);
|
|
232
232
|
});
|
|
233
233
|
} else
|
|
234
|
-
f(
|
|
234
|
+
f(r);
|
|
235
235
|
if ([
|
|
236
236
|
"onOptIn",
|
|
237
237
|
"onOptOut",
|
|
@@ -244,33 +244,33 @@ function I(m) {
|
|
|
244
244
|
throw new Error(`Callback '${c}' must be a function.`);
|
|
245
245
|
}), typeof i == "string" && !document.querySelector(i))
|
|
246
246
|
throw new Error(`Invalid location selector: '${i}'`);
|
|
247
|
-
if (
|
|
247
|
+
if (e && typeof e != "object")
|
|
248
248
|
throw new Error(
|
|
249
249
|
"Theme must be an object with CSS variables, do not include the '--' prefix"
|
|
250
250
|
);
|
|
251
251
|
}
|
|
252
|
-
function p(m, { text: t, className:
|
|
253
|
-
const
|
|
254
|
-
return
|
|
252
|
+
function p(m, { text: t, className: r, parent: s, innerHTML: i, href: e, target: n } = {}) {
|
|
253
|
+
const o = document.createElement(m);
|
|
254
|
+
return r && (o.className = r), t != null && (o.textContent = t), i != null && (o.innerHTML = i), e && "href" in o && (o.href = e), n && "target" in o && (o.target = n), s && s.appendChild(o), o;
|
|
255
255
|
}
|
|
256
|
-
function N(m, { name: t, description:
|
|
256
|
+
function N(m, { name: t, description: r }) {
|
|
257
257
|
p("div", {
|
|
258
258
|
className: "spot-header__title",
|
|
259
259
|
text: t,
|
|
260
260
|
parent: m
|
|
261
261
|
}), p("div", {
|
|
262
262
|
className: "spot-header__description",
|
|
263
|
-
text:
|
|
263
|
+
text: r,
|
|
264
264
|
parent: m
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
267
|
function M(m, t = []) {
|
|
268
|
-
const
|
|
268
|
+
const r = p("ul", {
|
|
269
269
|
className: "spot-benefits__list",
|
|
270
270
|
parent: m
|
|
271
271
|
});
|
|
272
272
|
t.forEach((s) => {
|
|
273
|
-
const i = p("li", { parent:
|
|
273
|
+
const i = p("li", { parent: r });
|
|
274
274
|
i.innerHTML = `
|
|
275
275
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" class="spot-bullets__checkmark">
|
|
276
276
|
<path d="M11.6666 3.5L5.24998 9.91667L2.33331 7"
|
|
@@ -280,13 +280,13 @@ function M(m, t = []) {
|
|
|
280
280
|
}
|
|
281
281
|
function L(m, t = []) {
|
|
282
282
|
if (!t || t.length === 0) return;
|
|
283
|
-
const
|
|
283
|
+
const r = p("div", {
|
|
284
284
|
className: "spot-qualifying-reasons__container",
|
|
285
285
|
parent: m
|
|
286
|
-
}), s = [...t].sort((
|
|
286
|
+
}), s = [...t].sort((o, a) => o.rank - a.rank), i = p("div", {
|
|
287
287
|
className: "spot-qualifying-reasons__grid",
|
|
288
|
-
parent:
|
|
289
|
-
}),
|
|
288
|
+
parent: r
|
|
289
|
+
}), e = {
|
|
290
290
|
"Accident & Illness": "cross.svg",
|
|
291
291
|
"Family Emergencies": "users.svg",
|
|
292
292
|
Layoffs: "building.svg",
|
|
@@ -298,9 +298,9 @@ function L(m, t = []) {
|
|
|
298
298
|
};
|
|
299
299
|
let n;
|
|
300
300
|
try {
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
303
|
-
const a = new URL(
|
|
301
|
+
const o = document.currentScript;
|
|
302
|
+
if (o != null && o.src) {
|
|
303
|
+
const a = new URL(o.src);
|
|
304
304
|
n = a.origin + a.pathname.replace(/\/[^/]*$/, "/");
|
|
305
305
|
} else
|
|
306
306
|
n = window.location.origin + window.location.pathname.replace(/\/[^/]*$/, "/");
|
|
@@ -308,7 +308,7 @@ function L(m, t = []) {
|
|
|
308
308
|
} catch {
|
|
309
309
|
n = "./assets/";
|
|
310
310
|
}
|
|
311
|
-
s.forEach((
|
|
311
|
+
s.forEach((o) => {
|
|
312
312
|
var f, y, c;
|
|
313
313
|
const a = p("div", {
|
|
314
314
|
className: "spot-qualifying-reasons__item",
|
|
@@ -316,28 +316,28 @@ function L(m, t = []) {
|
|
|
316
316
|
}), u = p("div", {
|
|
317
317
|
className: "spot-qualifying-reasons__icon-wrapper",
|
|
318
318
|
parent: a
|
|
319
|
-
}), h =
|
|
319
|
+
}), h = e[((f = o.benefitType) == null ? void 0 : f.name) || ""] || e[o.name || ""];
|
|
320
320
|
if (h) {
|
|
321
321
|
const d = p("img", {
|
|
322
322
|
parent: u
|
|
323
323
|
});
|
|
324
|
-
d.src = n + h, d.alt = ((y =
|
|
324
|
+
d.src = n + h, d.alt = ((y = o.benefitType) == null ? void 0 : y.name) || o.name || "", d.className = "spot-qualifying-reasons__icon";
|
|
325
325
|
}
|
|
326
326
|
p("span", {
|
|
327
327
|
className: "spot-qualifying-reasons__label",
|
|
328
|
-
text: ((c =
|
|
328
|
+
text: ((c = o.benefitType) == null ? void 0 : c.name) || o.name || "",
|
|
329
329
|
parent: a
|
|
330
330
|
});
|
|
331
331
|
});
|
|
332
332
|
}
|
|
333
|
-
function O(m, t = [],
|
|
334
|
-
if (t.length === 0 ||
|
|
333
|
+
function O(m, t = [], r) {
|
|
334
|
+
if (t.length === 0 || !r || r <= 1)
|
|
335
335
|
return;
|
|
336
336
|
const s = /* @__PURE__ */ new Map();
|
|
337
337
|
t.forEach((d) => {
|
|
338
338
|
s.set(d, (s.get(d) || 0) + 1);
|
|
339
339
|
});
|
|
340
|
-
const
|
|
340
|
+
const e = Array.from(s.entries()).map(
|
|
341
341
|
([d, l]) => ({
|
|
342
342
|
item: d,
|
|
343
343
|
count: l,
|
|
@@ -349,12 +349,12 @@ function O(m, t = [], e) {
|
|
|
349
349
|
}), n = p("div", {
|
|
350
350
|
className: "spot-covered-items__container",
|
|
351
351
|
parent: m
|
|
352
|
-
}),
|
|
352
|
+
}), o = p("div", {
|
|
353
353
|
className: "spot-covered-items__header",
|
|
354
354
|
parent: n
|
|
355
355
|
}), a = p("button", {
|
|
356
356
|
className: "spot-covered-items__toggle",
|
|
357
|
-
parent:
|
|
357
|
+
parent: o
|
|
358
358
|
});
|
|
359
359
|
p("span", {
|
|
360
360
|
className: "spot-covered-items__title",
|
|
@@ -381,7 +381,7 @@ function O(m, t = [], e) {
|
|
|
381
381
|
className: "spot-covered-items__list",
|
|
382
382
|
parent: f
|
|
383
383
|
});
|
|
384
|
-
|
|
384
|
+
e.forEach(({ displayText: d }) => {
|
|
385
385
|
const l = p("li", { parent: y });
|
|
386
386
|
p("span", { text: d, parent: l });
|
|
387
387
|
});
|
|
@@ -391,32 +391,32 @@ function O(m, t = [], e) {
|
|
|
391
391
|
}), a.setAttribute("aria-expanded", "false"), a.setAttribute("aria-controls", "covered-items-list"), f.setAttribute("id", "covered-items-list");
|
|
392
392
|
}
|
|
393
393
|
function P(m, t = []) {
|
|
394
|
-
const
|
|
394
|
+
const r = p("div", {
|
|
395
395
|
className: "spot-table__container",
|
|
396
396
|
parent: m
|
|
397
397
|
}), s = p("table", {
|
|
398
398
|
className: "spot-refund__table spot-table--dynamic",
|
|
399
|
-
parent:
|
|
400
|
-
}), i = p("thead", { parent: s }),
|
|
401
|
-
p("th", { text: "When you cancel", parent:
|
|
399
|
+
parent: r
|
|
400
|
+
}), i = p("thead", { parent: s }), e = p("tr", { parent: i });
|
|
401
|
+
p("th", { text: "When you cancel", parent: e }), p("th", { text: "You will receive", parent: e });
|
|
402
402
|
const n = p("tbody", { parent: s });
|
|
403
|
-
t.forEach(({ text:
|
|
403
|
+
t.forEach(({ text: o, percent: a, amount: u }) => {
|
|
404
404
|
const h = p("tr", { parent: n });
|
|
405
|
-
p("td", { text:
|
|
405
|
+
p("td", { text: o, parent: h });
|
|
406
406
|
const f = a === "Not eligible for refund" ? "Not eligible for a refund" : `$${u} refund`;
|
|
407
407
|
p("td", { text: f, parent: h });
|
|
408
408
|
});
|
|
409
409
|
}
|
|
410
|
-
function $(m, t,
|
|
410
|
+
function $(m, t, r) {
|
|
411
411
|
const s = p("div", {
|
|
412
412
|
className: "spot-selection__options",
|
|
413
413
|
parent: m
|
|
414
414
|
}), i = p("label", {
|
|
415
415
|
className: `spot-selection__option ${t ? "selected" : ""}`,
|
|
416
416
|
parent: s
|
|
417
|
-
}),
|
|
418
|
-
|
|
419
|
-
text:
|
|
417
|
+
}), e = p("input", { parent: i });
|
|
418
|
+
e.type = "radio", e.name = "selection", e.value = "yes", t && (e.checked = !0), p("strong", {
|
|
419
|
+
text: r.yesOptionText,
|
|
420
420
|
parent: i
|
|
421
421
|
}), p("span", {
|
|
422
422
|
className: "spot-selection__recommended-tag",
|
|
@@ -426,12 +426,12 @@ function $(m, t, e) {
|
|
|
426
426
|
const n = p("label", {
|
|
427
427
|
className: "spot-selection__option",
|
|
428
428
|
parent: s
|
|
429
|
-
}),
|
|
430
|
-
return
|
|
429
|
+
}), o = p("input", { parent: n });
|
|
430
|
+
return o.type = "radio", o.name = "selection", o.value = "no", p("span", { text: r.noOptionText, parent: n }), s;
|
|
431
431
|
}
|
|
432
432
|
function R(m, t) {
|
|
433
433
|
var i;
|
|
434
|
-
const
|
|
434
|
+
const r = (i = t.communication) == null ? void 0 : i.paymentTerms, s = p("div", {
|
|
435
435
|
className: "spot-payment-terms",
|
|
436
436
|
parent: m
|
|
437
437
|
});
|
|
@@ -441,17 +441,17 @@ function R(m, t) {
|
|
|
441
441
|
parent: s
|
|
442
442
|
}), p("div", {
|
|
443
443
|
className: "spot-payment-terms__body",
|
|
444
|
-
text:
|
|
444
|
+
text: r || "",
|
|
445
445
|
parent: s
|
|
446
446
|
}), s;
|
|
447
447
|
}
|
|
448
|
-
function V(m, t,
|
|
449
|
-
if (
|
|
450
|
-
const
|
|
448
|
+
function V(m, t, r = "bottom-right") {
|
|
449
|
+
if (r === "top-right") {
|
|
450
|
+
const e = p("div", {
|
|
451
451
|
className: "spot-logo__top-right",
|
|
452
452
|
parent: m
|
|
453
453
|
});
|
|
454
|
-
|
|
454
|
+
e.innerHTML = `
|
|
455
455
|
<svg width="145" height="28" viewBox="0 0 145 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
456
456
|
<rect width="145" height="28"/>
|
|
457
457
|
<rect x="-655" y="-270" width="819" height="325" rx="10"/>
|
|
@@ -484,12 +484,12 @@ function V(m, t, e = "bottom-right") {
|
|
|
484
484
|
className: "spot-footer__terms-link",
|
|
485
485
|
text: "Refund Guarantee Terms and Conditions",
|
|
486
486
|
parent: i
|
|
487
|
-
}),
|
|
488
|
-
const
|
|
487
|
+
}), r === "bottom-right") {
|
|
488
|
+
const e = p("p", {
|
|
489
489
|
className: "spot-footer__powered-by",
|
|
490
490
|
parent: s
|
|
491
491
|
});
|
|
492
|
-
|
|
492
|
+
e.innerHTML = `
|
|
493
493
|
<svg width="145" height="28" viewBox="0 0 145 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
494
494
|
<rect width="145" height="28"/>
|
|
495
495
|
<rect x="-655" y="-270" width="819" height="325" rx="10"/>
|
|
@@ -534,15 +534,15 @@ class A {
|
|
|
534
534
|
}, this._onResize = this._updateLayout.bind(this), this.root = typeof this.options.location == "string" ? document.querySelector(this.options.location) : this.options.location, this.currentSelection = this.options.optInSelected ? "yes" : null, this._init();
|
|
535
535
|
}
|
|
536
536
|
async _init() {
|
|
537
|
-
var t,
|
|
537
|
+
var t, r, s, i, e;
|
|
538
538
|
try {
|
|
539
|
-
|
|
539
|
+
D(this.options);
|
|
540
540
|
let n;
|
|
541
541
|
if (this.options.useMockData && this.options.mockData)
|
|
542
542
|
n = this.options.mockData;
|
|
543
543
|
else {
|
|
544
|
-
const { environment:
|
|
545
|
-
n = "cartInfo" in this.options.quoteRequestData && "items" in this.options.quoteRequestData ? await
|
|
544
|
+
const { environment: o, partnerId: a } = this.options.apiConfig, h = this.options.apiConfig.customEndpoint || T[o];
|
|
545
|
+
n = "cartInfo" in this.options.quoteRequestData && "items" in this.options.quoteRequestData ? await I(
|
|
546
546
|
h,
|
|
547
547
|
a,
|
|
548
548
|
this.options.quoteRequestData
|
|
@@ -561,15 +561,15 @@ class A {
|
|
|
561
561
|
}
|
|
562
562
|
if (this.quote = n.data, !this.quote)
|
|
563
563
|
throw new Error("No quote data in response");
|
|
564
|
-
if (this._renderWidget(), this.options.optInSelected && ((
|
|
565
|
-
const
|
|
564
|
+
if (this._renderWidget(), this.options.optInSelected && ((r = this.options.callbacks) != null && r.onOptIn)) {
|
|
565
|
+
const o = {
|
|
566
566
|
status: "QUOTE_ACCEPTED",
|
|
567
567
|
spotPrice: this.quote.spotPrice,
|
|
568
568
|
quoteId: this.quote.id
|
|
569
569
|
};
|
|
570
570
|
if (this.quote.originalQuotes && this.quote.originalQuotes.length > 0) {
|
|
571
571
|
const a = this.options.quoteRequestData;
|
|
572
|
-
|
|
572
|
+
o.batchQuoteDetails = this.quote.originalQuotes.map((u) => {
|
|
573
573
|
var f;
|
|
574
574
|
const h = (f = a.items) == null ? void 0 : f.find(
|
|
575
575
|
(y) => (y.cartItemId || `item-${a.items.indexOf(y) + 1}`) === u.id
|
|
@@ -581,19 +581,19 @@ class A {
|
|
|
581
581
|
};
|
|
582
582
|
});
|
|
583
583
|
}
|
|
584
|
-
this.options.callbacks.onOptIn(
|
|
584
|
+
this.options.callbacks.onOptIn(o);
|
|
585
585
|
}
|
|
586
586
|
if ((s = this.options.callbacks) != null && s.onQuoteRetrieved) {
|
|
587
|
-
const
|
|
588
|
-
|
|
587
|
+
const o = this.options.callbacks.onQuoteRetrieved(this.quote);
|
|
588
|
+
o && this._applyQuoteUpdates(o);
|
|
589
589
|
}
|
|
590
590
|
} catch (n) {
|
|
591
591
|
if ((i = this.options.callbacks) != null && i.onError) {
|
|
592
|
-
const
|
|
593
|
-
(
|
|
594
|
-
message:
|
|
595
|
-
status:
|
|
596
|
-
responseBody:
|
|
592
|
+
const o = n;
|
|
593
|
+
(e = this.options.callbacks) == null || e.onError({
|
|
594
|
+
message: o.message,
|
|
595
|
+
status: o.status,
|
|
596
|
+
responseBody: o.responseBody
|
|
597
597
|
});
|
|
598
598
|
}
|
|
599
599
|
}
|
|
@@ -601,8 +601,8 @@ class A {
|
|
|
601
601
|
_renderWidget() {
|
|
602
602
|
if (!this.quote) return;
|
|
603
603
|
this.container = document.createElement("div"), this.container.className = "spot-refund-guarantee", this.root.appendChild(this.container), Object.entries(this.options.theme || {}).forEach(([s, i]) => {
|
|
604
|
-
const
|
|
605
|
-
this.container.style.setProperty(
|
|
604
|
+
const e = `--${s}`;
|
|
605
|
+
this.container.style.setProperty(e, i);
|
|
606
606
|
}), N(this.container, this.quote.communication);
|
|
607
607
|
const t = document.createElement("div");
|
|
608
608
|
if (t.className = "spot-content__wrapper", this.container.appendChild(t), this.quote.qualifyingReasons ? L(t, this.quote.qualifyingReasons) : M(t, this.quote.communication.bulletPoints), this.quote.coveredItems) {
|
|
@@ -610,22 +610,22 @@ class A {
|
|
|
610
610
|
O(t, this.quote.coveredItems, s);
|
|
611
611
|
}
|
|
612
612
|
this.options.showTable && !this.quote.qualifyingReasons && P(t, this.quote.payoutSchedule);
|
|
613
|
-
const
|
|
613
|
+
const r = $(
|
|
614
614
|
t,
|
|
615
615
|
this.options.optInSelected,
|
|
616
616
|
this.quote.communication
|
|
617
617
|
);
|
|
618
|
-
t.appendChild(
|
|
618
|
+
t.appendChild(r), this.paymentTermsEl = p("div", {
|
|
619
619
|
className: "spot-payment-terms__wrapper",
|
|
620
620
|
parent: t
|
|
621
|
-
}), V(this.container, this.quote, this.options.logoPosition), window.addEventListener("resize", this._onResize), this._setupResizeObserver(), this._updateLayout(), this._setupOptionListeners(
|
|
621
|
+
}), V(this.container, this.quote, this.options.logoPosition), window.addEventListener("resize", this._onResize), this._setupResizeObserver(), this._updateLayout(), this._setupOptionListeners(r);
|
|
622
622
|
}
|
|
623
623
|
_updateLayout() {
|
|
624
624
|
if (!this.container || !this.quote) return;
|
|
625
625
|
const t = this.container.querySelector(
|
|
626
626
|
".spot-content__wrapper"
|
|
627
|
-
),
|
|
628
|
-
if (!t || !
|
|
627
|
+
), r = this.options.showTable && !this.quote.qualifyingReasons;
|
|
628
|
+
if (!t || !r) {
|
|
629
629
|
t == null || t.classList.remove("desktop-layout");
|
|
630
630
|
return;
|
|
631
631
|
}
|
|
@@ -633,19 +633,19 @@ class A {
|
|
|
633
633
|
t.classList.toggle("desktop-layout", s);
|
|
634
634
|
}
|
|
635
635
|
_shouldUseDesktopLayout(t) {
|
|
636
|
-
const
|
|
637
|
-
if (
|
|
636
|
+
const r = this.container.offsetWidth - 40, s = 325, i = 16;
|
|
637
|
+
if (r >= 900)
|
|
638
638
|
return !0;
|
|
639
|
-
if (
|
|
640
|
-
const
|
|
639
|
+
if (r >= 650) {
|
|
640
|
+
const e = t.classList.contains("desktop-layout");
|
|
641
641
|
t.classList.remove("desktop-layout"), t.offsetHeight;
|
|
642
642
|
const n = t.querySelector(
|
|
643
643
|
".spot-benefits__list, .spot-qualifying-reasons__container"
|
|
644
644
|
);
|
|
645
645
|
if (!n)
|
|
646
|
-
return
|
|
646
|
+
return e && t.classList.add("desktop-layout"), e;
|
|
647
647
|
const a = Math.min(n.scrollWidth, 400) + s + i;
|
|
648
|
-
return
|
|
648
|
+
return e && t.classList.add("desktop-layout"), r >= a;
|
|
649
649
|
}
|
|
650
650
|
return !1;
|
|
651
651
|
}
|
|
@@ -666,14 +666,14 @@ class A {
|
|
|
666
666
|
)), this.destroy(), this._renderWidget());
|
|
667
667
|
}
|
|
668
668
|
_setupOptionListeners(t) {
|
|
669
|
-
const
|
|
669
|
+
const r = t.querySelectorAll(
|
|
670
670
|
'input[type="radio"]'
|
|
671
671
|
), s = t.querySelectorAll(".spot-selection__option");
|
|
672
|
-
|
|
673
|
-
i.addEventListener("change", (
|
|
672
|
+
r.forEach((i) => {
|
|
673
|
+
i.addEventListener("change", (e) => {
|
|
674
674
|
var a, u, h;
|
|
675
|
-
const n =
|
|
676
|
-
if (this.hideSelectionError(), this.currentSelection =
|
|
675
|
+
const n = e.target, o = n.value;
|
|
676
|
+
if (this.hideSelectionError(), this.currentSelection = o, s.forEach((f) => f.classList.remove("selected")), (a = n.closest(".spot-selection__option")) == null || a.classList.add("selected"), this.paymentTermsEl && (this.paymentTermsEl.innerHTML = ""), o === "yes" && (this.options.quoteRequestData.isPartialPayment && R(this.paymentTermsEl, this.quote), (u = this.options.callbacks) != null && u.onOptIn)) {
|
|
677
677
|
const f = {
|
|
678
678
|
status: "QUOTE_ACCEPTED",
|
|
679
679
|
spotPrice: this.quote.spotPrice,
|
|
@@ -697,7 +697,7 @@ class A {
|
|
|
697
697
|
}
|
|
698
698
|
this.options.callbacks.onOptIn(f);
|
|
699
699
|
}
|
|
700
|
-
if (
|
|
700
|
+
if (o === "no" && ((h = this.options.callbacks) != null && h.onOptOut)) {
|
|
701
701
|
const f = {
|
|
702
702
|
status: "QUOTE_DECLINED",
|
|
703
703
|
quoteId: this.quote.id
|
|
@@ -727,10 +727,10 @@ class A {
|
|
|
727
727
|
var t;
|
|
728
728
|
if (!this.errorEl) {
|
|
729
729
|
this.errorEl = document.createElement("div"), this.errorEl.className = "spot-selection__error", this.errorEl.textContent = "Please make a selection";
|
|
730
|
-
const
|
|
730
|
+
const r = (t = this.container) == null ? void 0 : t.querySelector(
|
|
731
731
|
".spot-selection__options"
|
|
732
732
|
);
|
|
733
|
-
|
|
733
|
+
r && r.insertAdjacentElement("afterend", this.errorEl);
|
|
734
734
|
}
|
|
735
735
|
this.errorEl.style.display = "block";
|
|
736
736
|
}
|
|
@@ -745,14 +745,14 @@ class A {
|
|
|
745
745
|
return t ? this.hideSelectionError() : this.showSelectionError(), t;
|
|
746
746
|
}
|
|
747
747
|
async updateQuote(t) {
|
|
748
|
-
var
|
|
748
|
+
var r, s, i, e;
|
|
749
749
|
try {
|
|
750
750
|
const n = {
|
|
751
751
|
...this.options,
|
|
752
752
|
quoteRequestData: t
|
|
753
753
|
};
|
|
754
|
-
|
|
755
|
-
const { environment:
|
|
754
|
+
D(n);
|
|
755
|
+
const { environment: o, partnerId: a, customEndpoint: u } = this.options.apiConfig, h = u || T[o], y = "cartInfo" in n.quoteRequestData && "items" in n.quoteRequestData ? await I(
|
|
756
756
|
h,
|
|
757
757
|
a,
|
|
758
758
|
n.quoteRequestData
|
|
@@ -762,7 +762,7 @@ class A {
|
|
|
762
762
|
n.quoteRequestData
|
|
763
763
|
);
|
|
764
764
|
if (y.status !== "QUOTE_AVAILABLE")
|
|
765
|
-
return y.status === "NO_MATCHING_QUOTE" && ((
|
|
765
|
+
return y.status === "NO_MATCHING_QUOTE" && ((r = this.options.callbacks) != null && r.noMatchingQuote) && this.options.callbacks.noMatchingQuote({
|
|
766
766
|
status: "NO_MATCHING_QUOTE",
|
|
767
767
|
data: n.quoteRequestData
|
|
768
768
|
}), !1;
|
|
@@ -772,33 +772,33 @@ class A {
|
|
|
772
772
|
}
|
|
773
773
|
return !0;
|
|
774
774
|
} catch (n) {
|
|
775
|
-
const
|
|
776
|
-
return (
|
|
777
|
-
message:
|
|
778
|
-
status:
|
|
779
|
-
responseBody:
|
|
775
|
+
const o = n;
|
|
776
|
+
return (e = (i = this.options.callbacks) == null ? void 0 : i.onError) == null || e.call(i, {
|
|
777
|
+
message: o.message,
|
|
778
|
+
status: o.status,
|
|
779
|
+
responseBody: o.responseBody
|
|
780
780
|
}), !1;
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
783
|
getSelection() {
|
|
784
|
-
var
|
|
784
|
+
var r, s, i;
|
|
785
785
|
if (this.currentSelection == null) return null;
|
|
786
786
|
const t = {
|
|
787
787
|
selection: this.currentSelection,
|
|
788
|
-
quoteId: (
|
|
788
|
+
quoteId: (r = this.quote) == null ? void 0 : r.id,
|
|
789
789
|
spotPrice: (s = this.quote) == null ? void 0 : s.spotPrice,
|
|
790
790
|
status: this.currentSelection === "yes" ? "QUOTE_ACCEPTED" : "QUOTE_DECLINED"
|
|
791
791
|
};
|
|
792
792
|
if ((i = this.quote) != null && i.originalQuotes && this.quote.originalQuotes.length > 0) {
|
|
793
|
-
const
|
|
793
|
+
const e = this.options.quoteRequestData;
|
|
794
794
|
t.batchQuoteDetails = this.quote.originalQuotes.map((n) => {
|
|
795
795
|
var a;
|
|
796
|
-
const
|
|
797
|
-
(u) => (u.cartItemId || `item-${
|
|
796
|
+
const o = (a = e.items) == null ? void 0 : a.find(
|
|
797
|
+
(u) => (u.cartItemId || `item-${e.items.indexOf(u) + 1}`) === n.id
|
|
798
798
|
);
|
|
799
799
|
return {
|
|
800
800
|
quoteId: n.id,
|
|
801
|
-
productPrice: (
|
|
801
|
+
productPrice: (o == null ? void 0 : o.productPrice) || n.spotPrice,
|
|
802
802
|
cartItemId: n.id
|
|
803
803
|
};
|
|
804
804
|
});
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(_,C){typeof exports=="object"&&typeof module<"u"?module.exports=C():typeof define=="function"&&define.amd?define(C):(_=typeof globalThis<"u"?globalThis:_||self,_.SpotWidget=C())})(this,function(){"use strict";async function _(m,t,
|
|
1
|
+
(function(_,C){typeof exports=="object"&&typeof module<"u"?module.exports=C():typeof define=="function"&&define.amd?define(C):(_=typeof globalThis<"u"?globalThis:_||self,_.SpotWidget=C())})(this,function(){"use strict";async function _(m,t,r){try{const s=await fetch(m,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(r)}),i=await s.json();if(!s.ok){const e=new Error((i==null?void 0:i.message)||"Failed to fetch quote");throw e.status=s.status,e.responseBody=i,e}return i}catch(s){throw s instanceof Error?s:new Error("Unknown error occurred while fetching quote")}}async function C(m,t,r){try{const s=m.replace("/quote","/quote/batch"),i=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Spot-Partner-Id":t},body:JSON.stringify(r)}),e=await i.json();if(!i.ok){const n=new Error((e==null?void 0:e.message)||"Failed to fetch batch quote");throw n.status=i.status,n.responseBody=e,n}return e}catch(s){throw s instanceof Error?s:new Error("Unknown error occurred while fetching batch quote")}}async function k(m,t,r){var s;try{const i={cartId:r.cartInfo.cartId,cartName:r.cartInfo.cartName,currencyCode:r.cartInfo.currencyCode,items:r.items.map((a,u)=>({cartItemId:a.cartItemId||`item-${u+1}`,productPrice:a.productPrice,productType:a.productType,productDuration:a.productDuration,productId:a.productId,productName:a.productName,participantDescription:a.participantDescription,eventType:a.eventType,startDate:a.startDate,endDate:a.endDate}))},e=await C(m,t,i);if(e.status!=="QUOTES_AVAILABLE"&&e.status!=="QUOTE_AVAILABLE")return{status:"NO_MATCHING_QUOTE"};const n=e.quotes.map(a=>{const u=r.items.find((h,f)=>(h.cartItemId||`item-${f+1}`)===a.cartItemId);return u?u.participantDescription?`${u.productName} - ${u.participantDescription}`:u.productName:`Item ${a.id}`}),o=Math.round((e.totalSpotPrice||e.spotPrice||0)*100)/100;return{status:"QUOTE_AVAILABLE",data:{id:e.quotes?e.quotes.map(a=>a.id).join(","):((s=e.data)==null?void 0:s.id)||"",spotPrice:o,currencyCode:e.currencyCode||"",communication:{...e.communication,yesOptionText:e.communication.yesOptionText.replace(String(e.totalSpotPrice),String(o))},payoutSchedule:e.payoutSchedule.map(a=>({...a,amount:a.amount!==void 0?a.amount:0})),coveredItems:n,originalQuotes:e.quotes||(e.data?[e.data]:[])},spotPrice:o,coveredItems:n}}catch(i){throw i instanceof Error?i:new Error("Unknown error occurred while fetching multiple quotes")}}const z={sandbox:"https://api.sandbox.getspot.com/v1/quote",production:"https://api.getspot.com/v1/quote",local:"http://localhost:3999/api/v1/quote"};function x(m){const{apiConfig:t={},quoteRequestData:r,callbacks:s={},location:i,theme:e}=m,{environment:n="sandbox",partnerId:o,customEndpoint:a}=t;if(!o||typeof o!="string")throw new Error("Invalid or missing partnerId in apiConfig");if(!(a||z[n]))throw new Error(`Invalid environment in apiConfig: ${n}`);if(!r||typeof r!="object"&&!Array.isArray(r))throw new Error("quoteRequestData must be a non-null object or array");const h=["startDate","endDate","currencyCode","eventType","productType","productDuration","productPrice","productId","cartId","productName"];function f(c,d=null){const l=d!==null?`quoteRequestData[${d}]`:"quoteRequestData";h.forEach(v=>{if(!Object.prototype.hasOwnProperty.call(c,v)||c[v]===void 0||c[v]===null)throw new Error(`Missing required ${l} field: '${v}'`)});const b=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!b.test(c.startDate))throw new Error(`${l}.startDate must be a valid ISO8601 string`);if(!b.test(c.endDate))throw new Error(`${l}.endDate must be a valid ISO8601 string`);if(typeof c.currencyCode!="string")throw new Error(`${l}.currencyCode must be a string`);if(!["USD","CAD","AUD"].includes(c.currencyCode))throw new Error(`Invalid ${l}.currencyCode: ${c.currencyCode}`);if(typeof c.eventType!="string")throw new Error(`${l}.eventType must be a string`);if(typeof c.productType!="string")throw new Error(`${l}.productType must be a string`);const g=["Pass","Trip","Registration"];if(!g.includes(c.productType))throw new Error(`${l}.productType must be one of ${g.join(", ")}`);if(typeof c.productDuration!="string")throw new Error(`${l}.productDuration must be a string`);const w=["Daily","Seasonal","Trip","Event"];if(!w.includes(c.productDuration))throw new Error(`${l}.productDuration must be one of ${w.join(", ")}`);if(typeof c.productPrice!="number"||isNaN(c.productPrice))throw new Error(`${l}.productPrice must be a valid number`);if(typeof c.productId!="string")throw new Error(`${l}.productId must be a string`);if(typeof c.cartId!="string")throw new Error(`${l}.cartId must be a string`);if(typeof c.productName!="string")throw new Error(`${l}.productName must be a string`)}if("cartInfo"in r&&"items"in r){const c=r,{cartInfo:d,items:l}=c;if(!d||typeof d!="object")throw new Error("quoteRequestData.cartInfo must be a non-null object");if(!d.cartId||typeof d.cartId!="string")throw new Error("quoteRequestData.cartInfo.cartId must be a string");if(!d.cartName||typeof d.cartName!="string")throw new Error("quoteRequestData.cartInfo.cartName must be a string");if(!d.currencyCode||typeof d.currencyCode!="string")throw new Error("quoteRequestData.cartInfo.currencyCode must be a string");if(!["USD","CAD","AUD"].includes(d.currencyCode))throw new Error(`Invalid quoteRequestData.cartInfo.currencyCode: ${d.currencyCode}`);if(!Array.isArray(l)||l.length===0)throw new Error("quoteRequestData.items must be a non-empty array");const q=["startDate","endDate","eventType","productType","productDuration","productPrice","productId","productName"];l.forEach((g,w)=>{if(!g||typeof g!="object")throw new Error(`quoteRequestData.items[${w}] must be a non-null object`);const v=`quoteRequestData.items[${w}]`;q.forEach(E=>{if(!Object.prototype.hasOwnProperty.call(g,E)||g[E]===void 0||g[E]===null)throw new Error(`Missing required ${v} field: '${E}'`)});const D=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;if(!D.test(g.startDate))throw new Error(`${v}.startDate must be a valid ISO8601 string`);if(!D.test(g.endDate))throw new Error(`${v}.endDate must be a valid ISO8601 string`);if(typeof g.eventType!="string")throw new Error(`${v}.eventType must be a string`);if(typeof g.productType!="string")throw new Error(`${v}.productType must be a string`);const T=["Pass","Trip","Registration"];if(!T.includes(g.productType))throw new Error(`${v}.productType must be one of ${T.join(", ")}`);if(typeof g.productDuration!="string")throw new Error(`${v}.productDuration must be a string`);const H=["Daily","Seasonal","Trip","Event"];if(!H.includes(g.productDuration))throw new Error(`${v}.productDuration must be one of ${H.join(", ")}`);if(typeof g.productPrice!="number"||isNaN(g.productPrice))throw new Error(`${v}.productPrice must be a valid number`);if(typeof g.productId!="string")throw new Error(`${v}.productId must be a string`);if(typeof g.productName!="string")throw new Error(`${v}.productName must be a string`)})}else if(Array.isArray(r)){if(r.length===0)throw new Error("quoteRequestData array cannot be empty");r.forEach((c,d)=>{if(!c||typeof c!="object")throw new Error(`quoteRequestData[${d}] must be a non-null object`);f(c,d)})}else f(r);if(["onOptIn","onOptOut","onQuoteRetrieved","onError","noMatchingQuote"].forEach(c=>{const d=s[c];if(d&&typeof d!="function")throw new Error(`Callback '${c}' must be a function.`)}),typeof i=="string"&&!document.querySelector(i))throw new Error(`Invalid location selector: '${i}'`);if(e&&typeof e!="object")throw new Error("Theme must be an object with CSS variables, do not include the '--' prefix")}function p(m,{text:t,className:r,parent:s,innerHTML:i,href:e,target:n}={}){const o=document.createElement(m);return r&&(o.className=r),t!=null&&(o.textContent=t),i!=null&&(o.innerHTML=i),e&&"href"in o&&(o.href=e),n&&"target"in o&&(o.target=n),s&&s.appendChild(o),o}function N(m,{name:t,description:r}){p("div",{className:"spot-header__title",text:t,parent:m}),p("div",{className:"spot-header__description",text:r,parent:m})}function M(m,t=[]){const r=p("ul",{className:"spot-benefits__list",parent:m});t.forEach(s=>{const i=p("li",{parent:r});i.innerHTML=`
|
|
2
2
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" class="spot-bullets__checkmark">
|
|
3
3
|
<path d="M11.6666 3.5L5.24998 9.91667L2.33331 7"
|
|
4
4
|
stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
-
</svg>`,p("span",{text:s,parent:i})})}function L(m,t=[]){if(!t||t.length===0)return;const
|
|
5
|
+
</svg>`,p("span",{text:s,parent:i})})}function L(m,t=[]){if(!t||t.length===0)return;const r=p("div",{className:"spot-qualifying-reasons__container",parent:m}),s=[...t].sort((o,a)=>o.rank-a.rank),i=p("div",{className:"spot-qualifying-reasons__grid",parent:r}),e={"Accident & Illness":"cross.svg","Family Emergencies":"users.svg",Layoffs:"building.svg","Jury Duty":"scale.svg","Work Travel Conflict":"briefcase.svg","Severe Weather":"umbrella.svg","Travel Interruption":"plane.svg","Military Duty":"medal.svg"};let n;try{const o=document.currentScript;if(o!=null&&o.src){const a=new URL(o.src);n=a.origin+a.pathname.replace(/\/[^/]*$/,"/")}else n=window.location.origin+window.location.pathname.replace(/\/[^/]*$/,"/");n+="assets/"}catch{n="./assets/"}s.forEach(o=>{var f,y,c;const a=p("div",{className:"spot-qualifying-reasons__item",parent:i}),u=p("div",{className:"spot-qualifying-reasons__icon-wrapper",parent:a}),h=e[((f=o.benefitType)==null?void 0:f.name)||""]||e[o.name||""];if(h){const d=p("img",{parent:u});d.src=n+h,d.alt=((y=o.benefitType)==null?void 0:y.name)||o.name||"",d.className="spot-qualifying-reasons__icon"}p("span",{className:"spot-qualifying-reasons__label",text:((c=o.benefitType)==null?void 0:c.name)||o.name||"",parent:a})})}function O(m,t=[],r){if(t.length===0||!r||r<=1)return;const s=new Map;t.forEach(d=>{s.set(d,(s.get(d)||0)+1)});const e=Array.from(s.entries()).map(([d,l])=>({item:d,count:l,displayText:l>1?`${l} x ${d}`:d})).sort((d,l)=>{const b=d.item.charAt(0),q=l.item.charAt(0),g=/[a-zA-Z]/.test(b),w=/[a-zA-Z]/.test(q);return!g&&w?-1:g&&!w?1:d.item.localeCompare(l.item,void 0,{sensitivity:"base"})}),n=p("div",{className:"spot-covered-items__container",parent:m}),o=p("div",{className:"spot-covered-items__header",parent:n}),a=p("button",{className:"spot-covered-items__toggle",parent:o});p("span",{className:"spot-covered-items__title",text:`Items Covered in Your Cart (${t.length})`,parent:a});const u=p("div",{className:"spot-covered-items__right-section",parent:a});p("span",{className:"spot-covered-items__view-all",text:"View All",parent:u});const h=p("span",{className:"spot-covered-items__arrow",innerHTML:"▼",parent:u}),f=p("div",{className:"spot-covered-items__content",parent:n}),y=p("ul",{className:"spot-covered-items__list",parent:f});e.forEach(({displayText:d})=>{const l=p("li",{parent:y});p("span",{text:d,parent:l})});let c=!1;f.style.display="none",a.addEventListener("click",()=>{c=!c,f.style.display=c?"block":"none",h.innerHTML=c?"▲":"▼",a.setAttribute("aria-expanded",c.toString())}),a.setAttribute("aria-expanded","false"),a.setAttribute("aria-controls","covered-items-list"),f.setAttribute("id","covered-items-list")}function P(m,t=[]){const r=p("div",{className:"spot-table__container",parent:m}),s=p("table",{className:"spot-refund__table spot-table--dynamic",parent:r}),i=p("thead",{parent:s}),e=p("tr",{parent:i});p("th",{text:"When you cancel",parent:e}),p("th",{text:"You will receive",parent:e});const n=p("tbody",{parent:s});t.forEach(({text:o,percent:a,amount:u})=>{const h=p("tr",{parent:n});p("td",{text:o,parent:h});const f=a==="Not eligible for refund"?"Not eligible for a refund":`$${u} refund`;p("td",{text:f,parent:h})})}function $(m,t,r){const s=p("div",{className:"spot-selection__options",parent:m}),i=p("label",{className:`spot-selection__option ${t?"selected":""}`,parent:s}),e=p("input",{parent:i});e.type="radio",e.name="selection",e.value="yes",t&&(e.checked=!0),p("strong",{text:r.yesOptionText,parent:i}),p("span",{className:"spot-selection__recommended-tag",text:"Recommended",parent:i});const n=p("label",{className:"spot-selection__option",parent:s}),o=p("input",{parent:n});return o.type="radio",o.name="selection",o.value="no",p("span",{text:r.noOptionText,parent:n}),s}function R(m,t){var i;const r=(i=t.communication)==null?void 0:i.paymentTerms,s=p("div",{className:"spot-payment-terms",parent:m});return p("div",{className:"spot-payment-terms__header",text:"PAYMENT TERMS",parent:s}),p("div",{className:"spot-payment-terms__body",text:r||"",parent:s}),s}function V(m,t,r="bottom-right"){if(r==="top-right"){const e=p("div",{className:"spot-logo__top-right",parent:m});e.innerHTML=`
|
|
6
6
|
<svg width="145" height="28" viewBox="0 0 145 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
7
7
|
<rect width="145" height="28"/>
|
|
8
8
|
<rect x="-655" y="-270" width="819" height="325" rx="10"/>
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<rect width="45.405" height="14.8867" fill="white" transform="translate(87 8)"/>
|
|
18
18
|
</clipPath>
|
|
19
19
|
</defs>
|
|
20
|
-
</svg>`}const s=p("div",{className:"spot-footer__container",parent:m}),i=p("div",{className:"spot-footer__terms",parent:s});if(p("span",{innerHTML:t.communication.legalDisclaimer,parent:i}),p("br",{parent:i}),p("a",{href:t.communication.termsAndConditionsUrl,target:"_blank",className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:i}),
|
|
20
|
+
</svg>`}const s=p("div",{className:"spot-footer__container",parent:m}),i=p("div",{className:"spot-footer__terms",parent:s});if(p("span",{innerHTML:t.communication.legalDisclaimer,parent:i}),p("br",{parent:i}),p("a",{href:t.communication.termsAndConditionsUrl,target:"_blank",className:"spot-footer__terms-link",text:"Refund Guarantee Terms and Conditions",parent:i}),r==="bottom-right"){const e=p("p",{className:"spot-footer__powered-by",parent:s});e.innerHTML=`
|
|
21
21
|
<svg width="145" height="28" viewBox="0 0 145 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
22
22
|
<rect width="145" height="28"/>
|
|
23
23
|
<rect x="-655" y="-270" width="819" height="325" rx="10"/>
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
<rect width="45.405" height="14.8867" fill="white" transform="translate(87 8)"/>
|
|
33
33
|
</clipPath>
|
|
34
34
|
</defs>
|
|
35
|
-
</svg>`}return s}const S=":root{--spot-font-family: Arial;--spot-padding: 1.25rem;--spot-background-color: #ffffff;--spot-font-color: #000000;--spot-border-radius: .5rem;--spot-title-font-size: 1.25rem;--spot-title-font-weight: 700;--spot-title-padding: 0 0 1.25rem 0;--spot-description-font-size: .875rem;--spot-description-font-weight: 400;--spot-description-padding: 0 0 .5rem 0;--spot-bullets-font-size: .875rem;--spot-bullets-font-weight: 400;--spot-bullets-padding: .3125rem;--spot-bullets-checkmark-color: #2e2e2e;--spot-table-border-radius: .625rem;--spot-table-header-font-size: .875rem;--spot-table-header-font-weight: 700;--spot-table-header-padding: 0 .5rem .625rem;--spot-table-cell-font-size: .815rem;--spot-table-cell-font-weight: 400;--spot-table-cell-padding: 0 .625rem;--spot-radio-border: #000000;--spot-radio-border-radius: .625rem;--spot-radio-checked-background: #000000;--spot-radio-text-font-size: .875rem;--spot-radio-text-font-weight: 400;--spot-radio-text-padding: .625rem;--spot-radio-selection-background: #f4f4f4;--spot-radio-selection-border-radius: .625rem;--spot-radio-selection-padding: .625rem;--spot-recommended-tag-background: #000000;--spot-recommended-tag-font-color: #ffffff;--spot-recommended-tag-font-size: .875rem;--spot-recommended-tag-font-weight: 700;--spot-recommended-tag-padding: .25rem .5rem;--spot-recommended-tag-border-radius: .5rem;--spot-selection-error-font-color: #ff0000;--spot-selection-error-font-size: .875rem;--spot-qualifying-reasons-margin: .75rem 0;--spot-qualifying-reasons-padding: 0 .3125rem;--spot-qualifying-reasons-column-gap: 3rem;--spot-qualifying-reasons-row-gap: .25rem;--spot-qualifying-reasons-grid-padding-left: 1rem;--spot-qualifying-reasons-icon-wrapper-size: 1.125rem;--spot-qualifying-reasons-icon-size: .75rem;--spot-qualifying-reasons-icon-border-color: #2e2e2e;--spot-qualifying-reasons-icon-border-width: 1px;--spot-qualifying-reasons-icon-background: #ffffff;--spot-qualifying-reasons-item-gap: .625rem;--spot-qualifying-reasons-label-font-size: .8rem;--spot-qualifying-reasons-label-font-weight: 400;--spot-qualifying-reasons-label-font-color: #000000;--spot-qualifying-reasons-label-font-family: Arial;--spot-selection-error-padding: .5rem;--spot-payment-terms-background: #f4f4f4;--spot-payment-terms-border-radius: .625rem;--spot-payment-terms-padding: 1rem;--spot-payment-terms-font-color: #636569;--spot-payment-terms-font-size: .75rem;--spot-payment-terms-header-font-weight: 700;--spot-payment-terms-header-font-size: .875rem;--spot-payment-terms-header-margin-bottom: .5rem;--spot-payment-terms-header-border-color: #c2c2c2;--spot-payment-terms-header-padding: 0 0 .5rem 0;--spot-terms-font-size: .75rem;--spot-terms-font-weight: 400;--spot-terms-font-color: #636569;--spot-terms-padding: 0;--spot-terms-link-text-decoration: underline;--spot-terms-link-font-size: .75rem;--spot-terms-link-font-weight: 400;--spot-terms-link-font-color: #636569;--spot-terms-link-padding: 0;--spot-covered-items-background: #f1f3f5;--spot-covered-items-hover-background: #e9ecef;--spot-covered-items-border-radius: .5rem;--spot-covered-items-padding: .75rem 1rem;--spot-covered-items-font-size: .875rem;--spot-covered-items-font-weight: 400;--spot-covered-items-font-color: #000000;--spot-covered-items-font-family: Arial;--spot-covered-items-arrow-font-size: .6rem;--spot-covered-items-arrow-color: #636569;--spot-covered-items-view-all-color: #636569;--spot-covered-items-view-all-font-size: .875rem;--spot-covered-items-view-all-font-weight: 400;--spot-covered-items-content-background: #f8f9fa;--spot-covered-items-content-border: 1px solid #e0e0e0;--spot-covered-items-content-border-radius: .5rem;--spot-covered-items-content-padding: .75rem 1rem;--spot-desktop-radio-margin-top: -1.5rem;--spot-benefits-margin-bottom: 0rem;--spot-covered-items-margin-bottom: 1.5rem;--spot-footer-gap: 1rem;--spot-footer-terms-margin-right: 7rem;--spot-payment-terms-margin-top: .5rem;--spot-logo-top-right-margin: 1rem}.spot-refund-guarantee{font-family:var(--spot-font-family);padding:var(--spot-padding);background-color:var(--spot-background-color);color:var(--spot-font-color);border:.0625rem solid #e0e0e0;border-radius:var(--spot-border-radius);max-width:51rem;margin:1rem;container-type:inline-size;position:relative;word-wrap:normal;overflow-wrap:normal;-webkit-hyphens:none;hyphens:none}.spot-refund-guarantee *{color:inherit}.spot-header__title{font-size:var(--spot-title-font-size);font-weight:var(--spot-title-font-weight);padding:var(--spot-title-padding);color:var(--spot-title-font-color);font-family:var(--spot-title-font-family);line-height:120%;letter-spacing:-.03125rem}.spot-header__description{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:var(--spot-description-padding);line-height:125%;letter-spacing:-.025rem}.spot-content__wrapper{display:flex;flex-direction:column}.spot-content__wrapper.desktop-layout{display:grid;grid-template-columns:1fr auto;align-items:start;gap:1rem}.desktop-layout .spot-benefits__list,.desktop-layout .spot-qualifying-reasons__container,.desktop-layout .spot-covered-items__container,.desktop-layout .spot-selection__options{min-width:0;word-wrap:normal}.desktop-layout .spot-benefits__list,.desktop-layout .spot-qualifying-reasons__container{grid-row:1;margin-bottom:var(--spot-benefits-margin-bottom)}.desktop-layout .spot-covered-items__container{grid-row:2;grid-column:1;margin-bottom:var(--spot-covered-items-margin-bottom)}.desktop-layout .spot-selection__options{grid-row:3;margin-top:var(--spot-desktop-radio-margin-top)}.desktop-layout .spot-payment-terms__wrapper{grid-row:4;grid-column:1;margin-top:var(--spot-payment-terms-margin-top)}.desktop-layout .spot-table__container{grid-row:1 / span 4;grid-column:2;width:auto;min-width:20.3125rem}.spot-content__wrapper:not(.desktop-layout) .spot-table__container{display:flex;justify-content:flex-start;margin-top:1rem;margin-bottom:1rem;padding-left:.3125rem}.spot-content__wrapper:not(.desktop-layout) .spot-refund__table{width:100%;max-width:22rem;table-layout:auto}@media (max-width: 850px){.spot-selection__recommended-tag{display:inline-block;margin-left:0}}@media (max-width: 500px){.spot-selection__recommended-tag{margin-top:.5rem}}@media (max-width: 600px){.spot-refund__table th{padding:0rem}}.spot-benefits__list{list-style-type:none;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-benefits__list li{margin-bottom:.375rem;display:flex;align-items:flex-start;gap:.5rem}.spot-benefits__list li svg{flex-shrink:0;position:relative;top:.125rem}.spot-bullets__checkmark path{stroke:var(--spot-bullets-checkmark-color)}.spot-qualifying-reasons__container{margin:var(--spot-qualifying-reasons-margin);padding:var(--spot-qualifying-reasons-padding)}.spot-qualifying-reasons__grid{display:grid;grid-template-columns:repeat(2,minmax(0,max-content));column-gap:var(--spot-qualifying-reasons-column-gap);row-gap:var(--spot-qualifying-reasons-row-gap);max-width:100%;padding-left:var(--spot-qualifying-reasons-grid-padding-left)}.spot-qualifying-reasons__item{display:flex;align-items:center;gap:var(--spot-qualifying-reasons-item-gap)}.spot-qualifying-reasons__icon-wrapper{width:var(--spot-qualifying-reasons-icon-wrapper-size);height:var(--spot-qualifying-reasons-icon-wrapper-size);border-radius:50%;border:var(--spot-qualifying-reasons-icon-border-width) solid var(--spot-qualifying-reasons-icon-border-color);background-color:var(--spot-qualifying-reasons-icon-background);display:flex;align-items:center;justify-content:center;flex-shrink:0}.spot-qualifying-reasons__icon{width:var(--spot-qualifying-reasons-icon-size);height:var(--spot-qualifying-reasons-icon-size)}.spot-qualifying-reasons__label{font-size:var(--spot-qualifying-reasons-label-font-size);font-weight:var(--spot-qualifying-reasons-label-font-weight);color:var(--spot-qualifying-reasons-label-font-color);font-family:var(--spot-qualifying-reasons-label-font-family);line-height:1.2}@media (max-width: 480px){.spot-qualifying-reasons__grid{grid-template-columns:1fr}}.spot-covered-items__container{margin-top:.85rem;margin-bottom:.5rem;max-width:26rem}.spot-content__wrapper.desktop-layout:has(.spot-table__container) .spot-covered-items__container{margin-top:0rem;margin-bottom:1rem}.spot-covered-items__title{font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);padding:0 .3125rem .25rem;line-height:125%;margin:0}.spot-covered-items__list{list-style-type:disc;list-style-position:inside;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-covered-items__list li{margin-bottom:.3rem;text-align:left}.spot-covered-items__list li:last-child{margin-bottom:0}.spot-covered-items__header{margin-bottom:.5rem}.spot-covered-items__toggle{background:var(--spot-covered-items-background);border:none;border-radius:var(--spot-covered-items-border-radius);padding:var(--spot-covered-items-padding);cursor:pointer;display:flex;align-items:center;justify-content:space-between;width:100%;font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);line-height:125%;transition:all .2s ease}.spot-covered-items__toggle:hover{background-color:var(--spot-covered-items-hover-background)}.spot-covered-items__toggle:focus{outline:none;box-shadow:0 0 0 2px #0000001a}.spot-covered-items__title{font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);line-height:125%;margin:0;padding:0}.spot-covered-items__right-section{display:flex;align-items:center;gap:.5rem;margin-left:auto}.spot-covered-items__view-all{font-size:var(--spot-covered-items-view-all-font-size);font-weight:var(--spot-covered-items-view-all-font-weight);color:var(--spot-covered-items-view-all-color);font-family:var(--spot-covered-items-font-family);line-height:125%}.spot-covered-items__arrow{font-size:var(--spot-covered-items-arrow-font-size);transition:transform .2s ease;color:var(--spot-covered-items-arrow-color);flex-shrink:0;transform:scaleX(1.5)}.spot-covered-items__content{margin-top:.5rem;transition:all .2s ease;overflow:hidden}.spot-covered-items__list{background-color:var(--spot-covered-items-content-background);border:var(--spot-covered-items-content-border);border-radius:var(--spot-covered-items-content-border-radius);margin:0;padding:var(--spot-covered-items-content-padding)}.spot-table__container{width:100%}.spot-refund__table{max-width:22rem;border-radius:var(--spot-table-border-radius);overflow:hidden;border:.09375rem solid #636569;table-layout:fixed;margin-bottom:.5rem;margin-top:.25rem;padding:.625rem}.spot-refund__table--dynamic{height:auto!important;min-height:7.5rem}.spot-refund__table td,.spot-refund__table th{padding:.375rem .625rem;text-align:left}.spot-refund__table th{text-align:left;font-size:var(--spot-table-header-font-size);font-weight:var(--spot-table-header-font-weight);color:var(--spot-table-header-font-color);font-family:var(--spot-table-header-font-family);padding:var(--spot-table-header-padding)}.spot-refund__table td{text-align:left;font-size:var(--spot-table-cell-font-size);font-weight:var(--spot-table-cell-font-weight);color:var(--spot-table-cell-font-color);font-family:var(--spot-table-cell-font-family);padding:var(--spot-table-cell-padding)}input[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:.75rem;height:.75rem;min-width:.75rem;border:.0625rem solid var(--spot-radio-border);border-radius:var(--spot-radio-border-radius);margin-right:.5rem;position:relative;vertical-align:middle;top:-.0625rem;cursor:pointer;flex-shrink:0}input[type=radio]:checked{background:var(--spot-radio-checked-background);box-shadow:inset 0 0 0 .0625rem #fff}.spot-selection__options{display:flex;flex-direction:column;gap:.5rem}.spot-selection__option{display:flex;align-items:center;flex-wrap:nowrap;position:relative;transition:background .2s;cursor:pointer;font-size:var(--spot-radio-text-font-size);font-weight:var(--spot-radio-text-font-weight);color:var(--spot-radio-text-font-color);font-family:var(--spot-radio-text-font-family);padding:var(--spot-radio-text-padding);margin-right:.5rem}.spot-selection__option.selected{background:var(--spot-radio-selection-background);border-radius:var(--spot-radio-selection-border-radius);padding:var(--spot-radio-selection-padding)}.spot-selection__recommended-tag{background:var(--spot-recommended-tag-background);color:var(--spot-recommended-tag-font-color);font-size:var(--spot-recommended-tag-font-size);font-weight:var(--spot-recommended-tag-font-weight);padding:var(--spot-recommended-tag-padding);border-radius:var(--spot-recommended-tag-border-radius);margin-left:.75rem;white-space:nowrap;flex-shrink:0}@media (max-width: 850px){.spot-selection__recommended-tag{margin-left:.5rem}}@media (max-width: 600px){.spot-selection__recommended-tag{margin-left:.5rem;font-size:.75rem;padding:.1875rem .4375rem}}.spot-selection__error{color:var(--spot-selection-error-font-color);font-size:var(--spot-selection-error-font-size);padding:var(--spot-selection-error-padding);display:none}.spot-payment-terms__wrapper{margin-top:1rem}.spot-payment-terms__header{font-weight:var(--spot-payment-terms-header-font-weight);margin-bottom:.5rem;padding:var(--spot-payment-terms-header-padding);font-size:var(--spot-payment-terms-header-font-size);border-bottom:1px solid var(--spot-payment-terms-header-border-color)}.spot-payment-terms{background-color:var(--spot-payment-terms-background);border-radius:var(--spot-payment-terms-border-radius);padding:var(--spot-payment-terms-padding);margin-right:.5rem;color:var(--spot-payment-terms-font-color);font-size:var(--spot-payment-terms-font-size)}.spot-footer__terms{margin-top:.625rem;margin-right:.25rem;font-size:var(--spot-terms-font-size);font-weight:var(--spot-terms-font-weight);color:var(--spot-terms-font-color);font-family:var(--spot-terms-font-family);padding:var(--spot-terms-padding);line-height:1.4;word-wrap:normal;-webkit-hyphens:none;hyphens:none;flex:1;min-width:0;overflow-wrap:normal}.spot-footer__terms-link{text-decoration:var(--spot-terms-link-text-decoration);font-size:var(--spot-terms-link-font-size);font-weight:var(--spot-terms-link-font-weight);color:var(--spot-terms-link-font-color);font-family:var(--spot-terms-link-font-family);padding:var(--spot-terms-link-padding)}.spot-footer__container{display:flex;flex-direction:row;justify-content:space-between;align-items:flex-start;flex-wrap:nowrap;gap:var(--spot-footer-gap)}@container (max-width: 650px){.spot-footer__container{flex-direction:column!important;align-items:flex-start!important;flex-wrap:wrap!important}.spot-footer__terms{margin-right:0!important;margin-bottom:.5rem!important;flex:none!important;width:100%!important;max-width:none!important}}@media (max-width: 650px){.spot-footer__container{flex-direction:column!important;align-items:flex-start!important;flex-wrap:wrap!important}.spot-footer__terms{margin-right:0!important;margin-bottom:.5rem!important;flex:none!important;width:100%!important;max-width:none!important}}.spot-footer__powered-by{margin-top:0;flex-shrink:0}.spot-logo__top-right{position:absolute;top:-14px;right:40px;z-index:10;background:#fff;padding:0 8px}@container (min-width: 651px){.spot-footer__powered-by{margin-top:0;align-self:center}.spot-footer__terms{margin-right:var(--spot-footer-terms-margin-right)}}@media (min-width: 651px){.spot-footer__powered-by{margin-top:0;align-self:center}.spot-footer__terms{margin-right:var(--spot-footer-terms-margin-right)}}";function Q(m){const t=document.createElement("style");t.textContent=m,document.head.appendChild(t)}Q(S);const D={sandbox:"https://api.sandbox.getspot.com/api/v1/quote",production:"https://api.getspot.com/api/v1/quote",local:"http://localhost:3999/api/v1/quote"};class A{constructor(t={}){this.options={location:"body",showTable:!0,optInSelected:!1,logoPosition:"bottom-right",apiConfig:{environment:"production",partnerId:""},quoteRequestData:{},callbacks:{},useMockData:!1,...t},this._onResize=this._updateLayout.bind(this),this.root=typeof this.options.location=="string"?document.querySelector(this.options.location):this.options.location,this.currentSelection=this.options.optInSelected?"yes":null,this._init()}async _init(){var t,e,s,i,o;try{x(this.options);let n;if(this.options.useMockData&&this.options.mockData)n=this.options.mockData;else{const{environment:r,partnerId:a}=this.options.apiConfig,h=this.options.apiConfig.customEndpoint||D[r];n="cartInfo"in this.options.quoteRequestData&&"items"in this.options.quoteRequestData?await k(h,a,this.options.quoteRequestData):await _(h,a,this.options.quoteRequestData)}if(n.status!=="QUOTE_AVAILABLE"){n.status==="NO_MATCHING_QUOTE"&&((t=this.options.callbacks)!=null&&t.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:this.options.quoteRequestData});return}if(this.quote=n.data,!this.quote)throw new Error("No quote data in response");if(this._renderWidget(),this.options.optInSelected&&((e=this.options.callbacks)!=null&&e.onOptIn)){const r={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const a=this.options.quoteRequestData;r.batchQuoteDetails=this.quote.originalQuotes.map(u=>{var f;const h=(f=a.items)==null?void 0:f.find(y=>(y.cartItemId||`item-${a.items.indexOf(y)+1}`)===u.id);return{quoteId:u.id,productPrice:(h==null?void 0:h.productPrice)||u.spotPrice,cartItemId:u.id}})}this.options.callbacks.onOptIn(r)}if((s=this.options.callbacks)!=null&&s.onQuoteRetrieved){const r=this.options.callbacks.onQuoteRetrieved(this.quote);r&&this._applyQuoteUpdates(r)}}catch(n){if((i=this.options.callbacks)!=null&&i.onError){const r=n;(o=this.options.callbacks)==null||o.onError({message:r.message,status:r.status,responseBody:r.responseBody})}}}_renderWidget(){if(!this.quote)return;this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([s,i])=>{const o=`--${s}`;this.container.style.setProperty(o,i)}),N(this.container,this.quote.communication);const t=document.createElement("div");if(t.className="spot-content__wrapper",this.container.appendChild(t),this.quote.qualifyingReasons?L(t,this.quote.qualifyingReasons):M(t,this.quote.communication.bulletPoints),this.quote.coveredItems){const s=this._getTotalItemsInRequest();O(t,this.quote.coveredItems,s)}this.options.showTable&&!this.quote.qualifyingReasons&&P(t,this.quote.payoutSchedule);const e=$(t,this.options.optInSelected,this.quote.communication);t.appendChild(e),this.paymentTermsEl=p("div",{className:"spot-payment-terms__wrapper",parent:t}),V(this.container,this.quote,this.options.logoPosition),window.addEventListener("resize",this._onResize),this._setupResizeObserver(),this._updateLayout(),this._setupOptionListeners(e)}_updateLayout(){if(!this.container||!this.quote)return;const t=this.container.querySelector(".spot-content__wrapper"),e=this.options.showTable&&!this.quote.qualifyingReasons;if(!t||!e){t==null||t.classList.remove("desktop-layout");return}const s=this._shouldUseDesktopLayout(t);t.classList.toggle("desktop-layout",s)}_shouldUseDesktopLayout(t){const e=this.container.offsetWidth-40,s=325,i=16;if(e>=900)return!0;if(e>=650){const o=t.classList.contains("desktop-layout");t.classList.remove("desktop-layout"),t.offsetHeight;const n=t.querySelector(".spot-benefits__list, .spot-qualifying-reasons__container");if(!n)return o&&t.classList.add("desktop-layout"),o;const a=Math.min(n.scrollWidth,400)+s+i;return o&&t.classList.add("desktop-layout"),e>=a}return!1}_setupResizeObserver(){!this.container||!window.ResizeObserver||(this._resizeObserver=new ResizeObserver(()=>{this._resizeTimeout&&clearTimeout(this._resizeTimeout),this._resizeTimeout=window.setTimeout(()=>{this._updateLayout()},100)}),this._resizeObserver.observe(this.container))}_getTotalItemsInRequest(){return"cartInfo"in this.options.quoteRequestData&&"items"in this.options.quoteRequestData?this.options.quoteRequestData.items.length:1}_applyQuoteUpdates(t){!this.quote||!this.container||(t.spotPriceWithFees!==void 0&&(this.quote.communication.yesOptionText=this.quote.communication.yesOptionText.replace(`$${this.quote.spotPrice.toFixed(2)}`,`$${t.spotPriceWithFees.toFixed(2)}`)),this.destroy(),this._renderWidget())}_setupOptionListeners(t){const e=t.querySelectorAll('input[type="radio"]'),s=t.querySelectorAll(".spot-selection__option");e.forEach(i=>{i.addEventListener("change",o=>{var a,u,h;const n=o.target,r=n.value;if(this.hideSelectionError(),this.currentSelection=r,s.forEach(f=>f.classList.remove("selected")),(a=n.closest(".spot-selection__option"))==null||a.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),r==="yes"&&(this.options.quoteRequestData.isPartialPayment&&R(this.paymentTermsEl,this.quote),(u=this.options.callbacks)!=null&&u.onOptIn)){const f={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const y=this.options.quoteRequestData;f.batchQuoteDetails=this.quote.originalQuotes.map(c=>{var l;const d=(l=y.items)==null?void 0:l.find(b=>(b.cartItemId||`item-${y.items.indexOf(b)+1}`)===c.id);return{quoteId:c.id,productPrice:(d==null?void 0:d.productPrice)||c.spotPrice,cartItemId:c.id}})}this.options.callbacks.onOptIn(f)}if(r==="no"&&((h=this.options.callbacks)!=null&&h.onOptOut)){const f={status:"QUOTE_DECLINED",quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const y=this.options.quoteRequestData;f.batchQuoteDetails=this.quote.originalQuotes.map(c=>{var l;const d=(l=y.items)==null?void 0:l.find(b=>(b.cartItemId||`item-${y.items.indexOf(b)+1}`)===c.id);return{quoteId:c.id,productPrice:(d==null?void 0:d.productPrice)||c.spotPrice,cartItemId:c.id}})}this.options.callbacks.onOptOut(f)}})})}showSelectionError(){var t;if(!this.errorEl){this.errorEl=document.createElement("div"),this.errorEl.className="spot-selection__error",this.errorEl.textContent="Please make a selection";const e=(t=this.container)==null?void 0:t.querySelector(".spot-selection__options");e&&e.insertAdjacentElement("afterend",this.errorEl)}this.errorEl.style.display="block"}hideSelectionError(){this.errorEl&&(this.errorEl.style.display="none")}validateSelection(){if(!this.container)return!1;const t=!!this.container.querySelector('input[name="selection"]:checked');return t?this.hideSelectionError():this.showSelectionError(),t}async updateQuote(t){var e,s,i,o;try{const n={...this.options,quoteRequestData:t};x(n);const{environment:r,partnerId:a,customEndpoint:u}=this.options.apiConfig,h=u||D[r],y="cartInfo"in n.quoteRequestData&&"items"in n.quoteRequestData?await k(h,a,n.quoteRequestData):await _(h,a,n.quoteRequestData);if(y.status!=="QUOTE_AVAILABLE")return y.status==="NO_MATCHING_QUOTE"&&((e=this.options.callbacks)!=null&&e.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:n.quoteRequestData}),!1;if(this.options.quoteRequestData=n.quoteRequestData,this.quote=y.data,this.currentSelection=null,this.destroy(),this._renderWidget(),(s=this.options.callbacks)!=null&&s.onQuoteRetrieved){const c=this.options.callbacks.onQuoteRetrieved(this.quote);c&&this._applyQuoteUpdates(c)}return!0}catch(n){const r=n;return(o=(i=this.options.callbacks)==null?void 0:i.onError)==null||o.call(i,{message:r.message,status:r.status,responseBody:r.responseBody}),!1}}getSelection(){var e,s,i;if(this.currentSelection==null)return null;const t={selection:this.currentSelection,quoteId:(e=this.quote)==null?void 0:e.id,spotPrice:(s=this.quote)==null?void 0:s.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"};if((i=this.quote)!=null&&i.originalQuotes&&this.quote.originalQuotes.length>0){const o=this.options.quoteRequestData;t.batchQuoteDetails=this.quote.originalQuotes.map(n=>{var a;const r=(a=o.items)==null?void 0:a.find(u=>(u.cartItemId||`item-${o.items.indexOf(u)+1}`)===n.id);return{quoteId:n.id,productPrice:(r==null?void 0:r.productPrice)||n.spotPrice,cartItemId:n.id}})}return t}destroy(){window.removeEventListener("resize",this._onResize),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._resizeTimeout&&window.clearTimeout(this._resizeTimeout),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return A});
|
|
35
|
+
</svg>`}return s}const S=":root{--spot-font-family: Arial;--spot-padding: 1.25rem;--spot-background-color: #ffffff;--spot-font-color: #000000;--spot-border-radius: .5rem;--spot-title-font-size: 1.25rem;--spot-title-font-weight: 700;--spot-title-padding: 0 0 1.25rem 0;--spot-description-font-size: .875rem;--spot-description-font-weight: 400;--spot-description-padding: 0 0 .5rem 0;--spot-bullets-font-size: .875rem;--spot-bullets-font-weight: 400;--spot-bullets-padding: .3125rem;--spot-bullets-checkmark-color: #2e2e2e;--spot-table-border-radius: .625rem;--spot-table-header-font-size: .875rem;--spot-table-header-font-weight: 700;--spot-table-header-padding: 0 .5rem .625rem;--spot-table-cell-font-size: .815rem;--spot-table-cell-font-weight: 400;--spot-table-cell-padding: 0 .625rem;--spot-radio-border: #000000;--spot-radio-border-radius: .625rem;--spot-radio-checked-background: #000000;--spot-radio-text-font-size: .875rem;--spot-radio-text-font-weight: 400;--spot-radio-text-padding: .625rem;--spot-radio-selection-background: #f4f4f4;--spot-radio-selection-border-radius: .625rem;--spot-radio-selection-padding: .625rem;--spot-recommended-tag-background: #000000;--spot-recommended-tag-font-color: #ffffff;--spot-recommended-tag-font-size: .875rem;--spot-recommended-tag-font-weight: 700;--spot-recommended-tag-padding: .25rem .5rem;--spot-recommended-tag-border-radius: .5rem;--spot-selection-error-font-color: #ff0000;--spot-selection-error-font-size: .875rem;--spot-qualifying-reasons-margin: .75rem 0;--spot-qualifying-reasons-padding: 0 .3125rem;--spot-qualifying-reasons-column-gap: 3rem;--spot-qualifying-reasons-row-gap: .25rem;--spot-qualifying-reasons-grid-padding-left: 1rem;--spot-qualifying-reasons-icon-wrapper-size: 1.125rem;--spot-qualifying-reasons-icon-size: .75rem;--spot-qualifying-reasons-icon-border-color: #2e2e2e;--spot-qualifying-reasons-icon-border-width: 1px;--spot-qualifying-reasons-icon-background: #ffffff;--spot-qualifying-reasons-item-gap: .625rem;--spot-qualifying-reasons-label-font-size: .8rem;--spot-qualifying-reasons-label-font-weight: 400;--spot-qualifying-reasons-label-font-color: #000000;--spot-qualifying-reasons-label-font-family: Arial;--spot-selection-error-padding: .5rem;--spot-payment-terms-background: #f4f4f4;--spot-payment-terms-border-radius: .625rem;--spot-payment-terms-padding: 1rem;--spot-payment-terms-font-color: #636569;--spot-payment-terms-font-size: .75rem;--spot-payment-terms-header-font-weight: 700;--spot-payment-terms-header-font-size: .875rem;--spot-payment-terms-header-margin-bottom: .5rem;--spot-payment-terms-header-border-color: #c2c2c2;--spot-payment-terms-header-padding: 0 0 .5rem 0;--spot-terms-font-size: .75rem;--spot-terms-font-weight: 400;--spot-terms-font-color: #636569;--spot-terms-padding: 0;--spot-terms-link-text-decoration: underline;--spot-terms-link-font-size: .75rem;--spot-terms-link-font-weight: 400;--spot-terms-link-font-color: #636569;--spot-terms-link-padding: 0;--spot-covered-items-background: #f1f3f5;--spot-covered-items-hover-background: #e9ecef;--spot-covered-items-border-radius: .5rem;--spot-covered-items-padding: .75rem 1rem;--spot-covered-items-font-size: .875rem;--spot-covered-items-font-weight: 400;--spot-covered-items-font-color: #000000;--spot-covered-items-font-family: Arial;--spot-covered-items-arrow-font-size: .6rem;--spot-covered-items-arrow-color: #636569;--spot-covered-items-view-all-color: #636569;--spot-covered-items-view-all-font-size: .875rem;--spot-covered-items-view-all-font-weight: 400;--spot-covered-items-content-background: #f8f9fa;--spot-covered-items-content-border: 1px solid #e0e0e0;--spot-covered-items-content-border-radius: .5rem;--spot-covered-items-content-padding: .75rem 1rem;--spot-desktop-radio-margin-top: -1.5rem;--spot-benefits-margin-bottom: 0rem;--spot-covered-items-margin-bottom: 1.5rem;--spot-footer-gap: 1rem;--spot-footer-terms-margin-right: 7rem;--spot-payment-terms-margin-top: .5rem;--spot-logo-top-right-margin: 1rem}.spot-refund-guarantee{font-family:var(--spot-font-family);padding:var(--spot-padding);background-color:var(--spot-background-color);color:var(--spot-font-color);border:.0625rem solid #e0e0e0;border-radius:var(--spot-border-radius);max-width:51rem;margin:1rem;container-type:inline-size;position:relative;word-wrap:normal;overflow-wrap:normal;-webkit-hyphens:none;hyphens:none}.spot-refund-guarantee *{color:inherit}.spot-header__title{font-size:var(--spot-title-font-size);font-weight:var(--spot-title-font-weight);padding:var(--spot-title-padding);color:var(--spot-title-font-color);font-family:var(--spot-title-font-family);line-height:120%;letter-spacing:-.03125rem}.spot-header__description{font-size:var(--spot-description-font-size);font-weight:var(--spot-description-font-weight);color:var(--spot-description-font-color);font-family:var(--spot-description-font-family);padding:var(--spot-description-padding);line-height:125%;letter-spacing:-.025rem}.spot-content__wrapper{display:flex;flex-direction:column}.spot-content__wrapper.desktop-layout{display:grid;grid-template-columns:1fr auto;align-items:start;gap:1rem}.desktop-layout .spot-benefits__list,.desktop-layout .spot-qualifying-reasons__container,.desktop-layout .spot-covered-items__container,.desktop-layout .spot-selection__options{min-width:0;word-wrap:normal}.desktop-layout .spot-benefits__list,.desktop-layout .spot-qualifying-reasons__container{grid-row:1;margin-bottom:var(--spot-benefits-margin-bottom)}.desktop-layout .spot-covered-items__container{grid-row:2;grid-column:1;margin-bottom:var(--spot-covered-items-margin-bottom)}.desktop-layout .spot-selection__options{grid-row:3;margin-top:var(--spot-desktop-radio-margin-top)}.desktop-layout .spot-payment-terms__wrapper{grid-row:4;grid-column:1;margin-top:var(--spot-payment-terms-margin-top)}.desktop-layout .spot-table__container{grid-row:1 / span 4;grid-column:2;width:auto;min-width:20.3125rem}.spot-content__wrapper:not(.desktop-layout) .spot-table__container{display:flex;justify-content:flex-start;margin-top:1rem;margin-bottom:1rem;padding-left:.3125rem}.spot-content__wrapper:not(.desktop-layout) .spot-refund__table{width:100%;max-width:22rem;table-layout:auto}@media (max-width: 850px){.spot-selection__recommended-tag{display:inline-block;margin-left:0}}@media (max-width: 500px){.spot-selection__recommended-tag{margin-top:.5rem}}@media (max-width: 600px){.spot-refund__table th{padding:0rem}}.spot-benefits__list{list-style-type:none;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-benefits__list li{margin-bottom:.375rem;display:flex;align-items:flex-start;gap:.5rem}.spot-benefits__list li svg{flex-shrink:0;position:relative;top:.125rem}.spot-bullets__checkmark path{stroke:var(--spot-bullets-checkmark-color)}.spot-qualifying-reasons__container{margin:var(--spot-qualifying-reasons-margin);padding:var(--spot-qualifying-reasons-padding)}.spot-qualifying-reasons__grid{display:grid;grid-template-columns:repeat(2,minmax(0,max-content));column-gap:var(--spot-qualifying-reasons-column-gap);row-gap:var(--spot-qualifying-reasons-row-gap);max-width:100%;padding-left:var(--spot-qualifying-reasons-grid-padding-left)}.spot-qualifying-reasons__item{display:flex;align-items:center;gap:var(--spot-qualifying-reasons-item-gap)}.spot-qualifying-reasons__icon-wrapper{width:var(--spot-qualifying-reasons-icon-wrapper-size);height:var(--spot-qualifying-reasons-icon-wrapper-size);border-radius:50%;border:var(--spot-qualifying-reasons-icon-border-width) solid var(--spot-qualifying-reasons-icon-border-color);background-color:var(--spot-qualifying-reasons-icon-background);display:flex;align-items:center;justify-content:center;flex-shrink:0}.spot-qualifying-reasons__icon{width:var(--spot-qualifying-reasons-icon-size);height:var(--spot-qualifying-reasons-icon-size)}.spot-qualifying-reasons__label{font-size:var(--spot-qualifying-reasons-label-font-size);font-weight:var(--spot-qualifying-reasons-label-font-weight);color:var(--spot-qualifying-reasons-label-font-color);font-family:var(--spot-qualifying-reasons-label-font-family);line-height:1.2}@media (max-width: 480px){.spot-qualifying-reasons__grid{grid-template-columns:1fr}}.spot-covered-items__container{margin-top:.85rem;margin-bottom:.5rem;max-width:26rem}.spot-content__wrapper.desktop-layout:has(.spot-table__container) .spot-covered-items__container{margin-top:0rem;margin-bottom:1rem}.spot-covered-items__title{font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);padding:0 .3125rem .25rem;line-height:125%;margin:0}.spot-covered-items__list{list-style-type:disc;list-style-position:inside;line-height:125%;gap:.5625rem;font-size:var(--spot-bullets-font-size);font-weight:var(--spot-bullets-font-weight);color:var(--spot-bullets-font-color);font-family:var(--spot-bullets-font-family);padding:var(--spot-bullets-padding);margin-block-start:0rem;margin-block-end:0rem}.spot-covered-items__list li{margin-bottom:.3rem;text-align:left}.spot-covered-items__list li:last-child{margin-bottom:0}.spot-covered-items__header{margin-bottom:.5rem}.spot-covered-items__toggle{background:var(--spot-covered-items-background);border:none;border-radius:var(--spot-covered-items-border-radius);padding:var(--spot-covered-items-padding);cursor:pointer;display:flex;align-items:center;justify-content:space-between;width:100%;font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);line-height:125%;transition:all .2s ease}.spot-covered-items__toggle:hover{background-color:var(--spot-covered-items-hover-background)}.spot-covered-items__toggle:focus{outline:none;box-shadow:0 0 0 2px #0000001a}.spot-covered-items__title{font-size:var(--spot-covered-items-font-size);font-weight:var(--spot-covered-items-font-weight);color:var(--spot-covered-items-font-color);font-family:var(--spot-covered-items-font-family);line-height:125%;margin:0;padding:0}.spot-covered-items__right-section{display:flex;align-items:center;gap:.5rem;margin-left:auto}.spot-covered-items__view-all{font-size:var(--spot-covered-items-view-all-font-size);font-weight:var(--spot-covered-items-view-all-font-weight);color:var(--spot-covered-items-view-all-color);font-family:var(--spot-covered-items-font-family);line-height:125%}.spot-covered-items__arrow{font-size:var(--spot-covered-items-arrow-font-size);transition:transform .2s ease;color:var(--spot-covered-items-arrow-color);flex-shrink:0;transform:scaleX(1.5)}.spot-covered-items__content{margin-top:.5rem;transition:all .2s ease;overflow:hidden}.spot-covered-items__list{background-color:var(--spot-covered-items-content-background);border:var(--spot-covered-items-content-border);border-radius:var(--spot-covered-items-content-border-radius);margin:0;padding:var(--spot-covered-items-content-padding)}.spot-table__container{width:100%}.spot-refund__table{max-width:22rem;border-radius:var(--spot-table-border-radius);overflow:hidden;border:.09375rem solid #636569;table-layout:fixed;margin-bottom:.5rem;margin-top:.25rem;padding:.625rem}.spot-refund__table--dynamic{height:auto!important;min-height:7.5rem}.spot-refund__table td,.spot-refund__table th{padding:.375rem .625rem;text-align:left}.spot-refund__table th{text-align:left;font-size:var(--spot-table-header-font-size);font-weight:var(--spot-table-header-font-weight);color:var(--spot-table-header-font-color);font-family:var(--spot-table-header-font-family);padding:var(--spot-table-header-padding)}.spot-refund__table td{text-align:left;font-size:var(--spot-table-cell-font-size);font-weight:var(--spot-table-cell-font-weight);color:var(--spot-table-cell-font-color);font-family:var(--spot-table-cell-font-family);padding:var(--spot-table-cell-padding)}input[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:.75rem;height:.75rem;min-width:.75rem;border:.0625rem solid var(--spot-radio-border);border-radius:var(--spot-radio-border-radius);margin-right:.5rem;position:relative;vertical-align:middle;top:-.0625rem;cursor:pointer;flex-shrink:0}input[type=radio]:checked{background:var(--spot-radio-checked-background);box-shadow:inset 0 0 0 .0625rem #fff}.spot-selection__options{display:flex;flex-direction:column;gap:.5rem}.spot-selection__option{display:flex;align-items:center;flex-wrap:nowrap;position:relative;transition:background .2s;cursor:pointer;font-size:var(--spot-radio-text-font-size);font-weight:var(--spot-radio-text-font-weight);color:var(--spot-radio-text-font-color);font-family:var(--spot-radio-text-font-family);padding:var(--spot-radio-text-padding);margin-right:.5rem}.spot-selection__option.selected{background:var(--spot-radio-selection-background);border-radius:var(--spot-radio-selection-border-radius);padding:var(--spot-radio-selection-padding)}.spot-selection__recommended-tag{background:var(--spot-recommended-tag-background);color:var(--spot-recommended-tag-font-color);font-size:var(--spot-recommended-tag-font-size);font-weight:var(--spot-recommended-tag-font-weight);padding:var(--spot-recommended-tag-padding);border-radius:var(--spot-recommended-tag-border-radius);margin-left:.75rem;white-space:nowrap;flex-shrink:0}@media (max-width: 850px){.spot-selection__recommended-tag{margin-left:.5rem}}@media (max-width: 600px){.spot-selection__recommended-tag{margin-left:.5rem;font-size:.75rem;padding:.1875rem .4375rem}}.spot-selection__error{color:var(--spot-selection-error-font-color);font-size:var(--spot-selection-error-font-size);padding:var(--spot-selection-error-padding);display:none}.spot-payment-terms__wrapper{margin-top:1rem}.spot-payment-terms__header{font-weight:var(--spot-payment-terms-header-font-weight);margin-bottom:.5rem;padding:var(--spot-payment-terms-header-padding);font-size:var(--spot-payment-terms-header-font-size);border-bottom:1px solid var(--spot-payment-terms-header-border-color)}.spot-payment-terms{background-color:var(--spot-payment-terms-background);border-radius:var(--spot-payment-terms-border-radius);padding:var(--spot-payment-terms-padding);margin-right:.5rem;color:var(--spot-payment-terms-font-color);font-size:var(--spot-payment-terms-font-size)}.spot-footer__terms{margin-top:.625rem;margin-right:.25rem;font-size:var(--spot-terms-font-size);font-weight:var(--spot-terms-font-weight);color:var(--spot-terms-font-color);font-family:var(--spot-terms-font-family);padding:var(--spot-terms-padding);line-height:1.4;word-wrap:normal;-webkit-hyphens:none;hyphens:none;flex:1;min-width:0;overflow-wrap:normal}.spot-footer__terms-link{text-decoration:var(--spot-terms-link-text-decoration);font-size:var(--spot-terms-link-font-size);font-weight:var(--spot-terms-link-font-weight);color:var(--spot-terms-link-font-color);font-family:var(--spot-terms-link-font-family);padding:var(--spot-terms-link-padding)}.spot-footer__container{display:flex;flex-direction:row;justify-content:space-between;align-items:flex-start;flex-wrap:nowrap;gap:var(--spot-footer-gap)}@container (max-width: 650px){.spot-footer__container{flex-direction:column!important;align-items:flex-start!important;flex-wrap:wrap!important}.spot-footer__terms{margin-right:0!important;margin-bottom:.5rem!important;flex:none!important;width:100%!important;max-width:none!important}}@media (max-width: 650px){.spot-footer__container{flex-direction:column!important;align-items:flex-start!important;flex-wrap:wrap!important}.spot-footer__terms{margin-right:0!important;margin-bottom:.5rem!important;flex:none!important;width:100%!important;max-width:none!important}}.spot-footer__powered-by{margin-top:0;flex-shrink:0}.spot-logo__top-right{position:absolute;top:-14px;right:40px;z-index:10;background:#fff;padding:0 8px}@container (min-width: 651px){.spot-footer__powered-by{margin-top:0;align-self:center}.spot-footer__terms{margin-right:var(--spot-footer-terms-margin-right)}}@media (min-width: 651px){.spot-footer__powered-by{margin-top:0;align-self:center}.spot-footer__terms{margin-right:var(--spot-footer-terms-margin-right)}}";function Q(m){const t=document.createElement("style");t.textContent=m,document.head.appendChild(t)}Q(S);const I={sandbox:"https://api.sandbox.getspot.com/api/v1/quote",production:"https://api.getspot.com/api/v1/quote",local:"http://localhost:3999/api/v1/quote"};class A{constructor(t={}){this.options={location:"body",showTable:!0,optInSelected:!1,logoPosition:"bottom-right",apiConfig:{environment:"production",partnerId:""},quoteRequestData:{},callbacks:{},useMockData:!1,...t},this._onResize=this._updateLayout.bind(this),this.root=typeof this.options.location=="string"?document.querySelector(this.options.location):this.options.location,this.currentSelection=this.options.optInSelected?"yes":null,this._init()}async _init(){var t,r,s,i,e;try{x(this.options);let n;if(this.options.useMockData&&this.options.mockData)n=this.options.mockData;else{const{environment:o,partnerId:a}=this.options.apiConfig,h=this.options.apiConfig.customEndpoint||I[o];n="cartInfo"in this.options.quoteRequestData&&"items"in this.options.quoteRequestData?await k(h,a,this.options.quoteRequestData):await _(h,a,this.options.quoteRequestData)}if(n.status!=="QUOTE_AVAILABLE"){n.status==="NO_MATCHING_QUOTE"&&((t=this.options.callbacks)!=null&&t.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:this.options.quoteRequestData});return}if(this.quote=n.data,!this.quote)throw new Error("No quote data in response");if(this._renderWidget(),this.options.optInSelected&&((r=this.options.callbacks)!=null&&r.onOptIn)){const o={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const a=this.options.quoteRequestData;o.batchQuoteDetails=this.quote.originalQuotes.map(u=>{var f;const h=(f=a.items)==null?void 0:f.find(y=>(y.cartItemId||`item-${a.items.indexOf(y)+1}`)===u.id);return{quoteId:u.id,productPrice:(h==null?void 0:h.productPrice)||u.spotPrice,cartItemId:u.id}})}this.options.callbacks.onOptIn(o)}if((s=this.options.callbacks)!=null&&s.onQuoteRetrieved){const o=this.options.callbacks.onQuoteRetrieved(this.quote);o&&this._applyQuoteUpdates(o)}}catch(n){if((i=this.options.callbacks)!=null&&i.onError){const o=n;(e=this.options.callbacks)==null||e.onError({message:o.message,status:o.status,responseBody:o.responseBody})}}}_renderWidget(){if(!this.quote)return;this.container=document.createElement("div"),this.container.className="spot-refund-guarantee",this.root.appendChild(this.container),Object.entries(this.options.theme||{}).forEach(([s,i])=>{const e=`--${s}`;this.container.style.setProperty(e,i)}),N(this.container,this.quote.communication);const t=document.createElement("div");if(t.className="spot-content__wrapper",this.container.appendChild(t),this.quote.qualifyingReasons?L(t,this.quote.qualifyingReasons):M(t,this.quote.communication.bulletPoints),this.quote.coveredItems){const s=this._getTotalItemsInRequest();O(t,this.quote.coveredItems,s)}this.options.showTable&&!this.quote.qualifyingReasons&&P(t,this.quote.payoutSchedule);const r=$(t,this.options.optInSelected,this.quote.communication);t.appendChild(r),this.paymentTermsEl=p("div",{className:"spot-payment-terms__wrapper",parent:t}),V(this.container,this.quote,this.options.logoPosition),window.addEventListener("resize",this._onResize),this._setupResizeObserver(),this._updateLayout(),this._setupOptionListeners(r)}_updateLayout(){if(!this.container||!this.quote)return;const t=this.container.querySelector(".spot-content__wrapper"),r=this.options.showTable&&!this.quote.qualifyingReasons;if(!t||!r){t==null||t.classList.remove("desktop-layout");return}const s=this._shouldUseDesktopLayout(t);t.classList.toggle("desktop-layout",s)}_shouldUseDesktopLayout(t){const r=this.container.offsetWidth-40,s=325,i=16;if(r>=900)return!0;if(r>=650){const e=t.classList.contains("desktop-layout");t.classList.remove("desktop-layout"),t.offsetHeight;const n=t.querySelector(".spot-benefits__list, .spot-qualifying-reasons__container");if(!n)return e&&t.classList.add("desktop-layout"),e;const a=Math.min(n.scrollWidth,400)+s+i;return e&&t.classList.add("desktop-layout"),r>=a}return!1}_setupResizeObserver(){!this.container||!window.ResizeObserver||(this._resizeObserver=new ResizeObserver(()=>{this._resizeTimeout&&clearTimeout(this._resizeTimeout),this._resizeTimeout=window.setTimeout(()=>{this._updateLayout()},100)}),this._resizeObserver.observe(this.container))}_getTotalItemsInRequest(){return"cartInfo"in this.options.quoteRequestData&&"items"in this.options.quoteRequestData?this.options.quoteRequestData.items.length:1}_applyQuoteUpdates(t){!this.quote||!this.container||(t.spotPriceWithFees!==void 0&&(this.quote.communication.yesOptionText=this.quote.communication.yesOptionText.replace(`$${this.quote.spotPrice.toFixed(2)}`,`$${t.spotPriceWithFees.toFixed(2)}`)),this.destroy(),this._renderWidget())}_setupOptionListeners(t){const r=t.querySelectorAll('input[type="radio"]'),s=t.querySelectorAll(".spot-selection__option");r.forEach(i=>{i.addEventListener("change",e=>{var a,u,h;const n=e.target,o=n.value;if(this.hideSelectionError(),this.currentSelection=o,s.forEach(f=>f.classList.remove("selected")),(a=n.closest(".spot-selection__option"))==null||a.classList.add("selected"),this.paymentTermsEl&&(this.paymentTermsEl.innerHTML=""),o==="yes"&&(this.options.quoteRequestData.isPartialPayment&&R(this.paymentTermsEl,this.quote),(u=this.options.callbacks)!=null&&u.onOptIn)){const f={status:"QUOTE_ACCEPTED",spotPrice:this.quote.spotPrice,quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const y=this.options.quoteRequestData;f.batchQuoteDetails=this.quote.originalQuotes.map(c=>{var l;const d=(l=y.items)==null?void 0:l.find(b=>(b.cartItemId||`item-${y.items.indexOf(b)+1}`)===c.id);return{quoteId:c.id,productPrice:(d==null?void 0:d.productPrice)||c.spotPrice,cartItemId:c.id}})}this.options.callbacks.onOptIn(f)}if(o==="no"&&((h=this.options.callbacks)!=null&&h.onOptOut)){const f={status:"QUOTE_DECLINED",quoteId:this.quote.id};if(this.quote.originalQuotes&&this.quote.originalQuotes.length>0){const y=this.options.quoteRequestData;f.batchQuoteDetails=this.quote.originalQuotes.map(c=>{var l;const d=(l=y.items)==null?void 0:l.find(b=>(b.cartItemId||`item-${y.items.indexOf(b)+1}`)===c.id);return{quoteId:c.id,productPrice:(d==null?void 0:d.productPrice)||c.spotPrice,cartItemId:c.id}})}this.options.callbacks.onOptOut(f)}})})}showSelectionError(){var t;if(!this.errorEl){this.errorEl=document.createElement("div"),this.errorEl.className="spot-selection__error",this.errorEl.textContent="Please make a selection";const r=(t=this.container)==null?void 0:t.querySelector(".spot-selection__options");r&&r.insertAdjacentElement("afterend",this.errorEl)}this.errorEl.style.display="block"}hideSelectionError(){this.errorEl&&(this.errorEl.style.display="none")}validateSelection(){if(!this.container)return!1;const t=!!this.container.querySelector('input[name="selection"]:checked');return t?this.hideSelectionError():this.showSelectionError(),t}async updateQuote(t){var r,s,i,e;try{const n={...this.options,quoteRequestData:t};x(n);const{environment:o,partnerId:a,customEndpoint:u}=this.options.apiConfig,h=u||I[o],y="cartInfo"in n.quoteRequestData&&"items"in n.quoteRequestData?await k(h,a,n.quoteRequestData):await _(h,a,n.quoteRequestData);if(y.status!=="QUOTE_AVAILABLE")return y.status==="NO_MATCHING_QUOTE"&&((r=this.options.callbacks)!=null&&r.noMatchingQuote)&&this.options.callbacks.noMatchingQuote({status:"NO_MATCHING_QUOTE",data:n.quoteRequestData}),!1;if(this.options.quoteRequestData=n.quoteRequestData,this.quote=y.data,this.currentSelection=null,this.destroy(),this._renderWidget(),(s=this.options.callbacks)!=null&&s.onQuoteRetrieved){const c=this.options.callbacks.onQuoteRetrieved(this.quote);c&&this._applyQuoteUpdates(c)}return!0}catch(n){const o=n;return(e=(i=this.options.callbacks)==null?void 0:i.onError)==null||e.call(i,{message:o.message,status:o.status,responseBody:o.responseBody}),!1}}getSelection(){var r,s,i;if(this.currentSelection==null)return null;const t={selection:this.currentSelection,quoteId:(r=this.quote)==null?void 0:r.id,spotPrice:(s=this.quote)==null?void 0:s.spotPrice,status:this.currentSelection==="yes"?"QUOTE_ACCEPTED":"QUOTE_DECLINED"};if((i=this.quote)!=null&&i.originalQuotes&&this.quote.originalQuotes.length>0){const e=this.options.quoteRequestData;t.batchQuoteDetails=this.quote.originalQuotes.map(n=>{var a;const o=(a=e.items)==null?void 0:a.find(u=>(u.cartItemId||`item-${e.items.indexOf(u)+1}`)===n.id);return{quoteId:n.id,productPrice:(o==null?void 0:o.productPrice)||n.spotPrice,cartItemId:n.id}})}return t}destroy(){window.removeEventListener("resize",this._onResize),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=void 0),this._resizeTimeout&&window.clearTimeout(this._resizeTimeout),this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container)}}return A});
|
package/dist/ui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,qBAAqB,EAC1D,GAAG,EAAE,CAAC,EACN,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAE,cAAmB,GACxE,qBAAqB,CAAC,CAAC,CAAC,CAS1B;AAGD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAC,GACjE,IAAI,CAWN;AAGD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,WAAW,EACtB,OAAO,GAAE,MAAM,EAAO,GACrB,IAAI,CAcN;AAGD,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,WAAW,EACtB,iBAAiB,GAAE,gBAAgB,EAAO,GACzC,IAAI,CA0EN;AAGD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,YAAY,GAAE,MAAM,EAAO,EAC3B,mBAAmB,CAAC,EAAE,MAAM,GAC3B,IAAI,
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,qBAAqB,EAC1D,GAAG,EAAE,CAAC,EACN,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,GAAE,cAAmB,GACxE,qBAAqB,CAAC,CAAC,CAAC,CAS1B;AAGD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAC,GACjE,IAAI,CAWN;AAGD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,WAAW,EACtB,OAAO,GAAE,MAAM,EAAO,GACrB,IAAI,CAcN;AAGD,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,WAAW,EACtB,iBAAiB,GAAE,gBAAgB,EAAO,GACzC,IAAI,CA0EN;AAGD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,YAAY,GAAE,MAAM,EAAO,EAC3B,mBAAmB,CAAC,EAAE,MAAM,GAC3B,IAAI,CA+GN;AAGD,wBAAgB,WAAW,CACzB,SAAS,EAAE,WAAW,EACtB,QAAQ,GAAE,kBAAkB,EAAO,GAClC,IAAI,CAyBN;AAGD,wBAAgB,aAAa,CAC3B,SAAS,EAAE,WAAW,EACtB,aAAa,EAAE,OAAO,EACtB,aAAa,EAAE,aAAa,GAC3B,WAAW,CAyCb;AAGD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,KAAK,GACX,WAAW,CAqBb;AAGD,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,KAAK,EACZ,YAAY,GAAE,cAAc,GAAG,WAA4B,GAC1D,WAAW,CAwEb"}
|