Spaces:
Build error

anycoder-d4f3e582 / components /WorkoutCard.jsx
rbachina's picture
Upload components/WorkoutCard.jsx with huggingface_hub
56aa850 verified
Raw History Blame Contribute Delete
3.67 kB
import { useState, useEffect } from 'react';
import { Heart, Clock, Flame, ChevronDown, ChevronUp, Play } from 'lucide-react';
export default function WorkoutCard({ workout, onToggleFavorite, isFavorite }) {
const [expanded, setExpanded] = useState(false);
const [imageError, setImageError] = useState(false);
const categoryColors = {
strength: 'bg-blue-100 text-blue-800',
cardio: 'bg-red-100 text-red-800',
stretch: 'bg-green-100 text-green-800',
mindfulness: 'bg-purple-100 text-purple-800',
wellness: 'bg-teal-100 text-teal-800'
};
return (
<div className="card flex flex-col h-full">
<div className="relative h-48 bg-gray-200 overflow-hidden">
{!imageError ? (
<img
src={workout.image}
alt={workout.title}
className="w-full h-full object-cover"
onError={() => setImageError(true)}
/>
) : (
<div className="w-full h-full flex items-center justify-center bg-gradient-to-br from-primary-100 to-accent-100">
<span className="text-4xl">💪</span>
</div>
)}
<button
onClick={() => onToggleFavorite(workout.id)}
className={`absolute top-3 right-3 p-2 rounded-full transition-all duration-200 ${isFavorite ? 'bg-red-500 text-white' : 'bg-white/90 text-gray-600 hover:text-red-500'}`}
>
<Heart className={`w-5 h-5 ${isFavorite ? 'fill-current' : ''}`} />
</button>
<span className={`absolute top-3 left-3 px-3 py-1 rounded-full text-xs font-semibold capitalize ${categoryColors[workout.category] || 'bg-gray-100 text-gray-800'}`}>
{workout.category}
</span>
</div>
<div className="p-5 flex-1 flex flex-col">
<h3 className="text-xl font-bold text-gray-900 mb-2">{workout.title}</h3>
<p className="text-gray-600 text-sm mb-4 flex-1">{workout.description}</p>
<div className="flex items-center gap-4 mb-4 text-sm text-gray-500">
<div className="flex items-center gap-1">
<Clock className="w-4 h-4" />
<span>{workout.duration} min</span>
</div>
<div className="flex items-center gap-1">
<Flame className="w-4 h-4 text-orange-500" />
<span>{workout.calories} cal</span>
</div>
</div>
<button
onClick={() => setExpanded(!expanded)}
className="flex items-center justify-center gap-2 w-full py-2 text-primary-600 hover:bg-primary-50 rounded-lg transition-colors duration-200 font-medium"
>
{expanded ? (
<>Hide Instructions <ChevronUp className="w-4 h-4" /></>
) : (
<>Show Instructions <ChevronDown className="w-4 h-4" /></>
)}
</button>
{expanded && (
<div className="mt-4 pt-4 border-t border-gray-100 animate-pulse-slow">
<ol className="space-y-2">
{workout.instructions.map((step, idx) => (
<li key={idx} className="flex items-start gap-2 text-sm text-gray-700">
<span className="flex-shrink-0 w-6 h-6 bg-primary-100 text-primary-700 rounded-full flex items-center justify-center text-xs font-bold">
{idx + 1}
</span>
<span>{step}</span>
</li>
))}
</ol>
<button className="mt-4 w-full btn-primary flex items-center justify-center gap-2">
<Play className="w-4 h-4" /> Start Workout
</button>
</div>
)}
</div>
</div>
);
}