34 lines
1.8 KiB
Plaintext
34 lines
1.8 KiB
Plaintext
|
|
function updateLoyaltyUI() {
|
|
if (!loyaltySection || typeof LOYALTY_SETTINGS === 'undefined' || !LOYALTY_SETTINGS.is_enabled) return;
|
|
|
|
if (currentCustomer) {
|
|
loyaltySection.classList.remove('d-none');
|
|
if (loyaltyPointsDisplay) loyaltyPointsDisplay.textContent = currentCustomer.points + ' pts';
|
|
|
|
if (redeemLoyaltyBtn) {
|
|
const hasLoyaltyItem = cart.some(item => item.is_loyalty);
|
|
const hasNonLoyaltyItem = cart.some(item => !item.is_loyalty);
|
|
|
|
redeemLoyaltyBtn.disabled = !currentCustomer.eligible_for_free_meal || !hasLoyaltyItem || hasNonLoyaltyItem;
|
|
|
|
if (loyaltyMessage) {
|
|
if (currentCustomer.eligible_for_free_meal) {
|
|
const count = currentCustomer.eligible_count || 1;
|
|
loyaltyMessage.innerHTML = `<span class="text-success fw-bold">Eligible for ${count} Free Product${count > 1 ? 's' : ''}!</span>`;
|
|
|
|
if (hasNonLoyaltyItem) {
|
|
loyaltyMessage.innerHTML += '<div class="text-danger small" style="font-size: 0.7rem;">(Remove non-loyalty products to redeem)</div>';
|
|
} else if (!hasLoyaltyItem) {
|
|
loyaltyMessage.innerHTML += '<div class="text-warning small" style="font-size: 0.7rem;">(Add a loyalty product to redeem)</div>';
|
|
}
|
|
} else {
|
|
loyaltyMessage.textContent = `${currentCustomer.points_needed || 0} pts away from a free product.`;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
loyaltySection.classList.add('d-none');
|
|
}
|
|
}
|