
import 'package:bloc/bloc.dart';
import 'package:connectycube_sdk/connectycube_calls.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:meta/meta.dart';
import 'package:vmeeting/service/user_repositores/user_repo.dart';
import 'package:vmeeting/src/controllers/enter_number_cont.dart';
import '../../src/utils/app_utils.dart';
part 'edit_profile_event.dart';
part 'edit_profile_state.dart';

class EditProfileBloc extends Bloc<EditProfileEvent, EditProfileState> {
  EditProfileBloc() : super(EditProfileInitialState()) {
    on<EditProfileEvent>((event, emit) {
      emit(EditProfileLoadedState(user: AppUtils.cubeUser));
    });

    on<EditProfileUpdateEvent>((event, emit) async {
      try{
         await UserRepository.getInstance().updateUserProfile(event.context,event.user ?? CubeUser());
         event.controller?.inputElevatedButton.add(false);
        emit(EditProfileLoadedState(user: AppUtils.cubeUser));
      }catch(e){
        emit(EditProfileExceptionState(message: e.toString()));
      }
    });
  }
}
