// main.js document.addEventListener('DOMContentLoaded', function () { const presetContainer = document.getElementById('preset-container'); const stopButton = document.querySelector('.stop-button'); const currentStationName = document.getElementById('current-station-name'); let currentSound = null; // --- INITIALISIERUNG --- window.UI.initializeFooter(); // Wichtig: Hier wird die Stop-Funktion an den Timer übergeben if (window.SleepTimer) { window.SleepTimer.init(() => stopPlayback()); } window.PresetManager.load((presets) => { displayPresets(presets); initSortable(); }); // --- EVENT LISTENER (HAUPTSEITE) --- if (stopButton) stopButton.onclick = stopPlayback; document.getElementById('edit-presets-button').onclick = () => { window.UI.openModal('preset-modal'); window.PresetUI.renderTable(); }; document.getElementById('open-sleep-timer-modal').onclick = () => { window.UI.openModal('sleep-timer-modal'); if (window.SleepTimer) window.SleepTimer.updateButtonUI(); }; // --- SLEEPTIMER LOGIK IM MODAL --- document.querySelectorAll('.time-option').forEach(button => { button.onclick = () => { const ms = parseInt(button.getAttribute('data-time')); const minutes = ms / 60000; if (window.SleepTimer) { window.SleepTimer.setTimer(minutes); window.UI.closeModal('sleep-timer-modal'); } }; }); document.getElementById('off-sleep-timer-modal').onclick = () => { if (window.SleepTimer) { window.SleepTimer.clear(); window.UI.closeModal('sleep-timer-modal'); } }; document.getElementById('close-sleep-timer-modal').onclick = () => { window.UI.closeModal('sleep-timer-modal'); }; // --- PLAYER FUNKTIONEN --- function playStream(url, name) { stopPlayback(); currentSound = new Howl({ src: [url], html5: true, volume: 0.5, onplay: () => { stopButton.classList.remove('hidden'); window.UI.updateDocumentTitle(name); const iconHtml = ' '; currentStationName.innerHTML = iconHtml + name; if (window.MetaHandler) window.MetaHandler.start(url); } }); currentSound.play(); } function stopPlayback() { if (currentSound) { currentSound.stop(); currentSound = null; } stopButton.classList.add('hidden'); currentStationName.innerHTML = 'Wähle einen Sender aus'; window.UI.updateDocumentTitle(''); if (window.MetaHandler) window.MetaHandler.stop(); } // --- UI RENDERING --- function displayPresets(presets) { presetContainer.innerHTML = ''; if (!presets || presets.length === 0) { presetContainer.innerHTML = '
Keine Sender vorhanden.