// Main application script document.addEventListener('DOMContentLoaded', function() { initializeDashboard(); setupEventListeners(); }); // Initialize dashboard with mock data function initializeDashboard() { // Mock data for demonstration const mockStats = { activeUsers: 245, webhookEvents: 1567, monthlyRevenue: '$12,450' }; const mockActivity = [ { type: 'purchase', user: 'john@example.com', plan: 'Premium Plan', time: '2 hours ago', status: 'success' }, { type: 'cancellation', user: 'jane@example.com', plan: 'Basic Plan', time: '5 hours ago', status: 'warning' }, { type: 'webhook', user: 'system', plan: 'N/A', time: '1 day ago', status: 'info' }, { type: 'upgrade', user: 'mike@example.com', plan: 'Enterprise Plan', time: '2 days ago', status: 'success' } ]; // Update dashboard stats updateDashboardStats(mockStats); updateRecentActivity(mockActivity); } // Update dashboard statistics function updateDashboardStats(stats) { const activeUsersElement = document.getElementById('activeUsersCount'); const webhookEventsElement = document.getElementById('webhookEventsCount'); const monthlyRevenueElement = document.getElementById('monthlyRevenue'); if (activeUsersElement) activeUsersElement.textContent = stats.activeUsers; if (webhookEventsElement) textContent = stats.webhookEvents; if (monthlyRevenueElement) textContent = stats.monthlyRevenue; } // Update recent activity feed function updateRecentActivity(activities) { const activityContainer = document.getElementById('recentActivity'); if (!activityContainer) return; activityContainer.innerHTML = activities.map(activity => `

${activity.user} - ${activity.type}

${activity.plan}

${activity.time}

${activity.status}
`).join(''); } // Setup event listeners function setupEventListeners() { // Add any global event listeners here console.log('Event listeners initialized'); } // Utility function to format dates function formatDate(date) { return new Date(date).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }); } // API integration functions (for future use) async function fetchDashboardData() { try { // This would be replaced with actual API calls const response = await fetch('/api/dashboard'); if (!response.ok) throw new Error('Failed to fetch dashboard data'); return await response.json(); } catch (error) { console.error('Error fetching dashboard data:', error); return null; } } // Export functions for use in other modules window.HotmartFlow = { initializeDashboard, updateDashboardStats, updateRecentActivity, fetchDashboardData };