/** * Help Page — live stats, search, copy buttons, smooth navigation */ const API_BASE = window.location.origin; class HelpPage { async init() { this.setupSearch(); this.setupCopyButtons(); this.setupToc(); await this.loadLiveStats(); console.log('[Help] Ready'); } setupSearch() { const input = document.getElementById('help-search'); if (!input) return; input.addEventListener('input', (e) => { const q = e.target.value.toLowerCase().trim(); document.querySelectorAll('.help-section').forEach((section) => { const text = section.textContent.toLowerCase(); section.style.display = !q || text.includes(q) ? '' : 'none'; }); }); } setupToc() { document.querySelectorAll('.help-toc a').forEach((link) => { link.addEventListener('click', (e) => { const id = link.getAttribute('href')?.slice(1); const el = id && document.getElementById(id); if (el) { e.preventDefault(); el.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); } setupCopyButtons() { document.querySelectorAll('[data-copy]').forEach((btn) => { btn.addEventListener('click', async () => { const text = btn.getAttribute('data-copy') || btn.closest('.code-wrap')?.querySelector('code')?.textContent; if (!text) return; try { await navigator.clipboard.writeText(text.trim()); const label = btn.textContent; btn.textContent = 'Copied!'; setTimeout(() => { btn.textContent = label; }, 1500); } catch { btn.textContent = 'Copy failed'; } }); }); } async loadLiveStats() { const el = document.getElementById('live-stats'); if (!el) return; try { const res = await fetch(`${API_BASE}/api/dashboard/overview`, { signal: AbortSignal.timeout(15000) }); if (!res.ok) throw new Error(`HTTP ${res.status}`); const data = await res.json(); const c = data.cards || {}; el.innerHTML = `
${c.total_resources ?? '—'}Registry entries
${c.api_keys_env ?? 0}+${c.api_keys_file ?? 0}API keys (env + file)
${c.models_loaded ?? 0}/${c.models_total ?? 0}Models loaded
${c.pools_healthy ?? 0}/${c.pools_total ?? 0}Healthy pools
${c.providers_online ?? 0}Providers available
`; } catch (err) { el.innerHTML = `

Live stats unavailable (${err.message}). Endpoints below still work when the Space is running.

`; } } } export default HelpPage;