namespace ScrewsMaster
{
    using DG.Tweening;
    using UnityEngine;
    using FGUI.SC001_Tips;

    public class JoastUI : BaseUI
    {
        private JoastUICtrl ctrl;
        private JoastModel model;
        private FGUI.SC001_Tips.com_Tips ui;

        public JoastUI(JoastUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.JoastUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "SC001_Tips";
            uiInfo.assetName = "com_Tips";
            uiInfo.layerType = UILayerType.Tips;
            uiInfo.isNeedOpenAnim = false;
            uiInfo.isNeedCloseAnim = false;
            uiInfo.isNeedUIMask = false;
        }

        #region 生命周期

        protected override void OnInit()
        {
        }

        protected override void OnClose()
        {
            CommonHelper.FadeOut(ui);
        }

        protected override void OnBind()
        {
            ui = baseUI as com_Tips;
        }

        protected override void OnOpenBefore(object args)
        {
            JoastData joastData = args as JoastData;
            if (joastData != default)
            {
                ui.wnd_tips.text_tips.text = joastData.ValueStr;
                ui.wnd_tips.scale = Vector2.zero;
                float show = joastData.ShowTipsAniTime;
                float stay = joastData.TipsStayAniTime;
                float vanis = joastData.TipsVanishTime;
                int dic = joastData.TipsVanishMoveDic;

                ui.wnd_tips.TweenScale(Vector2.one, joastData.ShowTipsAniTime);
                DOVirtual.DelayedCall(show + stay, () =>
                {
                    ui.wnd_tips.TweenMoveY(ui.wnd_tips.y - dic, vanis).OnComplete((e) =>
                    {
                        uiCtrlDispatcher.Dispatch(UICtrlMsg.SCTipsUI_Close, joastData);
                    });
                    DG.Tweening.DOTween.To(() => ui.wnd_tips.alpha, (e) => ui.wnd_tips.alpha = e, 0, vanis);
                });
            }
            else
            {
                CtrlCloseUI();
            }
        }

        protected override void OnOpen(object args)
        {
            CommonHelper.FadeIn(ui);
        }

        #endregion
    }
}