using System.ComponentModel.Composition;
using System.Windows;
using TaskIt.Modules.Tasks.ViewModels;

namespace TaskIt.Modules.Tasks.Views
{
    public partial class List
    {
        public List()
        {            
            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            DataContext = ViewModel;

            ViewModel.ViewGrid += OnViewGrid;
            ViewModel.ViewCalendar += OnViewCalendar;
            ViewModel.TwitterMessage += OnTwitterMessage;
            ViewModel.CloseTwitterWindow += OnCloseTwitterWindow;

            SubmitTwitterMessageWindow.DataContext = ViewModel;

            GridView = new Grid();
            CalendarView = new Calendar();

            ViewContainer.Content = GridView;
        }

        void OnViewGrid(object sender, RoutedEventArgs e)
        {
            ViewContainer.Content = GridView;
        }

        void OnViewCalendar(object sender, RoutedEventArgs e)
        {
            ViewContainer.Content = CalendarView;
        }

        void OnTwitterMessage(object sender, RoutedEventArgs e)
        {
            SubmitTwitterMessageWindow.Show();
        }

        void OnCloseTwitterWindow(object sender, RoutedEventArgs e)
        {
            SubmitTwitterMessageWindow.Close();
        }

        private void SubmitTwitterMessageWindowClosed(object sender, Telerik.Windows.Controls.WindowClosedEventArgs e)
        {
            ViewModel.CloseTwitterWindowCommand.Execute(null);
        }

        public Grid GridView { get; set; }
        
        public Calendar CalendarView { get; set; }

        [Import]
        public ListViewModel ViewModel { get; set; }

    }
}