using SGModule.NetKit;

namespace RedHotRoast
{
    public class SecretUnlockUI : BaseUI
    {
        private SecretUnlockUICtrl ctrl;
        private SecretUnlockModel model;
        private FGUI.LG_Unlock.com_unlockView ui;

        public SecretUnlockUI(SecretUnlockUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.SecretUnlockUI;
            this.ctrl = ctrl;
        }

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

        #region 生命周期
        protected override void OnInit()
        {
            //model = ModuleManager.Instance.GetModel(ModelConst.SecretUnlockModel) as SecretUnlockModel;
        }

        protected override void OnClose()
        {
        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.LG_Unlock.com_unlockView;
        }

        protected override void OnOpenBefore(object args)
        {
            if (args != null)
            {
                type = (int)args;
            }
            InitView();
        }
        private int type = 1;
        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 void InitView()
        {
            ui.btn_close.SetClick(CtrlCloseUI);
            if (type == 1)
            {
                TrackKit.SendEvent(ADEventTrack.SecretAlbums, ADEventTrack.Property.secret_unlock);
                var unlockData = ConfigSystem.GetCommonConf().UnlockSecret;
                ui.text_coin.SetVar("coin", unlockData[0].ToString()).FlushVars();
                ui.text_level.SetVar("lv", unlockData[1].ToString()).FlushVars();
                ui.btn_gold.title = unlockData[0].ToString();
                //金币
                ui.btn_gold.SetClick(() =>
                {
                    if (GameHelper.Get101() < unlockData[0])
                    {
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open, true);
                    }
                    else
                    {
                        DataMgr.IsUnlockSecret.Value = 0;
                        DataMgr.Coin.Value -= unlockData[0];

                        GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
                        GameDispatcher.Instance.Dispatch(GameMsg.Update101);

                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretAlbumsUI_Open);
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Open, 1);
                        TrackKit.SendEvent(ADEventTrack.SecretAlbums, ADEventTrack.Property.secret_coin);
                        GameHelper.ShowTips("unlock_secret", true);
                    }
                    CtrlCloseUI();

                });

            }
            else if (type == 2)
            {
                var unlockData = ConfigSystem.GetCommonConf().UnlockLive;
                ui.text_coin.SetVar("coin", unlockData[0].ToString()).FlushVars();
                ui.text_level.SetVar("lv", unlockData[1].ToString()).FlushVars();
                ui.btn_gold.title = unlockData[0].ToString();
                //金币
                ui.btn_gold.SetClick(() =>
                {
                    if (GameHelper.Get101() < unlockData[0])
                    {
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open, true);
                    }
                    else
                    {
                        DataMgr.IsUnlockLive.Value = 0;
                        DataMgr.Coin.Value -= unlockData[0];
                        GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
                        GameDispatcher.Instance.Dispatch(GameMsg.Update101);
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Open, 2);
                        TrackKit.SendEvent(ADEventTrack.Live, ADEventTrack.Property.live_coin);
                        GameHelper.ShowTips("unlock_live", true);
                    }
                    CtrlCloseUI();

                });
            }
            else if (type == 3)//聊天
            {
                ui.type.selectedIndex = 1;


                int unlockData = ConfigSystem.GetCommonConf().UnlockAIAssistant;//xiugai
                ui.text_coin.SetVar("coin", unlockData.ToString()).FlushVars();
                // ui.text_level.SetVar("lv", unlockData[1].ToString()).FlushVars();
                ui.btn_gold.title = unlockData.ToString();
                //金币
                ui.btn_gold.SetClick(() =>
                {
                    if (GameHelper.Get101() < unlockData)
                    {
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.BuygoldUI_Open, true);
                    }
                    else
                    {
                        DataMgr.IsUnlockChat.Value = 0;
                        DataMgr.Coin.Value -= unlockData;
                        GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh);
                        GameDispatcher.Instance.Dispatch(GameMsg.Update101);
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Open, 3);

                        TrackKit.SendEvent(ADEventTrack.Chat, ADEventTrack.Property.chat_coin);

                        GameHelper.ShowTips("unlocked_assitant", true);
                    }
                    CtrlCloseUI();

                });

            }
            //订阅
            ui.btn_subscribe.SetClick(() =>
            {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.VipClubViewUI_Open);
                CtrlCloseUI();
                string event_type = "";
                string event_name = "";
                // string event_type_1 = "";
                if (type == 1)
                {
                    event_type = ADEventTrack.SecretAlbums;
                    event_name = ADEventTrack.Property.secret_sub;
                }
                else if (type == 2)
                {
                    event_type = ADEventTrack.Live;
                    event_name = ADEventTrack.Property.live_sub;
                }
                else if (type == 3)
                {
                    event_type = ADEventTrack.Chat;
                    event_name = ADEventTrack.Property.chat_sub;
                }

                TrackKit.SendEvent(event_type, event_name);



            });

            //闯关
            ui.btn_play.SetClick(() =>
            {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.LiveUI_Close);
                GameDispatcher.Instance.Dispatch(GameMsg.OpenGame);
                if (type == 1) TrackKit.SendEvent(ADEventTrack.SecretAlbums, ADEventTrack.Property.secret_play);
                else TrackKit.SendEvent(ADEventTrack.Live, ADEventTrack.Property.live_play);
                CtrlCloseUI();
            });
        }
    }
}
