using System.Windows;
using TaskIt.Modules.Tasks.ViewModels;
using TaskIt.Web;
using Telerik.Windows.Controls;

namespace TaskIt.Modules.Tasks.Core
{
    public class TreeViewNodeDataTemplateSelector : DataTemplateSelector
    {
        public static DataTemplateProvider TemplateProvider
        {
            get { return DataTemplateProvider.Instance; }
        }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (item is CategoriesTreeViewNodeModel ||
                item is ProjectsTreeViewNodeModel ||
                item is ContextsTreeViewNodeModel ||
                item is ContactsTreeViewNodeModel)
            {
                return TemplateProvider.Resources["ParentNodeTemplate"] as DataTemplate;
            }
            
            if (item is TaskCategory)
            {
                var category = item as TaskCategory;
                switch (category.ID)
                {
                    case 0:
                        return TemplateProvider.Resources["TaskCategoryAllTemplate"] as DataTemplate;
                    case 1:
                        return TemplateProvider.Resources["TaskCategoryInboxTemplate"] as DataTemplate;
                    case 2:
                        return TemplateProvider.Resources["TaskCategoryActionsTemplate"] as DataTemplate;
                    case 3:
                        return TemplateProvider.Resources["TaskCategoryWaitingTemplate"] as DataTemplate;
                    case 4:
                        return TemplateProvider.Resources["TaskCategorySomedayTemplate"] as DataTemplate;
                    case 5:
                        return TemplateProvider.Resources["TaskCategoryTicklersTemplate"] as DataTemplate;
                    case 6:
                        return TemplateProvider.Resources["TaskCategoryReferenceTemplate"] as DataTemplate;
                }                
            }
            
            if (item is Project)
            {
                return TemplateProvider.Resources["ProjectTemplate"] as DataTemplate;
            }

            if (item is Context)
            {
                return TemplateProvider.Resources["ContextTemplate"] as DataTemplate;
            }

            if (item is Contact)
            {
                return TemplateProvider.Resources["ContactTemplate"] as DataTemplate;
            }

            return null;
        }
    }
}