// UI Controls Module // Handles UI toggle functions, keyboard shortcuts, notifications, and DOM utilities (function() { 'use strict'; AppModules.require('api', 'screen-reader'); AppModules.register('ui-controls'); // Toast notification system function showToast(message, duration = AppConfig.ui.toastDuration) { const toast = document.getElementById('toast'); if (!toast) return; toast.textContent = message; toast.classList.add('show'); if (duration > 0) { setTimeout(() => { toast.classList.remove('show'); }, duration); } } function hideToast() { const toast = document.getElementById('toast'); if (toast) { toast.classList.remove('show'); } } // Notification badge management function updateNotificationBadge() { const badge = document.getElementById('notificationBadge'); if (badge) { if (AppState.unreadCount > 0) { badge.textContent = AppState.unreadCount > 99 ? '99+' : AppState.unreadCount; badge.classList.add('show'); } else { badge.classList.remove('show'); } } } // Dashboard toggle functionality function toggleDashboard() { const theater = document.querySelector('.theater'); const dashboardToggleBtn = document.querySelector('.video-player__toggle-dashboard-btn'); if (!theater || !dashboardToggleBtn) return; const isEnabled = theater.classList.contains('dashboard-enabled'); if (isEnabled) { theater.classList.remove('dashboard-enabled'); dashboardToggleBtn.setAttribute('aria-expanded', 'false'); AppState.dashboardEnabled = false; } else { theater.classList.add('dashboard-enabled'); dashboardToggleBtn.setAttribute('aria-expanded', 'true'); AppState.dashboardEnabled = true; // Initialize dashboard data when first enabled updateDashboardStats(); updateActiveUsers(); } // Store preference in localStorage try { localStorage.setItem('dashboard-enabled', AppState.dashboardEnabled ? 'true' : 'false'); } catch (e) { AppLogger.log('Audio notification failed:', e); } } // Dashboard stats management function updateDashboardStats() { // Update viewer count in dashboard const dashboardViewerCount = document.getElementById('statsViewersCount'); if (dashboardViewerCount) { const viewers = AppState.viewers || 0; dashboardViewerCount.textContent = viewers.toLocaleString(); } // Update stream quality const streamQuality = document.getElementById('statsStreamQuality'); if (streamQuality) { // Get from URL or assume HD for now streamQuality.textContent = 'HD'; } // Update uptime const uptime = document.getElementById('statsUptime'); if (uptime) { const streamStartTime = AppState.streamStartTime || Date.now() - 60000; // Default to 1 minute const elapsed = Date.now() - streamStartTime; const minutes = Math.floor(elapsed / 60000); const seconds = Math.floor((elapsed % 60000) / 1000); uptime.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; } } // Active users widget update function updateActiveUsers() { const activeUsersContainer = document.getElementById('activeUsers'); if (!activeUsersContainer) return; // This would typically poll for active users from server if (window.ChatSystem && typeof window.ChatSystem.getActiveViewers === 'function') { window.ChatSystem.getActiveViewers().then(users => { displayActiveUsers(users); }).catch(err => { AppLogger.error('Failed to get active users:', err); }); } else { // Fallback: show placeholder displayActiveUsers([]); } } function displayActiveUsers(users) { const activeUsersContainer = document.getElementById('activeUsers'); if (!activeUsersContainer) return; let html = ''; if (users.length === 0) { html = `