using FairyGUI;
using BingoBrain.Core;
using FGUI.JBingoPlay;

namespace BingoBrain
{
    public class MoreCardUI : BaseUI
    {
        private MoreCardUICtrl ctrl;
        private MoreCardModel model;
        private FGUI.JBingoPlay.com_morecard ui;

        public MoreCardUI(MoreCardUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.MoreCardUI;
            this.ctrl = ctrl;
        }

        protected override void SetUIInfo(UIInfo uiInfo)
        {
            uiInfo.packageName = "JBingoPlay";
            uiInfo.assetName = "com_morecard";
            uiInfo.layerType = UILayerType.Popup;
            uiInfo.isNeedOpenAnim = true;
            uiInfo.isNeedCloseAnim = true;
            uiInfo.isNeedUIMask = true;
        }

        #region 生命周期

        protected override void OnInit()
        {
            model = ModuleBoardk.GetModel(ModelConst.MoreCardModel) as MoreCardModel;
        }

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

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

        protected override void OnOpenBefore(object args)
        {
            ui.btn_more.onClick.Set(BuyBtn);
            ui.closeButton.onClick.Set(CtrlCloseUI);
            Audio.Instance.PlayDynamicEffect("pop_open");
        }

        private void BuyBtn(EventContext context)
        {
            GameHelper.GetVideo(model.VO.key, (isSuccess) =>
            {
                if (isSuccess)
                {
                    GameHelper.GetRewardOnly(model.VO.reward, model.VO.rewardAmount, RewardOrigin.MoreCard);
                    CtrlCloseUI();
                }
            });
        }

        protected override void OnOpen(object args)
        {
            ui?.FadeIn();
            GameHelper.DelayedShowGObject(this, ui.closeButton);
        }

        #endregion
    }
}