import 'package:flutter_bloc/flutter_bloc.dart';

import '../viewmodel/support_model.dart';


abstract class HelpSupportEvent {}

class LoadFAQ extends HelpSupportEvent {}

class OpenQuestion extends HelpSupportEvent {
  final SupportItem item;
  OpenQuestion(this.item);
}

class HelpSupportState {
  final List<SupportItem> faqs;
  final bool isLoading;

  HelpSupportState({required this.faqs, required this.isLoading});

  factory HelpSupportState.initial() => HelpSupportState(faqs: [], isLoading: false);

  HelpSupportState copyWith({
    List<SupportItem>? faqs,
    bool? isLoading,
  }) {
    return HelpSupportState(
      faqs: faqs ?? this.faqs,
      isLoading: isLoading ?? this.isLoading,
    );
  }
}

class HelpSupportBloc extends Bloc<HelpSupportEvent, HelpSupportState> {
  HelpSupportBloc() : super(HelpSupportState.initial()) {
    on<LoadFAQ>(_onLoadFAQ);
  }

  Future<void> _onLoadFAQ(LoadFAQ event, Emitter<HelpSupportState> emit) async {
    emit(state.copyWith(isLoading: true));
    await Future.delayed(const Duration(milliseconds: 500));
    final data = [
      SupportItem("How to redeem passes?", "assets/icon/material-symbols_policy-rounded.png", "Guide"),
      SupportItem("Refund Policy", "assets/icon/mingcute_information-fill.png", "Policy"),
      SupportItem("Payment Issues", "assets/icon/solar_dollar-bold.png", "Billing and Payments"),
      SupportItem("How to redeem passes?", "assets/icon/material-symbols_policy-rounded.png", "Guide"),
      SupportItem("Refund Policy", "assets/icon/mingcute_information-fill.png", "Policy"),
      SupportItem("Payment Issues", "assets/icon/solar_dollar-bold.png", "Billing and Payments"),
    ];
    emit(state.copyWith(isLoading: false, faqs: data));
  }
}