// podcastUI.js — Podcast feed manager + episode rendering. import { API } from './api.js'; import { escapeHtml, fmtDur, toast } from './utils.js'; export function initPodcasts() { const modal = document.getElementById('podcast-modal'); const closeBtn = document.getElementById('podcast-close'); const form = document.getElementById('podcast-form'); const urlInput = document.getElementById('podcast-url'); const nameInput = document.getElementById('podcast-name'); const listEl = document.getElementById('podcast-list'); const adminBtn = document.getElementById('admin-podcasts'); if (!modal) return; adminBtn?.addEventListener('click', () => { modal.classList.add('open'); refreshPodcasts(); }); closeBtn?.addEventListener('click', () => modal.classList.remove('open')); modal?.addEventListener('click', (e) => { if (e.target === modal) modal.classList.remove('open'); }); form?.addEventListener('submit', async (e) => { e.preventDefault(); const url = urlInput.value.trim(); const name = nameInput.value.trim(); if (!url) return; try { await API.subscribePodcast(url, name); toast('Subscribed to podcast'); urlInput.value = ''; nameInput.value = ''; refreshPodcasts(); } catch (err) { toast(err.message || 'Subscribe failed', 'error'); } }); async function refreshPodcasts() { if (!listEl) return; try { const podcasts = await API.podcasts(); if (!podcasts || !podcasts.length) { listEl.innerHTML = '
No podcasts subscribed.
'; return; } listEl.innerHTML = podcasts.map(p => `