import { Plus, Minus, Trash2 } from "lucide-react"; import { useI18n } from "locales/client"; import { WorkoutSet, WorkoutSetType, WorkoutSetUnit } from "@/features/workout-session/types/workout-set"; import { Button } from "@/components/ui/button"; interface WorkoutSetRowProps { set: WorkoutSet; setIndex: number; onChange: (setIndex: number, data: Partial) => void; onFinish: () => void; onRemove: () => void; } const SET_TYPES: WorkoutSetType[] = ["REPS", "WEIGHT", "TIME", "BODYWEIGHT", "NA"]; const UNITS: WorkoutSetUnit[] = ["kg", "lbs"]; export function WorkoutSessionSet({ set, setIndex, onChange, onFinish, onRemove }: WorkoutSetRowProps) { const t = useI18n(); // On utilise un tableau de types pour gérer plusieurs colonnes const types = set.types || []; const maxColumns = 4; // Handlers pour chaque champ const handleTypeChange = (columnIndex: number) => (e: React.ChangeEvent) => { const newTypes = [...types]; newTypes[columnIndex] = e.target.value as WorkoutSetType; onChange(setIndex, { types: newTypes }); }; const handleValueIntChange = (columnIndex: number) => (e: React.ChangeEvent) => { const newValuesInt = Array.isArray(set.valuesInt) ? [...set.valuesInt] : []; newValuesInt[columnIndex] = e.target.value ? parseInt(e.target.value, 10) : 0; onChange(setIndex, { valuesInt: newValuesInt }); }; const handleValueSecChange = (columnIndex: number) => (e: React.ChangeEvent) => { const newValuesSec = Array.isArray(set.valuesSec) ? [...set.valuesSec] : []; newValuesSec[columnIndex] = e.target.value ? parseInt(e.target.value, 10) : 0; onChange(setIndex, { valuesSec: newValuesSec }); }; const handleUnitChange = (columnIndex: number) => (e: React.ChangeEvent) => { const newUnits = Array.isArray(set.units) ? [...set.units] : []; newUnits[columnIndex] = e.target.value as WorkoutSetUnit; onChange(setIndex, { units: newUnits }); }; const addColumn = () => { if (types.length < maxColumns) { const newTypes = [...types, "REPS" as WorkoutSetType]; onChange(setIndex, { types: newTypes }); } }; const removeColumn = (columnIndex: number) => { const newTypes = types.filter((_, idx) => idx !== columnIndex); const newValuesInt = Array.isArray(set.valuesInt) ? set.valuesInt.filter((_, idx) => idx !== columnIndex) : []; const newValuesSec = Array.isArray(set.valuesSec) ? set.valuesSec.filter((_, idx) => idx !== columnIndex) : []; const newUnits = Array.isArray(set.units) ? set.units.filter((_, idx) => idx !== columnIndex) : []; onChange(setIndex, { types: newTypes, valuesInt: newValuesInt, valuesSec: newValuesSec, units: newUnits, }); }; const handleEdit = () => { onChange(setIndex, { completed: false }); }; const renderInputForType = (type: WorkoutSetType, columnIndex: number) => { const valuesInt = Array.isArray(set.valuesInt) ? set.valuesInt : [set.valueInt]; const valuesSec = Array.isArray(set.valuesSec) ? set.valuesSec : [set.valueSec]; const units = Array.isArray(set.units) ? set.units : [set.unit]; switch (type) { case "TIME": return (
); case "WEIGHT": return (
); case "REPS": return ( ); case "BODYWEIGHT": return ( ); default: return null; } }; return (
SET {setIndex + 1}
{/* Colonnes de types, stack vertical on mobile, horizontal on md+ */}
{types.map((type, columnIndex) => (
{types.length > 1 && ( )}
{renderInputForType(type, columnIndex)}
))}
{/* Bouton pour ajouter une colonne, sous les colonnes */} {types.length < maxColumns && (
)} {/* Finish & Edit buttons, full width on mobile */}
{set.completed && ( )}
); }