import { useState, useEffect } from 'react'
import { predictGame, getTeams } from '../api'
import { TeamLogo, getTeamName } from '../teamLogos'
function Predictions() {
const [teams, setTeams] = useState([])
const [homeTeam, setHomeTeam] = useState('LAL')
const [awayTeam, setAwayTeam] = useState('BOS')
const [prediction, setPrediction] = useState(null)
const [loading, setLoading] = useState(false)
useEffect(() => {
getTeams().then(data => {
setTeams(data.teams || [])
}).catch(console.error)
}, [])
const handlePredict = async () => {
if (!homeTeam || !awayTeam || homeTeam === awayTeam) return
setLoading(true)
try {
const result = await predictGame(homeTeam, awayTeam)
setPrediction(result)
} catch (err) {
console.error('Prediction failed:', err)
} finally {
setLoading(false)
}
}
const homeProb = prediction ? (prediction.home_win_probability * 100) : 50
const awayProb = prediction ? (prediction.away_win_probability * 100) : 50
return (
Game Predictions
Select teams to get AI-powered win probabilities
{/* Team Selector */}
{/* Away Team */}
@
{/* Home Team */}
{/* Prediction Result */}
{prediction && (
{/* Away Team */}
{prediction.away_team}
ELO: {prediction.away_elo?.toFixed(0) || 'N/A'}
{awayProb.toFixed(1)}%
{/* Prediction Center */}
Predicted Winner
{prediction.predicted_winner}
{prediction.confidence?.toUpperCase()} CONFIDENCE
ELO Difference: {prediction.elo_diff > 0 ? '+' : ''}{prediction.elo_diff?.toFixed(0)}
{/* Home Team */}
{prediction.home_team}
ELO: {prediction.home_elo?.toFixed(0) || 'N/A'}
{homeProb.toFixed(1)}%
{/* Probability Bar */}
{prediction.away_team}: {awayProb.toFixed(1)}%
{prediction.home_team}: {homeProb.toFixed(1)}%
{/* Factors */}
{prediction.factors && prediction.factors.length > 0 && (
Key Factors
{prediction.factors.map((factor, idx) => (
-
• {factor}
))}
)}
)}
)
}
export default Predictions