(() => {
"use strict";
const t = "undefined" != typeof window && "undefined" != typeof document,
e = { cartGroups: ["ex-cart"], gridTiles: ["*"], alternatives: ["*"] },
s = (t) => "*" === t || Boolean(document.body?.classList.contains(t)),
a = t && ["ex-a-2127645"].some(s),
i = (t) => a && e[t].some(s),
n = i("cartGroups"),
r = i("gridTiles"),
o = i("alternatives") || r;
if (t && ((!n && !r && !o) || window.__cswLoaded)) return;
t && document.body.classList.add("csw-on");
const c = (...t) => console.warn("[csw]", ...t),
l = (t) => String(t ?? "").replace(/[&<>"']/g, (t) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[t]),
d = (t) => new Promise((e) => setTimeout(e, t)),
u = {
1: "Next Day Delivery",
2: "1-2 Day Delivery",
3: "3-5 Day Delivery",
4: "4 Day Delivery",
5: "5-8 Day Delivery",
6: "6-8 Day Delivery",
7: "7-10 Day Delivery",
8: "8-10 Day Delivery",
10: "10-14 Day Delivery",
14: "14-18 Day Delivery",
15: "15-20 Day Delivery",
21: "21-28 Day Delivery",
28: "28-36 Day Delivery",
49: "42-49 Day Delivery",
63: "63 Day Delivery",
99: "Made to Order",
901: "Next Day Delivery",
902: "1-2 Day Delivery",
904: "4-6 Day Delivery",
905: "5-7 Working Days Delivery",
907: "7-10 Working Days Delivery",
915: "15-20 Working Days Delivery",
},
p = (t) => (99 === t ? 1 / 0 : t > 900 ? t - 900 : t),
h = (t) => (t <= 2 ? "fast" : t <= 10 ? "medium" : "slow"),
m = (t) => h(p(t)),
w = (t) => u[t]?.replace(/ Delivery$/, "").replace(/(\d) Day$/, "$1 Days");
function f(t) {
const e = Number(t.quantity) || 0,
s = String(t.location_name || "").replace(/\s*Stock$/i, "");
return `${l(s)} ${e}`;
}
function y(t) {
const e = (t || []).filter((t) => /local|group/i.test(String(t.location_name || "")));
return e.length > 0 && e.every((t) => (Number(t.quantity) || 0) <= 0);
}
const g = (t) => t.map(([t, e]) => encodeURIComponent(t) + "=" + encodeURIComponent(e ?? "")).join("&");
async function v(t, e, s) {
const a = await fetch(t, {
method: "POST",
signal: s ? AbortSignal.timeout(s) : void 0,
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"X-CSRF-TOKEN": document.querySelector('meta[name="csrf-token"]')?.content || "",
},
body: g(e),
});
if (!a.ok) throw Object.assign(new Error(`${t}: HTTP ${a.status}`), { status: a.status });
return { data: await a.json().catch(() => {}), redirected: a.redirected };
}
const b = new Map();
function k(t) {
if (((t = String(t)), !b.has(t))) {
const e = v(`/api/products/${t}`, [["compare", "1"]], 15e3).then(
({ data: e }) => {
if (!e?.product) throw Object.assign(new Error(`/api/products/${t}: status ${e?.status}`), { final: !0 });
return { product: e.product, available: "success" === e.status };
},
(t) => {
throw (t.status >= 400 && t.status < 500 && 408 !== t.status && 429 !== t.status && (t.final = !0), t);
},
);
(e.catch(() => b.delete(t)), b.set(t, e));
}
return b.get(t);
}
async function _(t) {
const e = t.map((t) => ["products[]", t.sku]);
t.forEach((t, s) =>
e.push(
[`productData[${s}][item_id]`, t.itemId],
[`productData[${s}][sku]`, t.sku],
[`productData[${s}][uom]`, t.uom],
[`productData[${s}][template_item]`, t.template ?? ""],
[`productData[${s}][inventory_v2]`, t.inventoryV2 ?? ""],
),
);
const { data: s } = await v(`/ajax/live-inventory?_=${Date.now()}`, e, 15e3);
if ("success" !== s?.status || !Array.isArray(s.data)) throw new Error(`live-inventory: status ${s?.status}`);
return s.data;
}
async function S(t, e = 15e3) {
const s = `table.items-list tr.item_${t}`,
a = document.querySelector(`${s} .delete-btn`);
if (!a) return !document.querySelector(s);
a.click();
const i = Date.now();
for (; document.querySelector(s); ) {
if (Date.now() - i > e) return !1;
await d(100);
}
return !0;
}
async function $(t, e, s) {
const { data: a, redirected: i } = await v("/cart/addcart", [
["product", JSON.stringify(t)],
["qty", e],
]);
if (i || !a || "object" != typeof a) throw new Error("addcart: not added (redirected or not JSON)");
if ("status" in a && !/^(200|success|ok|true)$/i.test(String(a.status))) throw new Error("addcart: " + (a.message || a.status));
let n = !1;
if ("function" == typeof window.updateminicart)
try {
window.updateminicart(a, !1, "add-item");
} catch (t) {
c("updateminicart", t);
}
const r = document.querySelector(".shopping-cart")?.__vue__;
if (r && Array.isArray(a.minicart_items))
try {
const t = new Set((r.items || []).map((t) => t.session_cart_id));
(r.updateItemsInTheCart({
...a,
minicart_items: a.minicart_items.map(({ item_obj: e, created_at: s, updated_at: a, ...i }) =>
t.has(i.session_cart_id)
? i
: r.transformCartItems([
{
...i,
created_at: s,
quote_id: i.session_id,
item_shipping_type: i.item_shipping_type ?? 3,
product_labels: i.product_labels ?? "",
},
])[0],
),
}),
a.minicart_totals && (r.totals = { ...r.totals, ...a.minicart_totals }),
await new Promise((t) => r.$nextTick(t)));
} catch (t) {
(c("cart table update", t), (n = "cart" === s));
}
else n = "cart" === s;
return (document.dispatchEvent(new CustomEvent("cart-total-update")), { data: a, reload: n });
}
const M = Object.assign(
{
api: "https://api.heymojo.dev/alternatives/v1/eu/stores/1655/products/",
track: !0,
searchTimeoutMs: 3e4,
searchConcurrency: 3,
pollDelaysMs: [5e3, 1e4, 15e3],
runCapMs: 6e4,
removeTimeoutMs: 15e3,
maxCandidates: 40,
showMax: 4,
showAllMax: 20,
closeMaxRatio: 3,
packRatioLimit: 20,
},
(t && window.cswAlternativesConfig) || {},
),
A = {
title: "Alternatives for",
inStock: "in stock",
queued: "Waiting for the previous search to finish",
step1: "Preparing your search",
step2: "Searching the store",
step3: "Checking suitability",
checking: "Still checking… more may appear",
empty: "No in-stock alternatives right now.",
stillChecking: "Still checking alternatives for this item. Try again in a minute.",
added: "Added",
add: "Add to basket",
addAlso: "Add {sku} to basket as well",
swap: "Swap",
swapping: "Swapping…",
swapTitle: "Replace {orig} in your basket with this",
swapPartial: "Added. We couldn't remove {orig} — please remove it from your basket.",
adding: "Adding…",
failed: "Try again",
cannotAdd: "Not available to add",
showAll: "Show all {n}",
showFewer: "Show fewer",
showMore: "Show more",
loadingMore: "Searching…",
srSearching: "Searching the store",
srResults: "alternatives in stock",
browse: "Or browse similar products in",
browseMore: "Not quite right? Browse",
browseCta: "Browse {name}",
},
q = (t) => Number(String(t ?? "").replace(/[^\d.]/g, "")),
x = (t) => {
const e = String(t ?? "").trim();
return /^[1-9]\d{0,11}$/.test(e) ? e : "";
},
T = (t) => ([t.productId, t.catalogId, t.supplierId, t.price].every((t) => Number.isFinite(t) && t > 0) && t.sku && t.title ? t : null);
function E(t) {
try {
return (JSON.parse(document.getElementById("cartdata")?.value || "{}").store_cart || []).find((e) => Number(e.item_id) === t) || null;
} catch {
return null;
}
}
function L(t) {
const e = t?.href || t?.url,
s = String(t?.textContent || t?.title || t?.name || "").trim();
return e && s && /^(https?:\/\/|\/)/.test(e) ? { name: s, url: e } : null;
}
async function C(t, e) {
const s = await fetch(M.api + t, { signal: AbortSignal.timeout(e) });
if (200 !== s.status) throw Object.assign(new Error("HTTP " + s.status), { status: s.status });
return s.json();
}
function N(t, e) {
let s = 0,
a = "",
i = !1;
for (let n = e; n < t.length; n++) {
const r = t[n];
if (a) i ? (i = !1) : "\\" === r ? (i = !0) : r === a && (a = "");
else if ('"' === r || "'" === r) a = r;
else if ("[" === r || "{" === r) s++;
else if (("]" === r || "}" === r) && 0 === --s) return t.slice(e, n + 1);
}
return null;
}
function D(t) {
const e = t.indexOf("$evodata.products.list = ");
if (e < 0) return [];
const s = e + 25,
a = t.slice(s, s + 6).search(/[[{]/),
i = a < 0 ? null : N(t, s + a);
if (!i) return [];
let n;
try {
n = JSON.parse(i);
} catch {
return [];
}
return (Array.isArray(n) ? n : n && "object" == typeof n ? (n.sku ? [n] : Object.values(n)) : []).filter(
(t) => t && "object" == typeof t && t.sku,
);
}
function I(t, e) {
const s = t[e];
let a, i;
if ('"' === s || "'" === s) {
let n = e + 1;
for (; n < t.length && t[n] !== s; ) n += "\\" === t[n] ? 2 : 1;
((a = t.slice(e, n + 1)), (i = n + 1));
} else if ("[" === s || "{" === s) ((a = N(t, e)), (i = a ? e + a.length : t.length));
else {
const s = t.indexOf(";", e);
((a = s < 0 ? null : t.slice(e, s).trim()), (i = s < 0 ? t.length : s));
}
if (!a || "undefined" === a) return [void 0, i];
const n = a.match(/^'([^'\\]*)'$/);
if (n) return [n[1], i];
try {
return [JSON.parse(a), i];
} catch {
return [void 0, i];
}
}
function P(t) {
const e = new Map(),
s = (e) => [...t.matchAll(e)].map((t) => t.index),
a = [...t.matchAll(/\$t_item\.item_sku\s*=\s*"([^"]+)"\s*;/g)],
i = [...s(/\$t_item\s*=\s*\{/g), ...a.map((t) => t.index)],
n = [...i, ...s(/