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 VmMiniPopup : PopupViewModelBase
    {
        #region [ Members ]
        private M_MiniPopup miniPopup;
        /// <summary>
        /// Parameters
        /// </summary>
        public M_MiniPopup MiniPopup
        {
            get { return miniPopup; }
            set { miniPopup = value; PropertyChange("MiniPopup"); }
        }

        private string iconNoramlBrush = string.Empty;
        /// <summary>
        /// Message Text
        /// </summary>
        public string IconNoramlBrush
        {
            get { return iconNoramlBrush; }
            set { iconNoramlBrush = value; PropertyChange("IconNoramlBrush"); }
        }
        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> subMessageText = null;
        /// <summary>
        /// SubMessage Text
        /// </summary>
        public List<M_Language> SubMessageText
        {
            get { return subMessageText; }
            set { subMessageText = value; PropertyChange("SubMessageText"); }
        }
        
        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 = 400d;
        /// <summary>
        /// OK Button Width
        /// </summary>
        public double OkButtonWidth
        {
            get { return okButtonWidth; }
            set { okButtonWidth = value; PropertyChange("OkButtonWidth"); }
        }
        private double cancelButtonWidth = 400d;
        /// <summary>
        /// OK Button Width
        /// </summary>
        public double CancelButtonWidth
        {
            get { return cancelButtonWidth; }
            set { cancelButtonWidth = value; PropertyChange("CancelButtonWidth"); }
        }
        /// <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 VmMiniPopup()
        {
            OkCommand = new Command(OkCommandHandler);
            CancelCommand = new Command(CancelCommandHandler);
            this.PropertyChanged += VmMiniPopup_PropertyChanged;
        }
        ~VmMiniPopup()
        {
            this.PropertyChanged -= VmMiniPopup_PropertyChanged;
        }
        #endregion Ctor

        #region [ Methods ]
        private void SetMiniPopup()
        {
            if (MiniPopup is M_MiniPopup)
            {
                ShowLanguageType = MiniPopup.DisplayLanguage;
                MessageText = MiniPopup.Message;
                SubMessageText = MiniPopup.SubMessage;
                OkButtonText = MiniPopup.OkButtonText;
                CancelButtonText = MiniPopup.CencalButtonText;
                TimeOutSeconds = MiniPopup.TimeoutSeconds;
                IsTimeoutPopup = MiniPopup.IsTimeoutPopup;
                var iconBrush = "Transparent";
                switch (MiniPopup.Icon)
                {
                    case MiniPopupIcon.Cancel:
                        iconBrush = ResourceManager.GetNximagePathAdd("ic_alert_cancel.png", CommonValue.PBdesignImagesPath);
                        break;
                    case MiniPopupIcon.Delete:
                        iconBrush = ResourceManager.GetNximagePathAdd("ic_alert_delete.png", CommonValue.PBdesignImagesPath);
                        break;
                    case MiniPopupIcon.ListCancel:
                        iconBrush = ResourceManager.GetNximagePathAdd("ic_alert_listcancel.png", CommonValue.PBdesignImagesPath);
                        break;
                    case MiniPopupIcon.DiscountCancel:
                        iconBrush = ResourceManager.GetNximagePathAdd("ic_alert_discountcancel.png", CommonValue.PBdesignImagesPath);
                        break;
                    case MiniPopupIcon.GiftCancel:
                        iconBrush = ResourceManager.GetNximagePathAdd("ic_alert_giftcancel.png", CommonValue.PBdesignImagesPath);
                        break;
                    case MiniPopupIcon.OrderCancel:
                        iconBrush = ResourceManager.GetNximagePathAdd("ic_alert_ordercancel.png", CommonValue.PBdesignImagesPath);
                        break;
                    case MiniPopupIcon.AddCoupon:
                        iconBrush = ResourceManager.GetNximagePathAdd("ic_alert_coupon.png", CommonValue.PBdesignImagesPath);
                        break;
                    case MiniPopupIcon.Payment:
                        iconBrush = ResourceManager.GetNximagePathAdd("ic_alert_payment.png", CommonValue.PBdesignImagesPath);
                        break;
                    default:
                        iconBrush = "Transparent";
                        break;
                }
                IconNoramlBrush = iconBrush;
                if (!MiniPopup.IsCencalButton)
                {
                    OkButtonWidth = 800d;
                    CancelButtonWidth = 0d;
                }
                else
                {
                    OkButtonWidth = 400d;
                    CancelButtonWidth = 400d;
                }
            }
        }
        #endregion Methods

        #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;
            
            ReturnValue = new M_PopupReturn
            {
                OKAnswer = true,
                TimeOut = false,
                ReturnLanguage = ShowLanguageType,
                PopupArgs = null
            };
            CanWindowClose = true;                
            
        }

        private void VmMiniPopup_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 "MiniPopup":
                    SetMiniPopup();
                    break;
            }
        }


        #endregion Event Handlers
    }
}