import 'package:flutter_bloc/flutter_bloc.dart';

abstract class ItineraryStepNavigationEvent {}

class ItineraryStepNavigationNextEvent extends ItineraryStepNavigationEvent {}

class ItineraryStepNavigationPreviousEvent extends ItineraryStepNavigationEvent {}

class ItineraryStepNavigationState {
  final int selectedIndex;
  const ItineraryStepNavigationState(this.selectedIndex);
}

class ItineraryStepNavigationBloc
    extends Bloc<ItineraryStepNavigationEvent, ItineraryStepNavigationState> {
  final int maxIndex; // maximum index allowed

  ItineraryStepNavigationBloc({this.maxIndex = 2})
    : super(const ItineraryStepNavigationState(0)) {


    on<ItineraryStepNavigationNextEvent>((event, emit) {
      final nextIndex = state.selectedIndex + 1;
      if (nextIndex <= 10) {
        emit(ItineraryStepNavigationState(nextIndex));
      }
    });

    on<ItineraryStepNavigationPreviousEvent>((event, emit) {
      final prevIndex = state.selectedIndex - 1;
      if (prevIndex >= 0) {
        emit(ItineraryStepNavigationState(prevIndex));
      }
    });
  }
}
