import React from 'react'; import { MoreVertical, X, CheckSquare, ChevronUp, ChevronDown, Scale, Dumbbell, Plus, Activity, Timer as TimerIcon, ArrowRight, ArrowUp, CheckCircle, Edit, Trash2 } from 'lucide-react'; import { ExerciseType, Language, WorkoutSet } from '../../types'; import { t } from '../../services/i18n'; import FilledInput from '../FilledInput'; import ExerciseModal from '../ExerciseModal'; import { useTracker } from './useTracker'; interface ActiveSessionViewProps { tracker: ReturnType; activeSession: any; // Using any to avoid strict type issues with the complex session object for now, but ideally should be WorkoutSession lang: Language; onSessionEnd: () => void; onSessionQuit: () => void; onRemoveSet: (setId: string) => void; } const ActiveSessionView: React.FC = ({ tracker, activeSession, lang, onSessionEnd, onSessionQuit, onRemoveSet }) => { const { elapsedTime, showFinishConfirm, setShowFinishConfirm, showQuitConfirm, setShowQuitConfirm, showMenu, setShowMenu, activePlan, // This comes from useTracker props but we might need to pass it explicitly if not in hook return currentStepIndex, showPlanList, setShowPlanList, jumpToStep, searchQuery, setSearchQuery, setShowSuggestions, showSuggestions, filteredExercises, setSelectedExercise, selectedExercise, weight, setWeight, reps, setReps, duration, setDuration, distance, setDistance, height, setHeight, handleAddSet, editingSetId, editWeight, setEditWeight, editReps, setEditReps, editDuration, setEditDuration, editDistance, setEditDistance, editHeight, setEditHeight, handleCancelEdit, handleSaveEdit, handleEditSet, isCreating, setIsCreating, handleCreateExercise, exercises } = tracker; // We need activePlan from the hook or props. The hook returns 'plans' but not 'activePlan'. // Actually useTracker takes activePlan as prop but doesn't return it. // We should probably pass activePlan as a prop to this component directly from the parent. // Let's assume the parent passes it or we modify the hook. // For now, let's use the activePlan passed to the hook if possible, but the hook doesn't expose it. // I will modify the hook to return activePlan or just accept it as prop here. // The hook accepts activePlan as argument, so I can return it. // Let's modify useTracker to return activePlan in the next step if needed, or just pass it here. // Wait, I can't modify useTracker easily now without rewriting it. // I'll pass activePlan as a prop to ActiveSessionView. const isPlanFinished = activePlan && currentStepIndex >= activePlan.steps.length; return (

{activePlan ? activePlan.name : t('free_workout', lang)}

{elapsedTime} {activeSession.userBodyWeight ? ` • ${activeSession.userBodyWeight}kg` : ''}
{showMenu && ( <>
setShowMenu(false)} />
)}
{activePlan && (
{showPlanList && (
{activePlan.steps.map((step, idx) => ( ))}
)}
)}
) => { setSearchQuery(e.target.value); setShowSuggestions(true); }} onFocus={() => { setSearchQuery(''); setShowSuggestions(true); }} onBlur={() => setTimeout(() => setShowSuggestions(false), 100)} // Delay hiding to allow click icon={} autoComplete="off" type="text" /> {showSuggestions && (
{filteredExercises.length > 0 ? ( filteredExercises.map(ex => ( )) ) : (
{t('no_exercises_found', lang)}
)}
)}
{selectedExercise && (
{/* Unilateral Exercise Toggle */} {selectedExercise.isUnilateral && (
tracker.handleToggleSameValues(e.target.checked)} className="w-5 h-5 rounded border-2 border-outline bg-surface-container-high checked:bg-primary checked:border-primary cursor-pointer" />
)} {/* Input Forms */} {selectedExercise.isUnilateral && !tracker.sameValuesBothSides ? ( /* Separate Left/Right Inputs */
{/* Left Side */}
L {t('left', lang)}
{(selectedExercise.type === ExerciseType.STRENGTH || selectedExercise.type === ExerciseType.BODYWEIGHT || selectedExercise.type === ExerciseType.STATIC) && ( tracker.setWeightLeft(e.target.value)} icon={} /> )} {(selectedExercise.type === ExerciseType.STRENGTH || selectedExercise.type === ExerciseType.BODYWEIGHT || selectedExercise.type === ExerciseType.PLYOMETRIC) && ( tracker.setRepsLeft(e.target.value)} icon={} type="number" /> )} {(selectedExercise.type === ExerciseType.CARDIO || selectedExercise.type === ExerciseType.STATIC) && ( tracker.setDurationLeft(e.target.value)} icon={} /> )} {(selectedExercise.type === ExerciseType.CARDIO || selectedExercise.type === ExerciseType.LONG_JUMP) && ( tracker.setDistanceLeft(e.target.value)} icon={} /> )} {(selectedExercise.type === ExerciseType.HIGH_JUMP) && ( tracker.setHeightLeft(e.target.value)} icon={} /> )}
{/* Right Side */}
R {t('right', lang)}
{(selectedExercise.type === ExerciseType.STRENGTH || selectedExercise.type === ExerciseType.BODYWEIGHT || selectedExercise.type === ExerciseType.STATIC) && ( tracker.setWeightRight(e.target.value)} icon={} /> )} {(selectedExercise.type === ExerciseType.STRENGTH || selectedExercise.type === ExerciseType.BODYWEIGHT || selectedExercise.type === ExerciseType.PLYOMETRIC) && ( tracker.setRepsRight(e.target.value)} icon={} type="number" /> )} {(selectedExercise.type === ExerciseType.CARDIO || selectedExercise.type === ExerciseType.STATIC) && ( tracker.setDurationRight(e.target.value)} icon={} /> )} {(selectedExercise.type === ExerciseType.CARDIO || selectedExercise.type === ExerciseType.LONG_JUMP) && ( tracker.setDistanceRight(e.target.value)} icon={} /> )} {(selectedExercise.type === ExerciseType.HIGH_JUMP) && ( tracker.setHeightRight(e.target.value)} icon={} /> )}
) : ( /* Single Input Form (for bilateral or unilateral with same values) */
{(selectedExercise.type === ExerciseType.STRENGTH || selectedExercise.type === ExerciseType.BODYWEIGHT || selectedExercise.type === ExerciseType.STATIC) && ( setWeight(e.target.value)} icon={} autoFocus={activePlan && !isPlanFinished && activePlan.steps[currentStepIndex]?.isWeighted && (selectedExercise.type === ExerciseType.BODYWEIGHT || selectedExercise.type === ExerciseType.STRENGTH)} /> )} {(selectedExercise.type === ExerciseType.STRENGTH || selectedExercise.type === ExerciseType.BODYWEIGHT || selectedExercise.type === ExerciseType.PLYOMETRIC) && ( setReps(e.target.value)} icon={} type="number" /> )} {(selectedExercise.type === ExerciseType.CARDIO || selectedExercise.type === ExerciseType.STATIC) && ( setDuration(e.target.value)} icon={} /> )} {(selectedExercise.type === ExerciseType.CARDIO || selectedExercise.type === ExerciseType.LONG_JUMP) && ( setDistance(e.target.value)} icon={} /> )} {(selectedExercise.type === ExerciseType.HIGH_JUMP) && ( setHeight(e.target.value)} icon={} /> )}
)}
)} {activeSession.sets.length > 0 && (

{t('history_section', lang)}

{[...activeSession.sets].reverse().map((set: WorkoutSet, idx: number) => { const setNumber = activeSession.sets.length - idx; const isEditing = editingSetId === set.id; return (
{setNumber}
{isEditing ? (
{set.exerciseName}
{set.weight !== undefined && ( setEditWeight(e.target.value)} className="px-2 py-1 bg-surface-container-high rounded text-sm text-on-surface border border-outline-variant focus:border-primary focus:outline-none" placeholder="Weight (kg)" /> )} {set.reps !== undefined && ( setEditReps(e.target.value)} className="px-2 py-1 bg-surface-container-high rounded text-sm text-on-surface border border-outline-variant focus:border-primary focus:outline-none" placeholder="Reps" /> )} {set.durationSeconds !== undefined && ( setEditDuration(e.target.value)} className="px-2 py-1 bg-surface-container-high rounded text-sm text-on-surface border border-outline-variant focus:border-primary focus:outline-none" placeholder="Duration (s)" /> )} {set.distanceMeters !== undefined && ( setEditDistance(e.target.value)} className="px-2 py-1 bg-surface-container-high rounded text-sm text-on-surface border border-outline-variant focus:border-primary focus:outline-none" placeholder="Distance (m)" /> )} {set.height !== undefined && ( setEditHeight(e.target.value)} className="px-2 py-1 bg-surface-container-high rounded text-sm text-on-surface border border-outline-variant focus:border-primary focus:outline-none" placeholder="Height (cm)" /> )}
) : (
{set.exerciseName}
{set.type === ExerciseType.STRENGTH && `${set.weight ? `${set.weight}kg` : ''} ${set.reps ? `x ${set.reps}` : ''}`.trim() } {set.type === ExerciseType.BODYWEIGHT && `${set.weight ? `${set.weight}kg` : ''} ${set.reps ? `x ${set.reps}` : ''}`.trim() } {set.type === ExerciseType.CARDIO && `${set.durationSeconds ? `${set.durationSeconds}s` : ''} ${set.distanceMeters ? `/ ${set.distanceMeters}m` : ''}`.trim() } {set.type === ExerciseType.STATIC && `${set.durationSeconds ? `${set.durationSeconds}s` : ''}`.trim() } {set.type === ExerciseType.HIGH_JUMP && `${set.height ? `${set.height}cm` : ''}`.trim() } {set.type === ExerciseType.LONG_JUMP && `${set.distanceMeters ? `${set.distanceMeters}m` : ''}`.trim() } {set.type === ExerciseType.PLYOMETRIC && `${set.reps ? `x ${set.reps}` : ''}`.trim() }
)}
{isEditing ? ( <> ) : ( <> )}
); })}
)}
{isCreating && ( setIsCreating(false)} onSave={handleCreateExercise} lang={lang} existingExercises={exercises} /> )} {/* Finish Confirmation Dialog */} {showFinishConfirm && (

{t('finish_confirm_title', lang)}

{t('finish_confirm_msg', lang)}

)} {/* Quit Without Saving Confirmation Dialog */} {showQuitConfirm && (

{t('quit_confirm_title', lang)}

{t('quit_confirm_msg', lang)}

)}
); }; export default ActiveSessionView;