//using System;
using System.Collections.Generic;
//using System.Text;
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;
using System.Diagnostics;
*/

namespace Sched.CustomDialogs
{
    /// <summary>
    /// Interaction logic for LanguageSelectionDialog.xaml
    /// </summary>
    public partial class LanguageSelectionDialog : Window
    {
        public string LanguageISOCode;
        public LanguageSelectionDialog()
        {
            InitializeComponent();

            this.Loaded += Window_OnLoaded;

            BTN_OK.Click += BTN_OK_Click;
            BTN_Cancel.Click += BTN_Cancel_Click;
        }

        public void Window_OnLoaded(object sender, RoutedEventArgs e)
        {
            string languageStart = "";
            List<string> languageList = new List<string>();
            for (int i = 0; i < Application.Current.Resources.MergedDictionaries.Count; i++)
            {
                var ResDict = Application.Current.Resources.MergedDictionaries[i];

                string languageName = (string)ResDict["languageName"];
                languageList.Add(languageName);

                if ((string)ResDict["languageISOCode"] == App._languageISOCode)
                {
                    languageStart = (string)ResDict["languageName"];
                }

            }
            languageList.Sort();
            CB_Language.ItemsSource = languageList;

            //Preselect current language
            foreach (var language in CB_Language.ItemsSource)
            {
                if (language.ToString() == languageStart)
                {
                    CB_Language.SelectedItem = language;
                }
            }
        }

        private void BTN_OK_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < Application.Current.Resources.MergedDictionaries.Count; i++)
            {
                var ResDict = Application.Current.Resources.MergedDictionaries[i];

                if ((string)ResDict["languageName"] == CB_Language.SelectedItem.ToString())
                {
                    LanguageISOCode = (string)ResDict["languageISOCode"];
                    break; 
                }
            }

            DialogResult = true;
            Close();
        }

        private void BTN_Cancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}
