using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
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 Sched.CustomClasses;
using Sched.CustomControls;

namespace Sched
{
    /// <summary>
    /// Interaction logic for DatabaseWindow.xaml
    /// </summary>

    public partial class DatabaseWindow : Window
    {
        private string _tableName = string.Empty;

        public DatabaseWindow()
        {
            InitializeComponent();

            Loaded += DatabaseWindow_Loaded;
            TV_Category.SelectedItemChanged += TV_Category_SelectedItemChanged;
            BTN_Filter.Click += BTN_Filter_Click;
            BTN_ResetView.Click += BTN_ResetView_Click;
        }

        private void DatabaseWindow_Loaded(object sender, RoutedEventArgs e)
        {
            List<string> categoryList = new List<string>() {
                "Str_Curriculum","Str_CurriculumCourse", "Str_Course", "Str_CourseHours",
                "Str_StudentGroup",
                "Str_LessonType",
                "Str_Building", "Str_Room", "Str_RoomType",
                "Str_Teacher",
                "Str_Semester", "Str_SemesterType"};

            List<TextBlock> CB_List = new List<TextBlock>();
            foreach (string s in categoryList)
            {
                TextBlock tBlock = new TextBlock();
                tBlock.Name = "TB_" + s;
                tBlock.SetResourceReference(TextBlock.TextProperty, s);
                CB_List.Add(tBlock);
            }
            TV_Category.ItemsSource = CB_List;
        }
        private void TV_Category_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            var tView = sender as TreeView;
            if (tView != null)
            {
                _tableName = ((TextBlock)tView.SelectedItem).Name.Substring(7);
                SC_Main.Content = new EditTableForm(_tableName);
            }
        }
        private void BTN_Filter_Click(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            if (btn != null)
            {
                var EditForm = SC_Main.Content as EditTableForm;
                if (EditForm != null)
                {
                    EditForm.DG_Filter(TB_Filter.Text);
                }
            }
        }
        private void BTN_ResetView_Click(object sender, RoutedEventArgs e)
        {
            TB_Filter.Text = string.Empty;
            BTN_Filter_Click(sender, e);
        }

    }
}
