UNPKG

@salla.sa/twilight-components

Version:
75 lines (71 loc) 2.2 kB
/*! * Crafted with ❤ by Salla */ 'use strict'; var index = require('./index-uoA36zqH.js'); function nearestLowerMultiple(number, multipleOf = window.matchMedia('(min-width: 768px)').matches ? 3 : 2) { return number < multipleOf ? number : number - (number % multipleOf); } function closeModals(cb = null) { for (const element of document.querySelectorAll('salla-modal')) { element.close(); } cb && requestAnimationFrame(cb); } function normalizeLoyaltyData(data) { const groups = (data.prizes || []).map((group) => { return { ...group, items: (group.items || []).map((item) => ({ ...item, group_title: group.title, group_type: group.type })), }; }); const all = { type: 'all', title: salla.lang.get('pages.loyalty_program.all'), items: groups.reduce((acc, group) => acc.concat(group.items), []), }; groups.unshift(all); return { ...data, prizes: groups, prizes_count: all.items.length, points: data.points ?? [], }; } function brand_path(brand) { return [brand.name.replace(/\s/g, '-'), `brand-${brand.id}`].join('/'); } function isUnitOrder(point) { for (const condition of (point.conditions ?? [])) { if (condition.key?.endsWith('_FOR_UNIT')) { return true; } } return false; } function formattedPointsJsx(value) { if (typeof value === 'number') { return index.h("span", null, value, " ", salla.lang.get('pages.loyalty_program.point')); } if (isUnitOrder(value)) { return index.h("span", null, "1 ", salla.config.currency().symbol, " = ", value.points, " ", salla.lang.get('pages.loyalty_program.point')); } return index.h("span", null, value.points, " ", salla.lang.get('pages.loyalty_program.point')); } exports.brand_path = brand_path; exports.closeModals = closeModals; exports.formattedPointsJsx = formattedPointsJsx; exports.nearestLowerMultiple = nearestLowerMultiple; exports.normalizeLoyaltyData = normalizeLoyaltyData;