import 'package:get/get.dart';

import '../../../core/utils/logs_utils.dart';
import '../views/model/FAQS.dart';


class FaqsSecondController extends GetxController {
  late Question question;
  final searchText = ''.obs;
  RxList<SubQuestion> filteredListSubQuestions = <SubQuestion>[].obs;

  @override
  onInit() {
    super.onInit();
    question = Get.arguments;
    filteredListSubQuestions.value = question.subQuestions;
    debounce(searchText, (_) => filterListQuestions(), time: const Duration(milliseconds: 300));
  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
    dp("filteredListSubQuestions", filteredListSubQuestions.toString());
  }

  void filterListQuestions() {
    if (searchText.value.isEmpty) {
      filteredListSubQuestions.value = question.subQuestions;
    } else {
      filteredListSubQuestions.value = question.subQuestions.where((question) => question.title.toLowerCase().contains(searchText.value.toLowerCase())).toList();
    }
  }
}
