using System.ComponentModel.Composition;
using System.Windows;
using TaskIt.Core;
using TaskIt.Modules.Tasks.ViewModels;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.DragDrop;

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

            // NOTE: Categories is currently read-only, and therefore is not bindable
            foreach (var calendarCategory in ViewModel.CalendarCategories)
            {
                schCalendar.Categories.Add(new Category { CategoryName = calendarCategory.CategoryName, CategoryBrush = calendarCategory.CategoryBrush });
            }

            RadDragAndDropManager.AddDragQueryHandler(schCalendar, OnDragQuery);
        }

        private void OnDragQuery(object sender, DragDropQueryEventArgs e)
        {
            if (e.Options.Status != DragStatus.DragQuery)
            {
                return;
            }

            ViewModel.HandleCalendarTaskDrag(e);
        }

        private void CalendarContextMenuOpened(object sender, RoutedEventArgs e)
        {
            Utils.CalendarContextMenuOpened(sender, e);
        }

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