import { useState } from 'react' const API_URL = '/api' function ExerciseResearchPanel({ exerciseId, exerciseName }) { const [loading, setLoading] = useState(false) const [research, setResearch] = useState(null) const [error, setError] = useState(null) const fetchResearch = async () => { setLoading(true) setError(null) try { const res = await fetch(`${API_URL}/exercises/${exerciseId}/research`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({}) }) if (!res.ok) { const data = await res.json() throw new Error(data.error || 'Failed to fetch research') } const data = await res.json() setResearch(data) } catch (err) { setError(err.message) } finally { setLoading(false) } } return (

Research

{!research && ( )} {research && ( )}
{loading && (
Searching for information on {exerciseName}...
)} {error && (
{error}
)} {research && !loading && (
{research.summary && (

Summary

{research.summary}

)} {research.results && research.results.length > 0 && (

Sources

    {research.results.map((result, i) => (
  • {result.title} {result.snippet && (

    {result.snippet}

    )}
  • ))}
)}
)}
) } export default ExerciseResearchPanel