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
    {
        private ObservableCollection<DataModel> comboData;
        public ObservableCollection<DataModel> ComboData
        {
            get => comboData;
            set
            {
                comboData = value;
                OnPropertyChanged("ComboData");
            }
        }

        private DataModel comboDataItem;
        public DataModel ComboDataItem
        {
            get => comboDataItem;
            set
            {
                comboDataItem = value;
                OnPropertyChanged("ComboDataItem");
            }
        }

        private string buttonText;
        public string ButtonText
        {
            get => buttonText;
            set
            {
                buttonText = value;
                OnPropertyChanged("ButtonText");
            }
        }

        ///////////// UserControl A
        private ObservableCollection<DataModel> userAGridView;
        public ObservableCollection<DataModel> UserAGridView
        {
            get => userAGridView;
            set
            {
                userAGridView = value;
                OnPropertyChanged("UserAGridView");
            }

        }

        private string userATextBlock = "UserControl A";
        public string UserATextBlock
        {
            get => userATextBlock;
            set
            {
                userATextBlock = value;
                OnPropertyChanged("UserATextBlock");
            }
        }


        public ICommand OnClickButtonCommand
        { 
            get => new DelegateCommand(x => 
            {
                switch(ComboDataItem.Title)
                {
                    case "A":
                        ButtonText = "A A A A A";
                        break;
                    case "B":
                        ButtonText = "B B B B B";
                        break;
                    case "C":
                        ButtonText = "C C C C C";
                        break;
                    case "Main":
                        ButtonText = "M A I N !";
                        break;
                    default :
                        ButtonText = "- - - - -";
                        break;
                }
            });
        }

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


        public MainWindowViewModel() { }

        public void Init()
        {
            ComboData = 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" },
            });
            ComboDataItem = ComboData.FirstOrDefault();

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