import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';

class BaseLogic extends GetxController {
  final RxBool isFilterSelected = false.obs;
  final RxBool isSearchSelected = false.obs;
  final RxnString searchValue = RxnString();
  final TextEditingController textEditingController = TextEditingController();

  void setSearchCallback(void Function(String?)? onSearchChanged) {
    debounce<String?>(searchValue, (val) {
      if (val != null && val.trim().isNotEmpty) {
        onSearchChanged?.call(val);
      }
    }, time: const Duration(milliseconds: 600));
  }

  void toggleSearch() {
    isSearchSelected.value = !isSearchSelected.value;
  }

  void clearSearch() {
    textEditingController.clear();
    searchValue.value = null;
    isSearchSelected.value = false;
  }

  void toggleFilter() {
    isFilterSelected.value = !isFilterSelected.value;
  }
}
