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.Popup.Model;
namespace SPC.Kiosk.Popup.ViewModel
{
    /// <summary>
    /// CallEmployee.xaml 의 ViewModel
    /// </summary>
    public class VmCallEmployee : PopupViewModelBase
    {
        #region [ Members ]
        private List<M_Language> messageText = null;
        /// <summary>
        /// Message Text
        /// </summary>
        public List<M_Language> MessageText
        {
            get { return messageText; }
            set { messageText = value; PropertyChange("MessageText"); }
        }
        private List<M_Language> infomationText = null;
        /// <summary>
        /// Infomation Text
        /// </summary>
        public List<M_Language> InfomationText
        {
            get { return infomationText; }
            set { infomationText = value; PropertyChange("InfomationText"); }
        }

        private bool isCallEmployeeOK = false;
        /// <summary>
        /// Is Call Employee Process OK 
        /// </summary>
        public bool IsCallEmployeeOK
        {
            get { return isCallEmployeeOK; }
            set { isCallEmployeeOK = value; PropertyChange("IsCallEmployeeOK"); }
        }
        private List<M_Language> cancelButtonText;
        /// <summary>
        /// Cancel Button Text
        /// </summary>
        public List<M_Language> CancelButtonText
        {
            get { return cancelButtonText; }
            set { cancelButtonText = value; PropertyChange("CancelButtonText"); }
        }
        private List<M_Language> okButtonText;
        /// <summary>
        /// OK Button Text
        /// </summary>
        public List<M_Language> OkButtonText
        {
            get { return okButtonText; }
            set { okButtonText = value; PropertyChange("OkButtonText"); }
        }
        private double okButtonWidth=650d;
        /// <summary>
        /// OK Button Width
        /// </summary>
        public double OkButtonWidth
        {
            get { return okButtonWidth; }
            set { okButtonWidth = value; PropertyChange("OkButtonWidth"); }
        }
        private double cancelButtonWidth = 650d;
        /// <summary>
        /// Cancel Button Visible
        /// </summary>
        public double CancelButtonWidth
        {
            get { return cancelButtonWidth; }
            set { cancelButtonWidth = value; PropertyChange("CancelButtonWidth"); }
        }
        private string callImage;
        /// <summary>
        /// Call Image Enabled (On Error Enabled False)
        /// </summary>
        public string CallImage
        {
            get { return callImage; }
            set { callImage = value; PropertyChange("CallImage"); }
        }
        private double popupWidth=1300d;
        /// <summary>
        /// Popup Whidth (For Calculate OK Button Width)
        /// </summary>
        public double PopupWidth
        {
            get { return popupWidth; }
            set { popupWidth = value; PropertyChange("PopupWidth"); }
        }
        /// <summary>
        /// OK Click Command
        /// </summary>
        public ICommand OkCommand { get; protected set; }
        /// <summary>
        /// Cancel Click Command
        /// </summary>
        public ICommand CancelCommand { get; protected set; }

        #endregion Members

        #region [ Ctor ]
        /// <summary>
        /// Ctor
        /// </summary>
        public VmCallEmployee()
        {
            OkCommand = new Command(OkCommandHandler);
            CancelCommand = new Command(CancelCommandHandler);
            this.PropertyChanged += VmCallEmployee_PropertyChanged;
            ShowLanguageType = CommonValue.CommonLanguageType;
            CallImage = ResourceManager.GetNximagePathAdd("ic_alert_help.png", CommonValue.PBdesignImagesPath);
            MessageText = Languages.GetMessages("LBL0102");
            InfomationText = new List<M_Language>();
            OkButtonText = Languages.GetMessages("BTN0005");
            CancelButtonText = Languages.GetMessages("BTN0021");
        }
        ~VmCallEmployee()
        {
            this.PropertyChanged -= VmCallEmployee_PropertyChanged;
        }
        #endregion Ctor

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

        private void OkCommandHandler(object obj)
        {
            TimerEnabled = false;
            if (IsCallEmployeeOK)
            {
                ReturnValue = new M_PopupReturn
                {
                    OKAnswer = true,
                    TimeOut = false,
                    ReturnLanguage = ShowLanguageType,
                    PopupArgs = null
                };
                CanWindowClose = true;
            }
            else
            {
                IsCallEmployeeOK = true;
            }
        }

        private void VmCallEmployee_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;
                case "IsCallEmployeeOK":
                    if (IsCallEmployeeOK)
                    {
                        CallImage = ResourceManager.GetNximagePathAdd("ic_alert_check.png", CommonValue.PBdesignImagesPath);
                        MessageText = Languages.GetMessages("LBL0101");
                        InfomationText = new List<M_Language>();
                        OkButtonWidth =PopupWidth;
                        CancelButtonWidth =  0;
                        OkButtonText = Languages.GetMessages("BTN0039");
                    }
                    break;
            }
        }

        #endregion Event Handlers
    }
}