"use client"; import { useState, useEffect } from "react"; import { api } from "@/lib/api"; import { Card } from "@/components/ui/Card"; import { Spinner } from "@/components/ui/Spinner"; import type { Equipment } from "@/lib/types"; interface EquipmentStepProps { selectedIds: number[]; onChange: (ids: number[]) => void; } export function EquipmentStep({ selectedIds, onChange }: EquipmentStepProps) { const [equipment, setEquipment] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function fetch() { try { const data = await api.getEquipment(); setEquipment(data); } catch (err) { console.error("Failed to fetch equipment:", err); } finally { setLoading(false); } } fetch(); }, []); const toggle = (id: number) => { if (selectedIds.includes(id)) { onChange(selectedIds.filter((i) => i !== id)); } else { onChange([...selectedIds, id]); } }; // Group by category const grouped = equipment.reduce>( (acc, item) => { const cat = item.category || "Other"; if (!acc[cat]) acc[cat] = []; acc[cat].push(item); return acc; }, {} ); if (loading) { return (
); } return (

What equipment do you have?

Select all the equipment you have access to. This helps us build workouts tailored to your setup.

{Object.entries(grouped).map(([category, items]) => (

{category}

{items.map((item) => { const isSelected = selectedIds.includes(item.id); return ( toggle(item.id)} className={`p-4 text-center transition-all duration-150 ${ isSelected ? "border-[#39FF14] bg-[rgba(57,255,20,0.1)]" : "" }`} > {item.name} ); })}
))}
); }