import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'development_sizes_event.dart';
part 'development_sizes_state.dart';

class DevelopmentSizesBloc extends Bloc<DevelopmentSizesEvent, DevelopmentSizesState> {
  final CustomerRepository customerRepository;
  DevelopmentSizesBloc({required this.customerRepository}) : super(DevelopmentSizesInitial()) {
    isMan = true;
    if ( Cache().userLoggedIn == null) {
      isMan = Cache().userLoggedIn!.sex == "m";
    } 
    
    on<DevelopmentSizesLoad>(_onLoad);
  }

  late bool isMan;

  void _onLoad(DevelopmentSizesLoad event, Emitter<DevelopmentSizesState> emit)  {
    emit( DevelopmentSizesLoading());
    if ( Cache().userLoggedIn == null) {
      emit(DevelopmentSizesError(message: "Please log in" ));
      return;
    }
    customerRepository.customer = Cache().userLoggedIn!;
    emit( DevelopmentSizesReady());
  }

  

}
