using FGUI.JTips;
using UnityEngine;
using BingoBrain.Core;
using BingoBrain.HotFix;

namespace BingoBrain
{
    public class JTipsUI : BaseUI
    {
        private JTipsUICtrl ctrl;
        private JTipsModel model;
        private com_Tips ui;

        public JTipsUI(JTipsUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.JTipsUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "JTips";
            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()
        {
            ui?.FadeOut();
        }

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

        protected override void OnOpenBefore(object args)
        {
            if (args is TipsData tipsData)
            {
                ui.wnd_tips.text_tips.text = tipsData.ValueStr;
                ui.wnd_tips.scale = Vector2.zero;
                var show = tipsData.ShowTipsAniTime;
                var stay = tipsData.TipsStayAniTime;
                var vanis = tipsData.TipsVanishTime;
                var dic = tipsData.TipsVanishMoveDic;

                ui.wnd_tips.TweenScale(Vector2.one, tipsData.ShowTipsAniTime);
                IsfvKit.StartAction("sctips", () =>
                {
                    ui.wnd_tips.TweenMoveY(ui.wnd_tips.y - dic, vanis).OnComplete((e) =>
                    {
                        uiCtrlDispatcher.Dispatch(SkinInfo.JTipsUI_Close, tipsData);
                    });
                    DG.Tweening.DOTween.To(() => ui.wnd_tips.alpha, (e) => ui.wnd_tips.alpha = e, 0, vanis);
                }, show + stay);
            }
            else
            {
                CtrlCloseUI();
            }
        }

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

        #endregion
    }
}