
import React from 'react';
import { WorkoutSession, WorkoutSet, WorkoutPlan, Language, SporadicSet } from '../../types';
import { useTracker } from './useTracker';
import IdleView from './IdleView';
import SporadicView from './SporadicView';
import ActiveSessionView from './ActiveSessionView';

interface TrackerProps {
    userId: string;
    userWeight?: number;
    activeSession: WorkoutSession | null;
    activePlan: WorkoutPlan | null;
    sporadicSets?: SporadicSet[];
    onSessionStart: (plan?: WorkoutPlan, startWeight?: number) => void;
    onSessionEnd: () => void;
    onSessionQuit: () => void;
    onSetAdded: (set: WorkoutSet) => void;
    onRemoveSet: (setId: string) => void;
    onUpdateSet: (set: WorkoutSet) => void;
    onSporadicSetAdded?: () => void;
    lang: Language;
}

const Tracker: React.FC<TrackerProps> = (props) => {
    const tracker = useTracker(props);
    const { isSporadicMode } = tracker;
    const { activeSession, lang, onSessionEnd, onSessionQuit, onRemoveSet, sporadicSets } = props;

    if (activeSession) {
        return (
            <ActiveSessionView
                tracker={tracker}
                activeSession={activeSession}
                lang={lang}
                onSessionEnd={onSessionEnd}
                onSessionQuit={onSessionQuit}
                onRemoveSet={onRemoveSet}
            />
        );
    }

    if (isSporadicMode) {
        return <SporadicView tracker={tracker} lang={lang} sporadicSets={sporadicSets} />;
    }

    return <IdleView tracker={tracker} lang={lang} />;
};

export default Tracker;
