import 'package:bloc/bloc.dart';
import 'onboarding_event.dart';
import 'onboarding_state.dart';

// A Bloc class that manages the onboarding process
class OnboardingBloc extends Bloc<OnboardingEvent, OnboardingState> {
  int _currentPage = 0;

  OnboardingBloc() : super(OnboardingInitial()) {
    // Define the event handler for the NextPage event
    on<NextPage>((event, emit) {
      _currentPage++;
      emit(OnboardingPageChanged(_currentPage));
    });

    // Define the event handler for the PreviousPage event
    on<PreviousPage>((event, emit) {
      _currentPage--;
      emit(OnboardingPageChanged(_currentPage));
    });

    // Define the event handler for the JumpToPage event
    on<JumpToPage>((event, emit) {
      _currentPage = event.pageIndex;
      emit(OnboardingPageChanged(_currentPage));
    });
  }
}
