using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace proverka
{
    /// <summary>
    /// Логика взаимодействия для Glavnay.xaml
    /// </summary>
    public partial class Glavnay : Page
    {
        List<ClassProduct> classProducts = new List<ClassProduct>();
        public static List<ClassProduct> basket;
        public Glavnay()
        {
            InitializeComponent();
            listProdyct.ItemsSource = ClassBase.BD.Product.ToList();
          if(basket != null)
            {
                classProducts=basket;
                Basket.Visibility = Visibility.Visible;
            }
        }

        private void addOrder_Click(object sender, RoutedEventArgs e)
        {
            Product index= (Product)listProdyct.SelectedItem;
            if(index!=null)
            {
                bool flag = false;
               foreach(ClassProduct product in classProducts)
                {
                    if(product.product==index)
                    {
                        product.count=product.count+=1;
                        flag=true;
                    }
                }
               if(!flag)
                {
                    ClassProduct product = new ClassProduct();
                    product.product=index;
                    product.count=1;
                    classProducts.Add(product);
                }
                Basket.Visibility = Visibility.Visible;
            }
        }

        private void Basket_Click(object sender, RoutedEventArgs e)
        {
            ClassNavigate.perehod.Navigate(new Baskets(classProducts));
        }
    }
}
