using NBAManagment.Entities;
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 NBAManagment
{
    /// <summary>
    /// Логика взаимодействия для PlayersMain.xaml
    /// </summary>
    public partial class PlayersMain : Window
    {
        public PlayersMain()
        {
            InitializeComponent();
            PlayersGrid.ItemsSource = App.Context.Player.ToList();
            UpdatePlayers();
            ComboSortCountry.SelectedIndex = 0; 
        }

        private void UpdatePlayers()
        {
            var Namee = App.Context.Player.ToList();
            Namee = Namee.Where(p => p.Name.ToLower().Contains(playqerNameTextBox.Text.ToLower())).ToList();
          

            if (ComboSortCountry.SelectedIndex == 0)
                Namee = Namee.ToList();
            
            if (ComboSortCountry.SelectedIndex == 1)
                Namee = Namee.Where(p => p.IdPosition == 1).ToList();


            if(ComboSortCountry.SelectedIndex == 2)
                Namee = Namee.Where(p => p.IdPosition == 2).ToList();
            if(ComboSortCountry.SelectedIndex == 3)
                Namee = Namee.Where(p => p.IdPosition == 3).ToList();
            if(ComboSortCountry.SelectedIndex == 4)
                Namee = Namee.Where(p => p.IdPosition == 4).ToList();
            if(ComboSortCountry.SelectedIndex == 5)
                Namee = Namee.Where(p => p.IdPosition == 5).ToList();
            PlayersGrid.ItemsSource = Namee;


             //< 1   ComboBoxItem Content = "SmallForward" ></ ComboBoxItem >
             //  2 < ComboBoxItem Content = "PowerForward" ></ ComboBoxItem >
             //  3 < ComboBoxItem Content = "Center" ></ ComboBoxItem >
             //  4 < ComboBoxItem Content = "ShootingGuard" ></ ComboBoxItem >
             //  5 //< ComboBoxItem Content = "PointGuard" ></ ComboBoxItem >
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            VisitorMenu visitorMenu = new VisitorMenu();
            visitorMenu.Show();
            this.Close();
        }

        private void Window_Loaded_Players(object sender, RoutedEventArgs e)
        {
            //PlayersGrid.ItemsSource = AppData.db.Players.ToList();
        }

        private void TBoxSearch_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
          
        }

        private void TBoxSearch_TextChanged(object sender, TextChangedEventArgs e)
        {  
            UpdatePlayers();

        }

        private void ComboSortCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            UpdatePlayers();

        }
    }
}
