using FGUI.ZM_Common_01;
using UnityEngine;
using FairyGUI;
using SGModule.NetKit;

namespace RedHotRoast
{
    public class UnlockTipsUI : BaseUI
    {
        private UnlockTipsUICtrl ctrl;
        private UnlockTipsModel model;
        private FGUI.ZM_Toast_23.com_unclok_tips ui;

        public UnlockTipsUI(UnlockTipsUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.UnlockTipsUI;
            this.ctrl = ctrl;
        }

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

        #region 生命周期

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

        protected override void OnClose()
        {
        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.ZM_Toast_23.com_unclok_tips;
        }

        private int _type = 0;
        protected override void OnOpenBefore(object args)
        {
            if (args == null)
            {
                return;
            }
            _type = (int)args;
            string key = null;
            if (_type == 1) key = "unlocked_secret";
            else if (_type == 2) key = "unlocked_live";
            else if (_type == 3) key = "unlocked_assitant";

            ui.text_tips.text = Language.GetContent(key);;

            if (_type == 1)
            {
                if (DataMgr.IsUnlockSecret.Value == 0)
                {
                    DataMgr.IsUnlockSecret.Value = 1;
                }
            }
            else if (_type == 2)
            {
                if (DataMgr.IsUnlockLive.Value == 0)
                {
                    DataMgr.IsUnlockLive.Value = 1;
                }
            }
            else if (_type == 3)
            {
                if (DataMgr.IsUnlockChat.Value == 0)
                {
                    DataMgr.IsUnlockChat.Value = 1;
                }
            }
            string event_type = null;
            if (_type == 1) event_type = ADEventTrack.Property.secret_albums_unclock;
            else if (_type == 2) event_type = ADEventTrack.Property.live_unclock;
            else if (_type == 3) event_type = ADEventTrack.Property.chat_unclock;
            TrackKit.SendEvent(ADEventTrack.Special, event_type);

            InitView();
        }

        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_go.SetClick(OnClick);
            ui.btn_close.SetClick(OnClick);
        }

        private void OnClick()
        {
            if (_type == 1)
            {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretAlbumsUI_Open);
            }
            else if (_type == 2)
            {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.LiveUI_Open);
            }
            else if (_type == 3)
            {
                UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.ChatChooseUI_Open);
            }
            UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Close);
        }
    }
}