using Office2016InspiredApplication.Appearance;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Spreadsheet.Commands.Descriptors;

namespace Office2016InspiredApplication.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        public ICommand ChangeUserControlCommand { get; set; }

        public MainViewModel()
        {
            MainViewModel.SelectedColorVariation = Office2016ColorVariations.Colorful;
            MainViewModel.SelectedOffice2016AccentBrush = Office2016AccentBrushes.WordBased;
            AppearanceManager.ChangeAppearance(MainViewModel.SelectedColorVariation, MainViewModel.SelectedOffice2016AccentBrush);
            this.ChangeAppearanceCommand = new DelegateCommand(this.ChangeColorVariation);
            this.ChangeUserControlCommand = new DelegateCommand(this.CustomCommandExecuted);
        }

        private void CustomCommandExecuted(object clickedItem)
        {
            if (clickedItem != null)
            {
                RadRibbonWindow win = new RadRibbonWindow();
                win.Style = Application.Current.Resources["RadRibbonWindowStyle"] as Style;
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                switch (clickedItem.ToString())
                {
                    case "RibbonView":
                      win.Content = new RibbonViewControl();
                      this.CurrentOffice2016AccentBrush = Office2016AccentBrushes.WordBased;
                      MainViewModel.SelectedOffice2016AccentBrush = this.CurrentOffice2016AccentBrush;
                      AppearanceManager.ChangeAppearance(MainViewModel.SelectedColorVariation, MainViewModel.SelectedOffice2016AccentBrush);
                      break;
                    case "Spreadsheet":
                      win.Content = new SpreadSheetControl();
                      this.CurrentOffice2016AccentBrush = Office2016AccentBrushes.ExcelBased;
                      MainViewModel.SelectedOffice2016AccentBrush = this.CurrentOffice2016AccentBrush;
                      AppearanceManager.ChangeAppearance(MainViewModel.SelectedColorVariation, MainViewModel.SelectedOffice2016AccentBrush);
                      break;
                    case "RichTextbox":
                      win.Content = new RichTextBoxControl();
                      this.CurrentOffice2016AccentBrush = Office2016AccentBrushes.WordBased;
                      MainViewModel.SelectedOffice2016AccentBrush = this.CurrentOffice2016AccentBrush;
                      AppearanceManager.ChangeAppearance(MainViewModel.SelectedColorVariation, MainViewModel.SelectedOffice2016AccentBrush);
                      break;
                }
                win.Show();
            }
        }

        private void ChangeColorVariation(object parameter)
        {
            var commandParameter = parameter as AppearanceCommandParameter;
            if (this.ColorVariation == commandParameter.ColorVariation)
            {
                return;
            }

            this.CurrentColorVariation = commandParameter.ColorVariation;
            MainViewModel.SelectedColorVariation = this.CurrentColorVariation;

            this.ColorVariation = commandParameter.ColorVariation;

            AppearanceManager.ChangeAppearance(this.ColorVariation, MainViewModel.SelectedOffice2016AccentBrush);
        }

        public DelegateCommand ChangeAppearanceCommand { get; private set; }

        public Office2016ColorVariations ColorVariation { get; private set; }

        public Office2016AccentBrushes Office2016AccentBrush { get; private set; }

        public Office2016ColorVariations CurrentColorVariation { get; private set; }

        public Office2016AccentBrushes CurrentOffice2016AccentBrush { get; private set; }

        public static Office2016ColorVariations SelectedColorVariation {get; set; }

        public static Office2016AccentBrushes SelectedOffice2016AccentBrush { get; set; } 

    }
}
