// app/modules/loyalty/static/storefront/js/loyalty-dashboard.js // Customer loyalty dashboard function customerLoyaltyDashboard() { return { ...storefrontLayoutData(), // Data card: null, program: null, rewards: [], transactions: [], locations: [], // Wallet walletUrls: { google_wallet_url: null, apple_wallet_url: null }, // UI state loading: false, showBarcode: false, async init() { console.log('Customer loyalty dashboard initializing...'); await this.loadData(); }, async loadData() { this.loading = true; try { await Promise.all([ this.loadCard(), this.loadTransactions() ]); } catch (error) { console.error('Failed to load loyalty data:', error); } finally { this.loading = false; } }, async loadCard() { try { const response = await apiClient.get('/storefront/loyalty/card'); if (response) { this.card = response.card; this.program = response.program; this.rewards = response.program?.points_rewards || []; this.locations = response.locations || []; this.walletUrls = response.wallet_urls || { google_wallet_url: null, apple_wallet_url: null }; console.log('Loyalty card loaded:', this.card?.card_number); } } catch (error) { if (error.status === 404) { console.log('No loyalty card found'); this.card = null; } else { throw error; } } }, async loadTransactions() { try { const response = await apiClient.get('/storefront/loyalty/transactions?limit=10'); if (response && response.transactions) { this.transactions = response.transactions; } } catch (error) { console.warn('Failed to load transactions:', error.message); } }, formatNumber(num) { if (num == null) return '0'; return new Intl.NumberFormat('en-US').format(num); }, formatDate(dateString) { if (!dateString) return '-'; try { return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }); } catch (e) { return dateString; } } }; }