const snackBarStyles = ``;
document.querySelector('body').insertAdjacentHTML('beforeend', snackBarStyles);
const snackBarHtml = `
`;
document.querySelector('body').insertAdjacentHTML('beforeend', snackBarHtml);
window.addEventListener('message', toasterEventListener, false);
function toasterEventListener(event) {
if (event?.data && typeof event?.data.indexOf === 'function' && event?.data?.indexOf('appstle_message_for_notification') !== -1) {
var message = event?.data?.split('|')[1];
showAppstleLoyaltyToaster(message);
}
}
let snackBarIndex = 0;
function showAppstleLoyaltyToaster(msg) {
var snackBar = document.getElementById('snackbar');
snackBar.classList.add('show');
snackBar.insertAdjacentHTML('beforeend', `
`);
const el = snackBarIndex;
setTimeout(function() {
if (document.getElementById(`elem${el}`))
document.getElementById(`elem${el}`).remove();
}, 5000);
snackBarIndex++;
}
const closeSnackBar = (el) => document.getElementById(el).remove();
document.addEventListener('DOMContentLoaded', () => {
});
const executeLoyaltyWidget = () => {
const parseHtmlStringContent = (content) => {
if (typeof content !== 'string') return content;
try {
const htmlDecoded = content?.replace(/\\\//g, '/');
return JSON.parse(`"${htmlDecoded}"`);
} catch (error) {
console.error('Error parsing content:', error);
return content;
}
};
const formatNumberByPointRoundType = num => {
if (typeof num !== 'number') return num;
const roundType = _ALConfig?.pointRoundType || "NO_ROUND";
const rounded = roundType === 'ROUND_UP' ? Math.ceil(num) : roundType === 'ROUND_DOWN' ? Math.floor(num) : num;
return (Number.isInteger(rounded) || rounded % 1 === 0) ? rounded.toFixed(0) : rounded.toFixed(2);
};
const loyaltyWidgetStyles = `
`;
document.querySelector('body').insertAdjacentHTML('beforeend', loyaltyWidgetStyles);
const mainHTMLString = `
`;
document.querySelector('body').insertAdjacentHTML('beforeend', mainHTMLString);
window.addEventListener('message', widgetEventListener, false);
function widgetEventListener(event) {
if (event?.data && typeof event?.data.indexOf === 'function' && event?.data?.indexOf('appstle_message_for_showWidget') !== -1) {
} else if (event?.data && typeof event?.data.indexOf === 'function' && event?.data?.indexOf('appstle_widget_showHide') !== -1) {
toggleWidget();
} else if (event?.data && typeof event?.data.indexOf === 'function' && event?.data?.indexOf('refresh_appstle_loyalty_widget') !== -1 && _ALConfig?.widget_setting?.widgetType === 'LAUNCHER') {
loadAppstleLoyaltyWidget();
console.log('REFRESH WIDGET');
} else if (event?.data && typeof event?.data.indexOf === 'function' && event?.data?.indexOf('show_appstle_loyalty_widget') !== -1) {
loadAppstleLoyaltyWidget();
enableWidget();
}
}
function removeAppstleLoyaltyWidget() {
document.querySelector('#appstle-loyalty-button')?.classList?.add('appstle-loyalty-hidden');
document.querySelector('#appstle_loyalty_iframe')?.classList?.add('appstle-loyalty-hidden');
}
(function checkForWidgetRestrictions() {
let isShowWidget = true;
if (_ALConfig?.customerLoyalty?.customerStatus === 'EXCLUDED') {
isShowWidget = false;
}
if (!_ALConfig?.customerId) {
isShowWidget = !(_ALConfig?.widget_setting?.restrictedCustomersTag || _ALConfig?.widget_setting?.allowedCustomersTag);
}
if (_ALConfig?.widget_setting?.allowedCustomersTag?.length && isShowWidget) {
let allowedTags = _ALConfig?.widget_setting?.allowedCustomersTag.split(',');
if (allowedTags?.length > 0 && !_ALConfig?.customerTags?.some((tag) => allowedTags?.some((allowedTag) => allowedTag?.trim()?.toLowerCase() === tag?.trim()?.toLowerCase()))) {
isShowWidget = false;
}
}
if (_ALConfig?.widget_setting?.restrictedCustomersTag?.length && isShowWidget) {
let restrictedTags = _ALConfig?.widget_setting?.restrictedCustomersTag?.split(',');
if (restrictedTags?.length > 0 && _ALConfig?.customerTags?.some((tag) => restrictedTags?.some((restrictedTag) => restrictedTag?.trim()?.toLowerCase() === tag?.trim()?.toLowerCase()))) {
isShowWidget = false;
}
}
if (_ALConfig?.widget_setting?.blockWidgetOnPages?.length && isShowWidget) {
let restrictedPages = _ALConfig?.widget_setting?.blockWidgetOnPages?.split(',');
const currentPage = window?.location?.pathname;
if (restrictedPages?.length > 0) {
if (restrictedPages?.includes('/homepage') && currentPage === '/') {
isShowWidget = false;
} else if (restrictedPages?.some((page) => currentPage?.includes(page))) {
isShowWidget = false;
}
}
}
if (_ALConfig?.widget_setting?.allowWidgetOnSpecificPages?.length && isShowWidget) {
let allowedPages = _ALConfig?.widget_setting?.allowWidgetOnSpecificPages?.split(',');
const currentPage = window?.location?.pathname;
if (allowedPages?.length > 0) {
if (allowedPages?.includes('/homepage') && currentPage === '/') {
isShowWidget = true;
} else if (allowedPages?.some((page) => currentPage?.includes(page))) {
isShowWidget = true;
} else {
isShowWidget = false;
}
}
}
if (!_ALConfig?.customerId && _ALConfig?.widget_setting?.showToLoggedInCustomerOnly) {
isShowWidget = false;
}
window.__APPSTLE_LOYALTY_LAUNCHER_ALLOWED = !!isShowWidget;
if (isShowWidget) {
showAppstleLoyaltyWidget();
} else {
removeAppstleLoyaltyWidget();
}
})();
function enableWidget() {
document.querySelector('#appstle_loyalty_iframe')?.classList?.add('open');
document.querySelector('#appstle_loyalty_iframe')?.classList?.remove('appstle-loyalty-hidden');
setTimeout(function() {
document.querySelector('#appstle_loyalty_iframe')?.classList?.toggle('show-close-icon');
}, 900);
}
function showAppstleLoyaltyWidget() {
const launcherAllowed = window?.['__APPSTLE_LOYALTY_LAUNCHER_ALLOWED'] !== false;
document.querySelector('#appstle_loyalty_iframe')?.classList?.remove('appstle-loyalty-hidden');
const btn = document.querySelector('#appstle-loyalty-button');
if (!btn) return;
if (launcherAllowed) {
btn.classList.remove('appstle-loyalty-hidden');
} else {
btn.classList.add('appstle-loyalty-hidden');
}
}
document.querySelector('.appstle-loyalty-button').addEventListener('click', toggleWidget);
if (_ALConfig?.widget_setting?.widgetPosition === 'LEFT') {
document.getElementById('appstle_loyalty_iframe')?.classList?.add('appstle-loyalty-left');
document.querySelector('.appstle-loyalty-button')?.classList?.add('appstle-loyalty-left');
document.getElementById('appstle_loyalty_iframe')?.classList?.add('appstle-loyalty-left');
document.getElementById('snackbar')?.classList?.add('left_snackbar');
} else {
document.getElementById('appstle_loyalty_iframe')?.classList?.add('appstle-loyalty-right');
document.querySelector('.appstle-loyalty-button')?.classList?.add('appstle-loyalty-right');
document.getElementById('snackbar')?.classList?.add('right_snackbar');
}
const alIframeSrc = `