import 'package:ambito/src/entity/_general/filter/item_filter_repository.dart';
import 'package:flutter/cupertino.dart';

import '../../../consts/consts.dart';

AmbitoFilterNotifier ambitoFilterNotifier = AmbitoFilterNotifier();

class AmbitoFilterNotifier extends ChangeNotifier {
  AmbitoFilterNotifier();

  AmbitoFilterNotifier.create(BuildContext context);

  Map<String, String?> activeFilters = {};
  Map<String, List<dynamic>?> activeIds = {};

  List<int> mergedIds = [];

  void setFilter(String type, String value) {
    prefs.setString('filter_$type', value).then((_) {
      activeFilters[type] = value;
      activeIds[type] = ItemFilterRepository().getIdsByTypeAndName(type, value);
      notifyListeners();
    });
  }

  void removeFilter(String type) {
    prefs.remove('filter_$type').then((_) {
      activeFilters[type] = null;
      activeIds[type] = null;
      notifyListeners();
    });
  }

  void removeAllFilters() {
    activeFilters.forEach((key, value) {
      prefs.remove('filter_$key').then((_) {
        activeFilters[key] = null;
        activeIds[key] = null;
      });
    });
    notifyListeners();
  }

  List<int>? getMergedIds() {
    return null;
  }

  String? getFilter(String type) {
    return activeFilters[type];
  }
}
