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;
using Agents.Class;

namespace Agents
{
    /// <summary>
    /// Логика взаимодействия для Main.xaml
    /// </summary>
    public partial class Main : Page
    {
        List<Agent> agents1 = BaseConnect.baseconnect.Agent.ToList();
        public Main()
        {
            InitializeComponent();
            listbox.ItemsSource = BaseConnect.baseconnect.Agent.ToList();
            cmbBox1.ItemsSource = BaseConnect.baseconnect.AgentType.ToList();
            cmbBox1.DisplayMemberPath = "Title";
            cmbBox1.SelectedValuePath = "ID";
        }


        private void btnDob_Click(object sender, RoutedEventArgs e)
        {
            Add add = new Add();
            add.ShowDialog();
        }

        private void cmbBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;
            int agenttype = (int)comboBox.SelectedIndex+1;
            if (agenttype != 7)
            {
                List<Agent> agents = BaseConnect.baseconnect.Agent.Where(x => x.ID == agenttype).ToList();
                listbox.ItemsSource = agents;
            }
            else
            {
                listbox.ItemsSource = agents1;
            }
        }

        private void cmbBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;
            switch(comboBox.SelectedIndex)
            {
                case 0:
                    agents1 = agents1.OrderBy(x => x.Title).ToList();
                    break;
                case 1:
                    agents1 = agents1.OrderBy(x => x.Title).ToList();
                    agents1.Reverse();
                    break;
                case 2:
                    agents1 = agents1.OrderBy(x => x.Title).ToList();
                    break;
                case 3:
                    agents1 = agents1.OrderBy(x => x.Title).ToList();
                    agents1.Reverse();
                    break;
                case 4:
                    agents1 = agents1.OrderBy(x => x.Priority).ToList();
                    break;
                case 5:
                    agents1 = agents1.OrderBy(x => x.Priority).ToList();
                    agents1.Reverse();
                    break;
            }
            listbox.ItemsSource = agents1;
        }

        private void txtBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (txtBox.Text != "")
            {
                List<Agent> agents = agents1.Where(x => x.Title.Contains(txtBox.Text)).ToList();
                listbox.ItemsSource = agents;
            }
            else
            {
                listbox.ItemsSource = agents1;
            }
        }

        private void btnRed_Click(object sender, RoutedEventArgs e)
        {
            Update update = new Update();
            update.ShowDialog();
        }
    }
}
