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.Shapes;

namespace Met_Fam
{
    /// <summary>
    /// Логика взаимодействия для Window1.xaml
    /// </summary>
    public partial class WindowShop : Window
    {
        ViewModel viewModel = new ViewModel();
        List<Goods> change;
        public WindowShop()
        {
            InitializeComponent();
            InitializeComponent();
            LBAllGoods.ItemsSource = viewModel.gds.ToList();
            LBAllGoods.Items.Refresh();
            change = viewModel.gds;
            Filter.ItemsSource = DataBase.BaseModel.Type_Goods.ToList();
            Filter.SelectedValuePath = "ID_Type_Goods";
            Filter.DisplayMemberPath = "Title_Type_Goods";
            Filter.SelectedIndex = -1;
        }

        public void Filter_SelectionChanged(object sender, RoutedEventArgs e)
        {
            change = viewModel.gds;
            if (Filter.SelectedIndex == -1)
            {
                change = viewModel.gds;
            }
            else
            {
                change = change.Where(x => x.ID_Type_Goods - 1 == Filter.SelectedIndex).ToList();
            }
            LBAllGoods.ItemsSource = change;

            switch (Sort.SelectedIndex)
            {
                case 0:
                    change = change.OrderBy(x => x.Title_Goods).ToList();
                    break;
                case 1:
                    change = change.OrderBy(x => x.Title_Goods).ToList();
                    change.Reverse();
                    break;
                case 2:
                    change = change.OrderBy(x => x.Price_Goods).ToList();
                    break;
                case 3:
                    change = change.OrderBy(x => x.Price_Goods).ToList();
                    change.Reverse();
                    break;
            }
            LBAllGoods.ItemsSource = change;


            if (Scan.Text != "")
            {
                change = change.Where(x => x.Title_Goods.Contains(Scan.Text)).ToList();
            }
            LBAllGoods.ItemsSource = change;
        }
    }

}