using System.Collections.Generic;
using System.ComponentModel.Composition;
using GalaSoft.MvvmLight.Messaging;
using TaskIt.Infrastructure;
using TaskIt.Models;
using TaskIt.Modules.Dashboard.Assets.Resources;
using TaskIt.Modules.Dashboard.Model;
using TaskIt.ViewModels;
using Telerik.Windows.Controls.Charting;

namespace TaskIt.Modules.Dashboard.ViewModels
{
    [Export]
    public class TasksOverviewViewModel : WidgetViewModelBase
    {
        public TasksOverviewViewModel()
        {
            LoadData();
            Messenger.Default.Register<ModuleEnum>(this, OnPageEnter);
            Brushes = ChartPalette.GetPalette();
        }

        private void OnPageEnter(ModuleEnum args)
        {
            if (args == ModuleEnum.Dashboard)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            // TODO: Ross - Loading temporary hard-coded data because I couldn't get Function Import working properly on my DataModel
            TasksOverviewStatistics = TasksOverviewData.GetTasksOverview();
            this.OnPropertyChanged(m => m.TasksOverviewStatistics);
            NotifyDataLoaded();
        }

        //private void LoadData()
        //{
            //ShowBusyIndicator();
            //Utils.HideBusyIndicator();
            //Utils.DataContext.TasksOverviews.Clear(); // Need to clear to get up-to-date data
            //DataProvider.GetTasksOverview(Utils.CurrentUserID, OnTasksOverviewLoaded);
        //}        

        //void OnTasksOverviewLoaded(LoadOperation<TasksOverview> lo)
        //{
        //    if (lo.HasError)
        //    {
        //        Utils.ShowErrorMessage(DashboardErrorStrings.Message_LoadingTasksOverviewFailed, lo.Error.Message);
        //        lo.MarkErrorAsHandled();
        //        return;
        //    }

        //    this.OnPropertyChanged(p => p.TasksOverviewStatistics);
        //    NotifyDataLoaded();
        //    HideBusyIndicator();
        //}

        //public ObjectResult<TasksOverview> TasksOverviewStatistics
        //{
        //    get { return Utils.DataContext.TasksOverviews; }
        //}

        # region Properties

        public List<TasksOverviewData> TasksOverviewStatistics { get; set; }

        public BrushCollection Brushes { get; set; }

        # endregion

        # region Resources

        public string ResourceLegendItemOverdue
        {
            get { return TasksOverviewStrings.LegendItem_Overdue; }
        }

        public string ResourceLegendItemDueThisWeek
        {
            get { return TasksOverviewStrings.LegendItem_DueThisWeek; }
        }

        public string ResourceLegendItemDueThisMonth
        {
            get { return TasksOverviewStrings.LegendItem_DueThisMonth; }
        }

        public string ResourceLegendItemCompletedThisWeek
        {
            get { return TasksOverviewStrings.LegendItem_CompletedThisWeek; }
        }

        public string ResourceLegendItemCompletedThisMonth
        {
            get { return TasksOverviewStrings.LegendItem_CompletedThisMonth; }
        }

        # endregion

    }
}