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 SASDesktop.Views.Transport
{
    /// <summary>
    /// Логика взаимодействия для Create.xaml
    /// </summary>
    public partial class Create : Page
    {
        public Create()
        {
            InitializeComponent();
            DataContext = new ViewModels.Transport.Create();
        }

        private ViewModels.Transport.Create GetTypedContext()
        {
            return (DataContext as ViewModels.Transport.Create);
        }

        #region Подсказки брендов
        private void tbBrand_GotFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().BrandSuggestionsVisible = true;
        }

        private void tbBrand_LostFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().BrandSuggestionsVisible = false;
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as ListBox).SelectedItem is Models.Brand)
            {
                var selectedBrand = (sender as ListBox).SelectedItem as Models.Brand;

                // Скрываем подсказки
                GetTypedContext().BrandSuggestionsVisible = false;

                // Устанавливаем наименование в поле поиска
                GetTypedContext().BrandSearch = selectedBrand.Name;

                // Устанавливаем выбранное значение
                GetTypedContext().SelectedBrand = selectedBrand;
            }
        }
        #endregion

        #region Подсказки моделей
        private void tbModel_GotFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().ModelSuggestionsVisible = true;
        }

        private void tbModel_LostFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().ModelSuggestionsVisible = false;
        }

        private void lbModelSuggestions_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as ListBox).SelectedItem is Models.Model)
            {
                var selectedModel = (sender as ListBox).SelectedItem as Models.Model;

                // Скрываем подсказки
                GetTypedContext().ModelSuggestionsVisible = false;

                // Устанавливаем наименование в поле поиска
                GetTypedContext().ModelSearch = selectedModel.Name;

                // Устанавливаем выбранное значение
                GetTypedContext().SelectedModel = selectedModel;
            }
        }
        #endregion

        #region Подсказки цветов
        private void tbColor_GotFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().ColorSuggestionsVisible = true;
        }

        private void tbColor_LostFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().ColorSuggestionsVisible = false;
        }

        private void lbColorSuggestions_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as ListBox).SelectedItem is Models.Color)
            {
                var selectedColor = (sender as ListBox).SelectedItem as Models.Color;

                // Скрываем подсказки
                GetTypedContext().ColorSuggestionsVisible = false;

                // Устанавливаем наименование в поле поиска
                GetTypedContext().ColorSearch = selectedColor.NameRus;

                // Устанавливаем выбранное значение
                GetTypedContext().SelectedColor = selectedColor;
            }
        }
        #endregion

        #region Подсказки владельцев
        private void tbOwner_GotFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().OwnerSuggestionsVisible = true;
        }

        private void tbOwner_LostFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().OwnerSuggestionsVisible = false;
        }

        private void lbOwners_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as ListBox).SelectedItem is Models.Citizen)
            {
                var selectedOwner = (sender as ListBox).SelectedItem as Models.Citizen;

                // Скрываем подсказки
                GetTypedContext().OwnerSuggestionsVisible = false;

                // Устанавливаем наименование в поле поиска
                GetTypedContext().OwnerSearch = selectedOwner.GetHumanName;

                // Устанавливаем выбранное значение
                GetTypedContext().SelectedOwner = selectedOwner;
            }
        }
        #endregion

        #region Подсказки моделей двигателей
        private void tbEngineModel_GotFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().EngineModelSuggestionsVisible = true;
        }

        private void tbEngineModel_LostFocus(object sender, RoutedEventArgs e)
        {
            GetTypedContext().EngineModelSuggestionsVisible = false;
        }

        private void lbEngineModelSuggestions_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((sender as ListBox).SelectedItem is Models.EngineModel)
            {
                var selectedEngineModel = (sender as ListBox).SelectedItem as Models.EngineModel;

                // Скрываем подсказки
                GetTypedContext().EngineModelSuggestionsVisible = false;

                // Устанавливаем наименование в поле поиска
                GetTypedContext().EngineModelSearch = selectedEngineModel.Name;

                // Устанавливаем выбранное значение
                GetTypedContext().SelectedEngineModel = selectedEngineModel;
            }
        }
        #endregion
    }
}
