namespace OfficeControlsTestApp.ViewModels
{
    #region Using
    using System;
    using System.ComponentModel;
    #endregion

    class MainWindowViewModel : INotifyPropertyChanged
    {
        #region Свойства
        private string browserFile;
        private string excelFile;
        private string wordFile;
        #endregion

        #region Конструктор
        public MainWindowViewModel()
        {
            this.excelFile = string.Empty;
            this.wordFile = string.Empty;
        }
        #endregion

        #region Общие свойства
        public string BrowserFile
        {
            get { return this.browserFile; }
            set
            {
                if (this.browserFile != value)
                {
                    this.browserFile = value;

                    this.BrowserFileChanged();

                    this.OnPropertyChanged("BrowserFile");
                }
            }
        }

        public string ExcelFile
        {
            get { return this.excelFile; }
            private set
            {
                if (this.excelFile != value)
                {
                    this.excelFile = value;

                    this.OnPropertyChanged("ExcelFile");
                }
            }
        }

        public string WordFile
        {
            get { return this.wordFile; }
            private set
            {
                if (this.wordFile != value)
                {
                    this.wordFile = value;

                    this.OnPropertyChanged("WordFile");
                }
            }
        }
        #endregion

        #region Методы
        private void BrowserFileChanged()
        {
            if (this.browserFile.EndsWith(".xls") || this.browserFile.EndsWith(".xlsx"))
            {
                this.ExcelFile = this.browserFile;
                this.WordFile = string.Empty;
            }
            else if (this.browserFile.EndsWith(".doc") || this.browserFile.EndsWith(".docx") || this.browserFile.EndsWith(".rtf") || this.browserFile.EndsWith(".txt"))
            {
                this.ExcelFile = string.Empty;
                this.WordFile = this.browserFile;
            }
            else
            {
                this.ExcelFile = string.Empty;
                this.WordFile = string.Empty;
            }
        }
        #endregion

        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged == null)
                return;
            else
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}
