import {router, useLocalSearchParams} from 'expo-router';
import { View, Text, Image } from 'react-native';
import { useEffect, useState } from 'react';
import {Workout} from "@/model/Workout";
import WorkoutPresentationComponent from "@/components/WorkoutPresentationComponent";

export default function WorkoutScreen() {
    const params = useLocalSearchParams();
    const [workout, setWorkout] = useState<Workout | null>(null);

    useEffect(() => {
        if (typeof params.workout === 'string') {
            try {
                const parsed = JSON.parse(params.workout);
                setWorkout(parsed);
            } catch (error) {
            }
        }
    }, []);

    if (!workout) {
        return <Text style={{ padding: 20, margin: 30 }}>Aucune donnée reçue.</Text>;
    }

    return (
        <View>
            <WorkoutPresentationComponent
                workout={workout}
            />r
        </View>
    );
}
