import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/passo/class_components.dart';
import 'package:unit2/sevices/passo/class_components_services.dart';

part 'class_components_event.dart';
part 'class_components_state.dart';

class ClassComponentsBloc
    extends Bloc<ClassComponentsEvent, ClassComponentsState> {
  ClassComponentsBloc() : super(ClassComponentLoading()) {
    on<LoadClassComponents>((event, emit) async {
      emit(ClassComponentLoading());
      try {
        final classs = await ClassComponentService.instance.fetch();
        emit(ClassComponentLoaded(classs));
      } catch (e) {
        emit(ClassComponentErrorState(e.toString()));
      }
    });
  }
}
