import React, { useState, useEffect } from 'react';
import { Activity, TrendingUp, AlertCircle, CheckCircle, Moon, Zap, Heart, Calendar, Award, Target, BarChart3, Settings, User, LogOut, Plus, ChevronRight, Bell, Flame } from 'lucide-react';
// Mock API service
const mockAPI = {
getDashboard: async () => ({
user: { name: 'Alex Johnson', streak: 15, totalWorkouts: 48 },
recommendation: {
acwr: 1.18,
wellness_score: 7.3,
pain_level: 1,
injury_risk: 0.15,
status: { color: 'green', text: 'Ready to Progress' },
recommendations: {
action: 'PROGRESS',
load_change_percent: 5,
message: "You're in the optimal zone! Add 5% to your main lifts today.",
focus: 'Progressive overload'
},
recovery: {
days_to_baseline: 0,
recovery_status: 0.95,
trajectory: 'improving',
baseline_wellness: 7.2
},
risk_factors: ['Low injury risk', 'Good recovery status'],
personalized_thresholds: { green_max: 1.35, yellow_max: 1.55 }
}
})
};
const EnhancedACWRApp = () => {
const [currentScreen, setCurrentScreen] = useState('dashboard');
const [dashboardData, setDashboardData] = useState(null);
const [loading, setLoading] = useState(true);
const [wellness, setWellness] = useState({
energy: 7, sleep: 7, soreness: 7, motivation: 7, pain: 0
});
const [checkinStep, setCheckinStep] = useState(0);
const [showCheckinResults, setShowCheckinResults] = useState(false);
useEffect(() => {
loadDashboard();
}, []);
const loadDashboard = async () => {
setLoading(true);
const data = await mockAPI.getDashboard();
setDashboardData(data);
setLoading(false);
};
const StatCard = ({ icon: Icon, label, value, max, color }) => (
);
const NavBar = () => (
{user.streak}
{recommendation.risk_factors.length > 0 && (
)}
);
};
const CheckInScreen = () => {
const questions = [
{ field: 'energy', label: 'Energy Level', icon: Zap, desc: 'How energized do you feel?' },
{ field: 'sleep', label: 'Sleep Quality', icon: Moon, desc: 'How well did you sleep?' },
{ field: 'soreness', label: 'Muscle Soreness', icon: Activity, desc: 'How sore are your muscles?' },
{ field: 'motivation', label: 'Motivation', icon: Target, desc: 'How motivated are you?' },
{ field: 'pain', label: 'Pain Level', icon: AlertCircle, desc: 'Any pain today?', showZero: true }
];
const currentQuestion = questions[checkinStep];
const handleNext = () => {
if (checkinStep < questions.length - 1) {
setCheckinStep(checkinStep + 1);
} else {
setShowCheckinResults(true);
}
};
const handlePrevious = () => {
if (checkinStep > 0) {
setCheckinStep(checkinStep - 1);
}
};
if (showCheckinResults) {
const wellnessScore = ((wellness.energy + wellness.sleep + wellness.soreness + wellness.motivation) / 4).toFixed(1);
// Calculate recommendation based on actual wellness values
const calculateRecommendation = () => {
const score = parseFloat(wellnessScore);
const painLevel = wellness.pain;
const reasons = [];
// Safety overrides
if (painLevel >= 6) {
reasons.push(`High pain level (${painLevel}/10)`);
reasons.push('Rest is required for injury prevention');
return {
color: 'red',
status: 'Mandatory Rest',
message: 'High pain detected. Complete rest required today.',
icon: AlertCircle,
reasons
};
}
if (score < 4) {
reasons.push(`Low wellness score (${wellnessScore}/10)`);
if (wellness.energy < 5) reasons.push(`Low energy (${wellness.energy}/10)`);
if (wellness.sleep < 5) reasons.push(`Poor sleep (${wellness.sleep}/10)`);
if (wellness.soreness > 7) reasons.push(`High soreness (${wellness.soreness}/10)`);
if (wellness.motivation < 5) reasons.push(`Low motivation (${wellness.motivation}/10)`);
if (painLevel > 0) reasons.push(`Pain present (${painLevel}/10)`);
return {
color: 'red',
status: 'Rest Day',
message: 'Your body needs recovery. Take today off or do light activity only.',
icon: AlertCircle,
reasons
};
}
if (painLevel >= 4) {
reasons.push(`Moderate pain (${painLevel}/10)`);
reasons.push('Training should be modified or avoided');
return {
color: 'red',
status: 'Rest Day',
message: 'Your body needs recovery. Take today off or do light activity only.',
icon: AlertCircle,
reasons
};
}
if (score < 6 || painLevel === 3) {
reasons.push(`Below-average wellness (${wellnessScore}/10)`);
if (wellness.energy < 6) reasons.push(`Lower energy (${wellness.energy}/10)`);
if (wellness.sleep < 6) reasons.push(`Suboptimal sleep (${wellness.sleep}/10)`);
if (wellness.soreness > 6) reasons.push(`Elevated soreness (${wellness.soreness}/10)`);
if (wellness.motivation < 6) reasons.push(`Lower motivation (${wellness.motivation}/10)`);
if (painLevel > 0) reasons.push(`Pain present (${painLevel}/10)`);
return {
color: 'orange',
status: 'Reduce Load',
message: 'Reduce weight by 15-20%. Your body needs easier training today.',
icon: AlertCircle,
reasons
};
}
if (score < 7) {
reasons.push(`Moderate wellness (${wellnessScore}/10)`);
if (wellness.energy < 7) reasons.push(`Energy could be better (${wellness.energy}/10)`);
if (wellness.sleep < 7) reasons.push(`Sleep could be better (${wellness.sleep}/10)`);
if (wellness.soreness > 5) reasons.push(`Some soreness present (${wellness.soreness}/10)`);
if (painLevel > 0) reasons.push(`Minor pain (${painLevel}/10)`);
return {
color: 'yellow',
status: 'Maintain Load',
message: 'Keep weights the same as last workout. Focus on movement quality.',
icon: Activity,
reasons
};
}
// Good state - ready to progress
reasons.push(`Excellent wellness score (${wellnessScore}/10)`);
if (wellness.energy >= 8) reasons.push(`High energy (${wellness.energy}/10)`);
if (wellness.sleep >= 8) reasons.push(`Great sleep quality (${wellness.sleep}/10)`);
if (wellness.soreness <= 4) reasons.push(`Low soreness (${wellness.soreness}/10)`);
if (wellness.motivation >= 8) reasons.push(`High motivation (${wellness.motivation}/10)`);
if (painLevel === 0) reasons.push('No pain reported');
return {
color: 'green',
status: 'Ready to Progress',
message: 'Great scores! Add 5-10% to your main lifts today.',
icon: CheckCircle,
reasons
};
};
const recommendation = calculateRecommendation();
const statusColors = {
green: 'from-green-50 to-green-100 border-green-300 text-green-800',
yellow: 'from-yellow-50 to-yellow-100 border-yellow-300 text-yellow-800',
orange: 'from-orange-50 to-orange-100 border-orange-300 text-orange-800',
red: 'from-red-50 to-red-100 border-red-300 text-red-800'
};
const iconColors = {
green: 'text-green-600',
yellow: 'text-yellow-600',
orange: 'text-orange-600',
red: 'text-red-600'
};
return (
{recommendation.status}
)}
);
}
return (
setWellness({...wellness, [currentQuestion.field]: parseInt(e.target.value)})}
className="w-full h-4 bg-gradient-to-r from-red-300 via-yellow-300 to-green-300 rounded-lg appearance-none cursor-pointer mb-4"
/>
);
};
const WorkoutScreen = () => (
Ready to Progress
);
const ProgressScreen = () => (
);
const ProfileScreen = () => (
);
return (
{value}{max && `/${max}`}
{label}
{[
{ id: 'dashboard', icon: Activity, label: 'Home' },
{ id: 'checkin', icon: Heart, label: 'Check-In' },
{ id: 'workout', icon: Plus, label: 'Log' },
{ id: 'progress', icon: BarChart3, label: 'Progress' },
{ id: 'profile', icon: User, label: 'Profile' }
].map(nav => (
))}
);
const DashboardScreen = () => {
if (loading || !dashboardData) return Loading...
;
const { user, recommendation } = dashboardData;
const statusColors = {
green: 'from-green-500 to-green-600',
yellow: 'from-yellow-500 to-yellow-600',
orange: 'from-orange-500 to-orange-600',
red: 'from-red-500 to-red-600'
};
const statusColor = statusColors[recommendation.status.color];
return (
Hey, {user.name.split(' ')[0]}! 👋
Let's make today count
Training Load Status
{recommendation.acwr}
ACWR Score
0.8
{recommendation.personalized_thresholds.green_max}
{recommendation.personalized_thresholds.yellow_max}
2.0+
{recommendation.status.text}
Today's AI Recommendation
Confidence
85%
💪 Action Plan:
{recommendation.recommendations.message}
Key Insights:
{recommendation.risk_factors.map((factor, idx) => (
{factor}
))}
Recovery Status
{recommendation.recovery.trajectory}
Current: {recommendation.wellness_score}
Baseline: {recommendation.recovery.baseline_wellness}
Quick Actions
All Set! 🎉
Your daily check-in is complete
= 7 ? 'text-green-600' :
wellnessScore >= 6 ? 'text-yellow-600' :
wellnessScore >= 5 ? 'text-orange-600' :
'text-red-600'
}`}>{wellnessScore}
Wellness Score
{wellnessScore >= 8 ? 'Excellent' :
wellnessScore >= 7 ? 'Good' :
wellnessScore >= 6 ? 'Moderate' :
wellnessScore >= 5 ? 'Fair' : 'Low'}
{Object.entries(wellness).map(([key, value]) => {
// Pain uses reverse color logic (low is good, high is bad)
const isPain = key === 'pain';
let colorClass;
if (isPain) {
colorClass = value === 0 ? 'text-green-600' :
value <= 2 ? 'text-yellow-600' :
value <= 5 ? 'text-orange-600' :
'text-red-600';
} else {
colorClass = value >= 7 ? 'text-green-600' :
value >= 5 ? 'text-yellow-600' :
'text-orange-600';
}
return (
);
})}
{value}
{key}
{recommendation.message}
{recommendation.reasons && recommendation.reasons.length > 0 && (Why this recommendation:
-
{recommendation.reasons.map((reason, idx) => (
- • {reason} ))}
Daily Check-In
Question {checkinStep + 1} of {questions.length}
{questions.map((q, idx) => (
))}
{currentQuestion.desc}
Slide to rate how you feel
{wellness[currentQuestion.field]}
{wellness[currentQuestion.field] <= 3 ? 'Low' :
wellness[currentQuestion.field] <= 6 ? 'Moderate' : 'High'}
{currentQuestion.showZero ? 'None' : 'Low'}
Medium
High
{checkinStep > 0 && (
)}
Log Workout
Track your training session
Today's Recommendation
Add 5% weight to your main lifts today
Exercises
Workout logging coming soon...
Your Progress
Track your journey
Achievements
🔥
15
Day Streak
💪
48
Workouts
🎯
0
Injuries
Alex Johnson
Member since Jan 2025
{[
{ icon: Settings, label: 'Settings' },
{ icon: Award, label: 'Achievements' },
{ icon: Calendar, label: 'Training History' },
{ icon: Target, label: 'Goals' },
{ icon: LogOut, label: 'Logout' }
].map((item, idx) => (
))}
{currentScreen === 'dashboard' && }
{currentScreen === 'checkin' && }
{currentScreen === 'workout' && }
{currentScreen === 'progress' && }
{currentScreen === 'profile' && }
);
};
export default EnhancedACWRApp;