
using FGUI.tixian;
using IgnoreOPS;

namespace ChillConnect
{
    public class RedeemCodeUI : BaseUI
    {
        private RedeemCodeUICtrl ctrl;
        private RedeemCodeModel model;
        private com_redeem_code ui;

        public RedeemCodeUI(RedeemCodeUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.RedeemCodeUI;
            this.ctrl = ctrl;
        }

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

        #region 生命周期

        protected override void OnInit()
        {
        }

        protected override void OnClose()
        {
            GameDispatcher.Instance.Dispatch(GameMsg.StopArrowTouch, true);
        }

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

        protected override void OnOpenBefore(object args)
        {
            GameDispatcher.Instance.Dispatch(GameMsg.StopArrowTouch, false);
            
            InitView();
        }
        
        protected override void OnOpen(object args)
        {
        }

        #endregion


        private void InitView()
        {
            ui.lab_mn2.text = GameHelper.Get101Str(0);
            
            ui.lab_ticket.text = GameHelper.GetPriceInt(SaveData.GetSaveObject().PettyAmount);

            var strings = ConfigSystem.GetConfig<CommonModel>().X_Redeemcode;
            ui.lab_code.text = strings;
            
            ui.btn_copy.SetClick(() =>
            {
                GameHelper.CopyText(ui.lab_code.text);
            });
            
            ui.btn_contact_us.SetClick(() =>
            {
                SDKOpenConfig openConfig = new SDKOpenConfig
                {
                    normal = false,
                    url = ConfigSystem.GetConfig<CommonModel>().X_ShopURL
                };

                CtrlDispatcher.Instance.Dispatch(CtrlMsg.open_wb, openConfig);
                CtrlCloseUI();
            });
            
            ui.btn_close1.SetClick(CtrlCloseUI);
            

        }
        #region 消息

        protected override void AddListener()
        {

        }

        protected override void RemoveListener()
        {
      
        }

        #endregion
    }
}
