// video_bloc.dart
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:tanami_app/features/contactAdmin/bloc/contact_admin_event.dart';
import 'package:tanami_app/features/contactAdmin/bloc/contact_admin_state.dart';
import 'package:tanami_app/features/contactAdmin/domain/model/contact_admin_model.dart';
import 'package:tanami_app/features/contactAdmin/domain/repository/contact_admin_api.dart';

import '../../../Api_Helper/base_manager.dart';
import '../../../Globalconst.dart';

class ContactAdminBloc extends Bloc<ContactAdminEvent, ContactAdminState> {
  ContactAdminBloc() : super(ContactAdminInitial()) {
    on<ContactAdminEvent>(mapEventToState);
  }

  Future<void> mapEventToState(
      ContactAdminEvent event, Emitter<ContactAdminState> emit) async {
    emit(ContactAdminLoading());
    try {
      ResponseData response = await ContactAdminApi().contactAdminApi();
      if (response.status == ResponseStatus.SUCCESS) {
        ContactAdminModel contactAdminModel =
            ContactAdminModel.fromJson(response.data);
        emit(ContactAdminLoaded(contactAdminModel));
      }
    } catch (e) {
      emit(ContactAdminError(Globalconst.languageSelected == "en"
          ? 'Oops Something went wrong'
          : "تبا شيء ما حدث بشكل خاطئ"));
    }
  }
}
