import 'package:e_commerce_training/src/model/repository/app_repository.dart';
import 'package:e_commerce_training/src/page/forgot_password/forgot_password.dart';
import 'package:e_commerce_training/src/util/util.dart';
import 'package:e_commerce_training/src/util/validator.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class ForgotPassCubit extends Cubit<ForgotPassState> with Validators {
  final AppRepository repository;

  String? errorEmail;

  ForgotPassCubit(this.repository) : super(ForgotPassInitial());

  void forgotPass(String email) {
    emit(ForgotPassLoading());
    errorEmail = checkEmail( email.trim());
    if (!Util.isEmpty(errorEmail)) {
      emit(ForgotPassFailure(errorEmail));
    }
  }

  void validateEmail(String email) {
    emit(ForgotPassLoading());
    errorEmail = checkEmail( email);
    emit(ForgotPassInitial());
  }
}
