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.Shapes;

namespace barry
{
    /// <summary>
    /// Logique d'interaction pour OptionsWindow.xaml
    /// </summary>
    public partial class OptionsWindow : Window
    {
        Methods methods = new Methods();
        BackupConfig bkp;
        bool _loaded = false;
        public OptionsWindow(BackupConfig current_bkp)
        {

            InitializeComponent();
            _loaded = true;

            bkp = current_bkp;

            txt_path.Text = bkp.dir_path;
            txt_subdir.Text = bkp.local_subdir;
            foreach (ComboBoxItem item in cb_bkptype.Items)
            {
                if(item.Tag.Equals(bkp.bkp_type))
                {
                    cb_bkptype.SelectedItem = item;
                }
            }

        }

        private void btn_save_Click(object sender, RoutedEventArgs e)
        {
            methods.save_this_cpu(bkp);
            Close();
        }

        private void btn_cancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void cb_bkptype_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!_loaded) { return; }
            bkp.bkp_type = int.Parse(cb_bkptype.Tag.ToString());
            update_window();
        }

        private void update_window()
        {
            if (!_loaded) { return; }
            lbl_decription.Content = bkp.describe();
        }

        private void txt_subdir_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!_loaded) { return; }
            //if (! System.IO.Directory.Exists(txt_subdir.Text))
            //{
            //    lbl_decription.Content = "Wait! Barry does not find this directory on the computer!";
            //    return;
            //}
            
            bkp.local_subdir = txt_subdir.Text;
            update_window();
        }

        private void txt_path_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!_loaded) { return; }
            bkp.dir_path = txt_path.Text;
            update_window();
        }

    }
}
