import 'package:food_delivery_client/food_delivery_client.dart';

part 'splash_event.dart';

part 'splash_state.dart';

part 'splash_bloc.freezed.dart';

@injectable
class SplashBloc extends Bloc<SplashEvent, SplashState> {
  final StorageService _storageService;

  SplashBloc(this._storageService) : super(const SplashState()) {
    on<_Started>(_onStarted);
  }

  _onStarted(_Started event, Emitter<SplashState> emit) async {
    await Future.delayed(TimeDelayConst.duration2);
    final token = _storageService.getString(key: AppLocaleKeys.token);
    log("Token:$token");
    if (token != null) {
      emit(state.copyWith(status: RequestStatus.loaded));
    } else {
      emit(state.copyWith(status: RequestStatus.error));
    }
  }
}
