using System.Collections.Generic;
using DG.Tweening;

namespace ChillConnect
{
    public class RewardAniUICtrl : BaseUICtrl
    {
        private RewardAniModel model;

        private uint openUIMsg = UICtrlMsg.RewardAniUI_Open;
        private uint closeUIMsg = UICtrlMsg.RewardAniUI_Close;

        #region 生命周期

        protected override void OnInit()
        {

        }

        protected override void OnDispose()
        {
        }

        private Queue<RewardAniUI> removeList = new Queue<RewardAniUI>();

        public override void OpenUI(object args = null)
        {
            if (removeList.Count > 0)
            {
                DOVirtual.DelayedCall(3f, () =>
                {
                    if (removeList.Count > 0)
                    {
                        var tmpUI = removeList.Peek();
                        tmpUI?.CtrlCloseUI();
                    }
                });
            }

            var rewardAniUI = new RewardAniUI(this);
            rewardAniUI.Open(args);
            removeList.Enqueue(rewardAniUI);
        }

        public override void CloseUI(object args = null)
        {
            if (removeList.Count > 0)
            {
                var tmpUI = removeList.Dequeue();
                if (tmpUI != null && !tmpUI.isClose)
                {
                    tmpUI.Close();
                }
            }
        }

        #endregion

        #region 消息

        public override uint GetOpenUIMsg(string uiName)
        {
            return openUIMsg;
        }

        public override uint GetCloseUIMsg(string uiName)
        {
            return closeUIMsg;
        }

        protected override void AddListener()
        {
            uiCtrlDispatcher.AddListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.AddListener(closeUIMsg, CloseUI);
        }

        protected override void RemoveListener()
        {
            uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
        }

        protected override void AddServerListener()
        {

        }

        protected override void RemoveServerListener()
        {

        }

        #endregion


    }
}