import 'package:bloc/bloc.dart';
import 'package:easycook_mobile/models/recommedation.dart';
import 'package:easycook_mobile/repositories/dapurku_repository.dart';
import 'package:equatable/equatable.dart';

part 'search_material_state.dart';

class SearchMaterialCubit extends Cubit<SearchMaterialState> {
  SearchMaterialCubit() : super(SearchMaterialInitial());

  final DapurkuRepositories _repo = DapurkuRepositories();

  Future<void> search({required String nameProduct}) async {
    emit(SearchMaterialLoading());
    try {
      final response =
          await _repo.getRecipesForRecommendation(nameProduct: nameProduct);
      emit(SearchMaterialSuccess(response.data));
    } catch (error) {
      emit(SearchMaterialFailure(message: error.toString()));
    }
  }
}
