import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart';

class CompareList with ChangeNotifier {
  List<PharmacyProduct> _product = [];

  List<PharmacyProduct> get productListItems => _product;

  void addItem(data) {
    if (_product.length == 0) {
      _product.add(data);
      AppToast.showSuccessToast(message: 'You have added a product to the Compare list');
    } else {
      for (int i = 0; i < _product.length; i++) {
        if (_product.length <= 4 && _product[i].id != data.id) {
          _product.add(data);
          AppToast.showSuccessToast(message: 'You have added a product to the Compare list');
          break;
        } else if(_product[i].id == data.id){
          AppToast.showErrorToast(message: 'the item is already in the list');
        } else if(_product.length == 4){
          AppToast.showErrorToast(message: 'your compare list is full');
        }
      }
    }
    notifyListeners();
  }

  void deleteItem(data) {
    for (int i = 0; i < _product.length; i++) {
      if (_product[i].id == data) _product.remove(_product[i]);
    }
    notifyListeners();
  }
}
