import 'dart:async';
import 'package:aitrainer_app/repository/exercise_repository.dart';
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';

part 'body_development_event.dart';

part 'body_development_state.dart';

class BodyDevelopmentBloc extends Bloc<BodyDevelopmentEvent, BodyDevelopmentState> {
  final WorkoutTreeRepository workoutTreeRepository;
  final ExerciseRepository exerciseRepository = ExerciseRepository();

  List<int> radarTicks = [];
  List<String> radarFeatures = [];
  List<List<int>> radarData = [];

  @override
  BodyDevelopmentBloc({required this.workoutTreeRepository}) : super(BodyDevelopmentInitial());

  Future<void> getData() async {
    radarTicks = [20, 40, 60, 80, 100];
    radarFeatures = ["Mell", "Bicepsz", "Tricepsz", "Hát", "Váll"];
    radarData = [
      [80, 95, 45, 67, 83]
    ];
  }

  @override
  Stream<BodyDevelopmentState> mapEventToState(BodyDevelopmentEvent event) async* {
    try {
      if (event is BodyDevelopmentLoad) {
        yield BodyDevelopmentLoading();
        await getData();
        yield BodyDevelopmentReady();
      }
    } on Exception catch (e) {
      yield BodyDevelopmentError(message: e.toString());
    }
  }
}
