using System;
using DG.Tweening;
using FGUI.GameResult_08;
using UnityEngine;

namespace ChillConnect
{
    public class GameAgainUI : BaseUI
    {
        private GameAgainUICtrl ctrl;
        private GameAgainModel model;
        private com_arrow_end_again ui;
        
        private Action closeCallback;
        

        public GameAgainUI(GameAgainUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.GameAgainUI;
            this.ctrl = ctrl;
        }

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

        #region 生命周期

        protected override void OnInit()
        {
            //model = ModuleManager.Instance.GetModel(ModelConst.GameResultModel) as GameResultModel;
        }

        protected override void OnClose()
        {

        }
        //
        protected override void OnBind()
        {
            ui = baseUI as com_arrow_end_again;
        }
        private SuccessData successData_;

        protected override void OnOpenBefore(object args)
        {
            
            ui.btn_revive.SetClick(() =>
            {
                float[] cash_array = GameHelper.GetRewardValue(2);
                
                var temp = new SuccessData();
                temp.IsWin = false;
                temp.cash_number = cash_array[0];
                temp.IsLevelSuccess = true;
                temp.IsH5Reward = false;
                temp.boost_array = GameHelper.GetRewardBoost(2);
                DOVirtual.DelayedCall(0.1f, () =>
                {
                    UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.LevelSuccessUI_Open, temp);
                });
                CtrlCloseUI();
            });
            
            ui.btn_restart.SetClick(() =>
            {
                GameDispatcher.Instance.Dispatch(GameMsg.reset_game, false);
                CtrlCloseUI();

            });
            
            ui.btn_back.SetClick(() =>
            {
                
                GameDispatcher.Instance.Dispatch(GameMsg.reset_game, false);
                CtrlCloseUI();
            });
        }
        
        protected override void OnOpen(object args)
        {
        }

        protected override void OnHide()
        {
        }

        protected override void OnDisplay(object args)
        {
        }
        #endregion

        #region 消息
        protected override void AddListener()
        {
        }
        protected override void RemoveListener()
        {
        }
        #endregion
        private int time_count;
       
    }
}
