import apiClient from './apiClient.js'; class DebugConsoleView { constructor(section, wsClient) { this.section = section; this.wsClient = wsClient; this.healthStatus = section.querySelector('[data-health-status]'); this.providersContainer = section.querySelector('[data-providers]'); this.requestLogBody = section.querySelector('[data-request-log]'); this.errorLogBody = section.querySelector('[data-error-log]'); this.wsLogBody = section.querySelector('[data-ws-log]'); this.refreshButton = section.querySelector('[data-refresh-health]'); } init() { this.refresh(); if (this.refreshButton) { this.refreshButton.addEventListener('click', () => this.refresh()); } apiClient.onLog(() => this.renderRequestLogs()); apiClient.onError(() => this.renderErrorLogs()); this.wsClient.onStatusChange(() => this.renderWsLogs()); this.wsClient.onMessage(() => this.renderWsLogs()); } async refresh() { const [health, providers] = await Promise.all([apiClient.getHealth(), apiClient.getProviders()]); if (health.ok) { this.healthStatus.textContent = health.data?.status || 'OK'; } else { this.healthStatus.textContent = 'Unavailable'; } if (providers.ok) { const list = providers.data || []; this.providersContainer.innerHTML = list .map( (provider) => `
Status: ${ provider.status || 'unknown' }
Latency: ${provider.latency || '—'}ms