import 'package:farm_tpf/custom_model/SuppliesUsing.dart';
import 'package:get/get.dart';

class ChangeSupplyUsing extends GetxController {
  List<SuppliesUsing> currentItems = <SuppliesUsing>[];
  SuppliesUsing currentSupplyUsing = SuppliesUsing();
  int currentIndex = -1;
  void init(List<SuppliesUsing> initItems) {
    currentItems = initItems;
    currentSupplyUsing = SuppliesUsing();
    currentIndex = -1;
    update();
  }

  void changeIndexEdit(int index) {
    currentIndex = index;
    update();
  }

  void changeInitList(List<SuppliesUsing> sups) {
    currentItems = sups;
    update();
  }

  void addSupply(SuppliesUsing supplyUsing) {
    currentItems.insert(0, supplyUsing);
    currentSupplyUsing = SuppliesUsing();
    update();
  }

  void deleteSupply(int index) {
    currentItems.removeAt(index);
    currentSupplyUsing = SuppliesUsing();
    update();
  }

  void editSupply(int index, SuppliesUsing supplyUsing) {
    var newSup = supplyUsing;
    newSup.id = currentItems[index].id;
    currentItems[index] = newSup;
    currentSupplyUsing = SuppliesUsing();
    update();
  }
}
