using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CafeTerrace.Services;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace CafeTerrace.Views.Controller
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class BuyBagButton : ContentView,INotifyPropertyChanged
    {
        private int _foodCount = App.BuyBagService.Foods.Count;

        public int FoodCount
        {
            get { return _foodCount; }
            set { _foodCount = value; OnPropertyChanged(nameof(FoodCount)); }
        }
        public BuyBagButton()
        {
            BindingContext = this;
            InitializeComponent();

            App.BuyBagService.FoodChanged += BuyBagService_FoodChanged;
        }

        private void BuyBagService_FoodChanged(object sender, Services.BagEventArgs e)
        {
            if (e.BagEventStatus == BagEventStatus.Added)
                FoodCount++;
            else if (e.BagEventStatus == BagEventStatus.Removed)
                FoodCount--;
        }

    }
}