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

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

  List<PharmacyProduct> get productListItems => _product;

  void addItem(data, context) {
    if (_product.length == 0) {
      _product.add(data);
      AppToast.showSuccessToast(message:TranslationBase.of(context).addToCompareMsg
    //  'You have added a product to the Compare list'
      );
    } else {
      for (int i = 0; i < _product.length; i++) {
        if (_product.length < 3 && _product[i].id != data.id) {
          _product.add(data);
          AppToast.showSuccessToast(message:TranslationBase.of(context).addToCompareMsg
         // 'You have added a product to the Compare list'
          );
          break;
        } else if(_product[i].id == data.id){
          AppToast.showErrorToast(message:TranslationBase.of(context).itInListMsg
         // 'the item is already in the list'
          );
        } else if(_product.length == 3){
          AppToast.showErrorToast(message: TranslationBase.of(context).compareListFull
         // '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();
  }
}
