using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using Telerik.Windows.Controls;

namespace WpfApp99
{
    public class DataModel : ViewModelBase
    {
        public string Title { get; set; }
    }

    public class MainWindowViewModel :ViewModelBase
    {
        #region Usercontrol A

        private ObservableCollection<DataModel> gridViewA;
        public ObservableCollection<DataModel> GridViewA
        {
            get => gridViewA;
            set
            {
                gridViewA = value;
                OnPropertyChanged("GridViewA");
            }
        }

        public ICommand OnClickAinA
        {
            get => new DelegateCommand(x =>
            {
                var item = x as DataModel;
                System.Windows.MessageBox.Show($"{item.Title}");
            });
        }
        public ICommand OnClickAinB
        {
            get => new DelegateCommand(x =>
            {
                var item = x as DataModel;
                System.Windows.MessageBox.Show($"{item.Title}");
            });
        }

        #endregion

        #region UserControl B

        private ObservableCollection<DataModel> comboDataB;
        public ObservableCollection<DataModel> ComboDataB
        {
            get => comboDataB;
            set
            {
                comboDataB = value;
                OnPropertyChanged("ComboDataB");
            }
        }

        private DataModel comboDataItemB;
        public DataModel ComboDataItemB
        {
            get => comboDataItemB;
            set
            {
                comboDataItemB = value;
                OnPropertyChanged("ComboDataItemB");
            }
        }

        private string textB;
        public string TextB
        {
            get => textB;
            set
            {
                textB = value;
                OnPropertyChanged("TextB");
            }
        }
        public ICommand OnClickB
        {
            get => new DelegateCommand(x =>
            {
                switch (ComboDataItemB.Title)
                {
                    case "A":
                        TextB = "A A A A A";
                        break;
                    case "B":
                        TextB = "B B B B B";
                        break;
                    case "C":
                        TextB = "C C C C C";
                        break;
                    case "Main":
                        TextB = "M A I N !";
                        break;
                    default:
                        TextB = "- - - - -";
                        break;
                }
            });
        }

        #endregion

        #region UserControl C

        public string TextC1 { get; set; } = "C - 1";
        public string TextC2 { get; set; } = "C - 2";
        public string TextC3 { get; set; } = "C - 3";

        #endregion

        public ObservableCollection<NavigationItemModel> Item { get; set; }

        public MainWindowViewModel() 
        {
            var data = new List<NavigationItemModel>
            {
                new NavigationItemModel {IconGlyph = "&#xe68f", Title = "UserControl A" },
                new NavigationItemModel { IconGlyph = "&#xe13a", Title = "UserControl B-C", IsSelectable = false,
                    SubItems = new ObservableCollection<NavigationItemModel>
                    {
                        new NavigationItemModel { IconGlyph = "&#xe51b", Title = "UserControl B" },
                        new NavigationItemModel { IconGlyph = "&#xe507", Title = "UserControl C" }
                    },
                },
            };

            Item = new ObservableCollection<NavigationItemModel>(data);
        }

        public void Init()
        {
            ComboDataB = new ObservableCollection<DataModel>(new List<DataModel>
            {
                new DataModel { Title = "A" },
                new DataModel { Title = "B" },
                new DataModel { Title = "C" },
                new DataModel { Title = "D" },
                new DataModel { Title = "E" },
            });
            ComboDataItemB = ComboDataB.FirstOrDefault();

            var dataModel = new List<DataModel>
            {
                new DataModel { Title = "a"},
                new DataModel { Title = "b"},
                new DataModel { Title = "c"},
                new DataModel { Title = "d"},
            };
            GridViewA = new ObservableCollection<DataModel>(dataModel);
        }
    }
}
