/** * VenueFlow — Simulator Control UI */ let simRefreshInterval = null; document.addEventListener('DOMContentLoaded', () => { simRefreshInterval = setInterval(refreshSimStatus, 3000); }); async function refreshSimStatus() { try { const status = await apiCall('/api/simulator/status'); updateEl('sim-tick', status.tick_count || 0); updateEl('sim-speed', (status.speed || 1) + 'x'); updateEl('sim-occ', (status.venue_occupancy || 0) + '%'); const badge = document.getElementById('sim-status-badge'); if (badge) { badge.textContent = status.running ? '🟢 Running' : '⏸️ Stopped'; badge.className = status.running ? 'badge badge-low' : 'badge badge-info'; } } catch (e) {} } async function startSim() { try { await apiCall('/api/simulator/start', { method: 'POST' }); showToast('Simulation Started', 'Real-time data generation is active', 'success'); refreshSimStatus(); } catch (err) { showToast('Error', err.message, 'error'); } } async function stopSim() { try { await apiCall('/api/simulator/stop', { method: 'POST' }); showToast('Simulation Stopped', 'Data generation paused', 'info'); refreshSimStatus(); } catch (err) { showToast('Error', err.message, 'error'); } } async function setPhase(phase) { try { await apiCall('/api/simulator/phase', { method: 'POST', body: JSON.stringify({ phase }), }); showToast('Phase Changed', `Event phase set to: ${phase.replace('_', ' ')}`, 'success'); refreshSimStatus(); } catch (err) { showToast('Error', err.message, 'error'); } } async function setSpeed(speed) { try { const label = document.getElementById('speed-label'); if (label) label.textContent = speed + 'x'; await apiCall('/api/simulator/speed', { method: 'POST', body: JSON.stringify({ speed: parseFloat(speed) }), }); } catch (err) { showToast('Error', err.message, 'error'); } } function updateEl(id, value) { const el = document.getElementById(id); if (el) el.textContent = value; } console.log('🎮 Simulator UI loaded');