
using FGUI.ZM_Common_01;
using UnityEngine;
using FairyGUI;
using IgnoreOPS;
using SGModule.Common.Extensions;

namespace RedHotRoast
{
    public class ChatChooseUI : BaseUI
    {
        private ChatChooseUICtrl ctrl;
        private ChatChooseModel model;
        private FGUI.LG_AIchat.com_chatChoose ui;

        public ChatChooseUI(ChatChooseUICtrl ctrl) : base(ctrl)
        {
            uiName = UIConst.ChatChooseUI;
            this.ctrl = ctrl;
        }

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

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

        protected override void OnClose()
        {
        }

        protected override void OnBind()
        {
            ui = baseUI as FGUI.LG_AIchat.com_chatChoose;
        }

        protected override void OnOpenBefore(object args)
        {
            if (Screen.safeArea.y != 0)
            {
                ui.btn_gold.y += Screen.safeArea.y - 15;
            }
            InitView();
            ui.btn_close.SetClick(() =>
            {
                uiCtrlDispatcher.Dispatch(UICtrlMsg.ChatChooseUI_Close);
            });
            RefreshRed();
            ui.btn_0.SetClick(() =>
            {
                if (DataMgr.IsUnlockChat.Value < 0 && !GameHelper.GetVipPrivilege(Subscription.UnlockAssitant.As<int>()))//未解锁。
                {
                    UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretUnlockUI_Open, 3);
                }
                else
                {
                    if (DataMgr.IsUnlockChat.Value == 0)
                    {
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Open, 3);
                    }
                    else
                    {
                        uiCtrlDispatcher.Dispatch(UICtrlMsg.ChatUI_Open, 0);
                    }
                }
            });


            ui.btn_1.SetClick(() =>
            {
                if (DataMgr.IsUnlockChat.Value < 0 && !GameHelper.GetVipPrivilege(Subscription.UnlockAssitant.As<int>()))//未解锁。
                {
                    UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretUnlockUI_Open, 3);
                }
                else
                {
                    if (DataMgr.IsUnlockChat.Value == 0)
                    {
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Open, 3);
                    }
                    else
                    {
                        uiCtrlDispatcher.Dispatch(UICtrlMsg.ChatUI_Open, 1);
                    }
                }
            });
            ui.btn_2.SetClick(() =>
            {
                if (DataMgr.IsUnlockChat.Value < 0 && !GameHelper.GetVipPrivilege(Subscription.UnlockAssitant.As<int>()))//未解锁。
                {
                    UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SecretUnlockUI_Open, 3);
                }
                else
                {
                    if (DataMgr.IsUnlockChat.Value == 0)
                    {
                        UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.UnlockTipsUI_Open, 3);
                    }
                    else
                    {
                        uiCtrlDispatcher.Dispatch(UICtrlMsg.ChatUI_Open, 2);
                    }
                }
            });
        }
        public void SetTopCurr(object a = null)
        {
            var btn_gold = ui.btn_gold as com_gold;
            btn_gold.text_gold.text = $"{DataMgr.Coin.Value:N0}";



        }
        protected override void OnOpen(object args)
        {
        }

        protected override void OnHide()
        {
        }

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

        #region 消息
        protected override void AddListener()
        {
            GameDispatcher.Instance.AddListener(GameMsg.Gold_refresh, SetTopCurr);
            GameDispatcher.Instance.AddListener(GameMsg.RefreshRedDot, RefreshRed);
        }
        protected override void RemoveListener()
        {
            GameDispatcher.Instance.RemoveListener(GameMsg.Gold_refresh, SetTopCurr);
            GameDispatcher.Instance.RemoveListener(GameMsg.RefreshRedDot, RefreshRed);
        }
        #endregion
        private void RefreshRed(object isShow = null)
        {
            ui.btn_0.red.visible = ChatHelper.GetChatRed(0);
            ui.btn_1.red.visible = ChatHelper.GetChatRed(1);
            ui.btn_2.red.visible = ChatHelper.GetChatRed(2);
        }
        //初始化页面逻辑
        private void InitView()
        {
            SetTopCurr();
        }
    }
}