`; } function showResults(app, data) { const analysis = data.analysis || {}; app.innerHTML = `

Analysis Complete ✅

Here's your personalized coaching feedback

Your Form Analysis

${analysis.formAnalysis || 'Analysis in progress...'}

Areas for Improvement

${analysis.improvementAreas || 'Analyzing...'}

Coaching Cues

    ${(analysis.coachingCues || []).map((cue, i) => `
  • ${i+1} ${cue}
  • `).join('')}
`; } function showHistory(app) { app.innerHTML = `

Analysis History

Loading...

`; loadHistory(); } async function loadHistory() { try { const res = await fetch('${API_BASE}/analyses', { headers: { 'Authorization': 'Bearer ' + localStorage.getItem('session_token') } }); const data = await res.json(); if (data.analyses && data.analyses.length > 0) { document.getElementById('historyStatus').style.display = 'none'; document.getElementById('analysisHistory').innerHTML = data.analyses.map(a => `

${a.movement_type}

${new Date(a.created_at).toLocaleDateString()}

${a.form_analysis.substring(0, 100)}...

`).join(''); } else { document.getElementById('historyStatus').innerHTML = '

No analyses yet. Start with your first video!

'; } } catch (err) { document.getElementById('historyStatus').innerHTML = '

Error loading history: ' + err.message + '

'; } } function showPricing(app) { app.innerHTML = `

Simple Pricing

Free

\$0

  • 1 video analysis per week
  • Form analysis feedback
  • 5 coaching cues
Popular

Pro

\$9.99/month

  • Unlimited video analyses
  • Detailed coaching notes
  • 8-10 coaching cues per video
  • Downloadable PDF reports
  • Video comparison tools
`; } function showAccount(app) { app.innerHTML = `

Account Settings

Profile

${currentUser?.email || 'Loading...'}

${currentUser?.plan === 'pro' ? 'Pro ✨' : 'Free'}

${currentUser?.plan === 'free' ? '' : ''}

Danger Zone

`; } async function upgradeToPro() { const token = localStorage.getItem('session_token'); try { const res = await fetch(`${API_BASE}/checkout`, { method: 'POST', headers: { 'Authorization': `Bearer ${token}` } }); const data = await res.json(); if (data.checkoutUrl) { window.location.href = data.checkoutUrl; } else { alert('Upgrade failed: ' + (data.error || 'Unknown error')); } } catch (err) { alert('Error: ' + err.message); } } // Initialize async function init() { const isAuth = await checkAuth(); if (isAuth) { showPage('upload'); } else { showPage('landing'); } } init();