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 BuzuevaDemo.Classes;

namespace BuzuevaDemo.Pages
{
    /// <summary>
    /// Логика взаимодействия для Agents.xaml
    /// </summary>
    public partial class Agents : Page
    {
        ViewModel view = new ViewModel();
        List<Agent> filter;

        public Agents()
        {
            InitializeComponent();
            AllAgent.ItemsSource = view.agent.ToList();
            AllAgent.Items.Refresh();
            filter = view.agent.ToList();
        }

        private void Changeg(object sender, TextChangedEventArgs e)
        {
            filter = view.agent;
            if (poisk.Text != "")
            {
                filter = filter.Where(x => x.Title.Contains(poisk.Text) || x.Email.Contains(poisk.Text) || x.Phone.Contains(poisk.Text)).ToList();

            }
            AllAgent.ItemsSource = filter.ToList();

            
        }

        private void PerexodCreate(object sender, MouseButtonEventArgs e)
        {
            StackPanel zapis = (StackPanel)sender;
            int id = Convert.ToInt32(zapis.Uid);
            Agent agent = DataBase.BaseModel.Agent.FirstOrDefault(x => x.ID == id);
            new CreateChange(agent, 0).ShowDialog();
        }
    }
}
