using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Threading;
using SPC.Kiosk.Base;
using SPC.Kiosk.Common;
using SPC.Kiosk.DataHelper;
using SPC.Kiosk.Popup.Model;

namespace SPC.Kiosk.Popup.ViewModel
{
    public class VmLanguageSelector : PopupViewModelBase
    {
        #region [ Members ]
        private List<M_Language> okButtonText;
        /// <summary>
        /// OK Button Text
        /// </summary>
        public List<M_Language> OkButtonText
        {
            get { return okButtonText; }
            set { okButtonText = value; PropertyChange("OkButtonText"); }
        }
        /// <summary>
        /// OK Click Command
        /// </summary>
        public ICommand OkCommand { get; protected set; }

        private string optionValue813;
        /// <summary>
        /// 다국어 - 영문사용
        /// </summary>
        public string OptionValue813
        {
            get { return optionValue813; }
            set { optionValue813 = value; PropertyChange("OptionValue813"); }
        }

        private string optionValue814;
        /// <summary>
        /// 다국어 - 일어사용
        /// </summary>
        public string OptionValue814
        {
            get { return optionValue814; }
            set { optionValue814 = value; PropertyChange("OptionValue814"); }
        }

        private string optionValue815;
        /// <summary>
        /// 다국어 - 중국어사용
        /// </summary>
        public string OptionValue815
        {
            get { return optionValue815; }
            set { optionValue815 = value; PropertyChange("OptionValue815"); }
        }

        #endregion Members

        #region [ Ctor ]
        /// <summary>
        /// Ctor
        /// </summary>
        public VmLanguageSelector()
        {
            OkCommand = new Command(OkCommandHandler);
            this.PropertyChanged += VmLanguageSelector_PropertyChanged;
            OkButtonText = Languages.GetMessages("BTN0024");
            ShowLanguageType = CommonValue.CommonLanguageType;

            this.GetPosOption();
        }

        private void GetPosOption()
        {
            //PosOption 값 획득
            using (var backDataService = new BackDataService())
            {
                this.OptionValue813 = backDataService.GetPosOption(nameof(PosOptionType.OPT813));
                this.OptionValue814 = backDataService.GetPosOption(nameof(PosOptionType.OPT814));
                this.OptionValue815 = backDataService.GetPosOption(nameof(PosOptionType.OPT815));
            }
        }

        ~VmLanguageSelector()
        {
            this.PropertyChanged -= VmLanguageSelector_PropertyChanged;
        }
        #endregion Ctor

        #region [ Event Handlers ]
        private void OkCommandHandler(object obj)
        {
            TimerEnabled = false;
            ReturnValue = new M_PopupReturn
            {
                OKAnswer = true,
                TimeOut = false,
                ReturnLanguage = ShowLanguageType,
                PopupArgs = null
            };
            CanWindowClose = true;
        }

        private void VmLanguageSelector_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "IsTimeout":
                    if (IsTimeout)
                    {
                        ReturnValue = new M_PopupReturn
                        {
                            OKAnswer = false,
                            TimeOut = true,
                            ReturnLanguage = ShowLanguageType,
                            PopupArgs = null
                        };
                        CanWindowClose = true;
                    }
                    break;
            }
        }

        #endregion Event Handlers
    }
}