import { useState, useEffect } from 'react'; import { Shuffle, Filter, Sparkles } from 'lucide-react'; import WorkoutCard from './WorkoutCard'; const categories = [ { id: 'all', label: 'All Snacks', icon: '🎯' }, { id: 'strength', label: 'Strength', icon: '💪' }, { id: 'cardio', label: 'Cardio', icon: '❤️' }, { id: 'stretch', label: 'Stretch', icon: '🧘' }, { id: 'mindfulness', label: 'Mind', icon: '🧠' }, { id: 'wellness', label: 'Wellness', icon: '✨' } ]; export default function WorkoutGenerator({ favorites, onToggleFavorite }) { const [workouts, setWorkouts] = useState([]); const [currentWorkout, setCurrentWorkout] = useState(null); const [selectedCategory, setSelectedCategory] = useState('all'); const [loading, setLoading] = useState(false); useEffect(() => { fetchWorkouts(); }, [selectedCategory]); const fetchWorkouts = async () => { setLoading(true); try { const res = await fetch(`/api/workouts?category=${selectedCategory}`); const data = await res.json(); setWorkouts(data); if (data.length > 0) { setCurrentWorkout(data[Math.floor(Math.random() * data.length)]); } } catch (error) { console.error('Failed to fetch workouts:', error); } setLoading(false); }; const generateRandom = async () => { setLoading(true); try { const res = await fetch(`/api/workouts?category=${selectedCategory}&random=true`); const data = await res.json(); if (data.length > 0) { setCurrentWorkout(data[0]); } } catch (error) { console.error('Failed to generate workout:', error); } setLoading(false); }; return (

Workout Snack Generator

Quick desk-friendly exercises to keep you energized throughout the day

Built with anycoder →
{categories.map(cat => ( ))}
{currentWorkout && (
Your Daily Snack
)}
{workouts.filter(w => w.id !== currentWorkout?.id).map(workout => ( ))}
); }