const RecordingUI = (function() { 'use strict'; let recordings = []; let active = []; function init() { refresh(); } function refresh() { fetch('/recordings') .then(r => r.json()) .then(data => { if (data.status !== 'success') return; recordings = data.recordings || []; active = data.active || []; renderActive(); renderRecordings(); }) .catch(err => console.error('[Recording] Load failed', err)); } function start() { const modeSelect = document.getElementById('recordingModeSelect'); const labelInput = document.getElementById('recordingLabelInput'); const mode = modeSelect ? modeSelect.value : ''; const label = labelInput ? labelInput.value : ''; if (!mode) return; fetch('/recordings/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mode, label }) }) .then(r => r.json()) .then(() => { refresh(); }) .catch(err => console.error('[Recording] Start failed', err)); } function stop() { const modeSelect = document.getElementById('recordingModeSelect'); const mode = modeSelect ? modeSelect.value : ''; if (!mode) return; fetch('/recordings/stop', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mode }) }) .then(r => r.json()) .then(() => refresh()) .catch(err => console.error('[Recording] Stop failed', err)); } function stopById(sessionId) { fetch('/recordings/stop', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: sessionId }) }).then(() => refresh()); } function renderActive() { const container = document.getElementById('recordingActiveList'); if (!container) return; if (!active.length) { container.innerHTML = '