
using BingoBrain.Core;
using BingoBrain.HotFix;
using UnityEngine;

namespace BingoBrain
{
    public class RecordViewUICtrl : BaseUICtrl
    {
        public RecordViewUI ui;
        public RecordViewModel model;

        private uint openUIMsg = SkinInfo.RecordViewUI_Open;
        private uint closeUIMsg = SkinInfo.RecordViewUI_Close;

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

        protected override void OnDispose()
        {
        }

        public override void OpenUI(object args = null)
        {
            if (ui == null)
            {
                ui = new RecordViewUI(this);
                ui.Open(args);
            }
        }

        public override void CloseUI(object args = null)
        {
            if (ui != null && !ui.isClose)
            {
                ui.Close();
            }
            ui = null;
        }
        #endregion

        #region 消息
        public override uint GetOpenUIMsg(string uiName)
        {
            return openUIMsg;
        }
        public override uint GetCloseUIMsg(string uiName)
        {
            return closeUIMsg;
        }

        protected override void AddListener()
        {
            uiCtrlDispatcher.AddListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.AddListener(closeUIMsg, CloseUI);
            GameDispatcher.Instance.AddListener(BingoInfo.updateRecordList, RefreshList);
        }
        protected override void RemoveListener()
        {
            uiCtrlDispatcher.RemoveListener(openUIMsg, OpenUI);
            uiCtrlDispatcher.RemoveListener(closeUIMsg, CloseUI);
            GameDispatcher.Instance.RemoveListener(BingoInfo.updateRecordList, RefreshList);
        }
        void RefreshList(object args = null)
        {
            Debug.Log("????????????????0");
              Debug.Log(args);
                 Debug.Log(model);
                        Debug.Log(model.recordList);
            if (args == null || model.recordList == null) return;
Debug.Log("????????????????1");
            if (model.recordList.Count >= 9)
            {
                model.recordList.RemoveAt(0);

            }
            model.recordList.Add(args.ToString());

            ui?.UpdateRecord();

        }
        protected override void AddServerListener()
        {

        }
        protected override void RemoveServerListener()
        {

        }
        #endregion
    }
}