using BingoBrain.Core;
using UnityEngine;
using BingoBrain.Asset;
using BingoBrain.HotFix;
using Unity.VisualScripting;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace BingoBrain
{
    public class BingoScene : BaseScene
    {
        public override int SceneIdx => 0;


        protected override void OnEnter()
        {
        }

        protected override void OnLeave()
        {
        }

        protected override void OnSwhSceCompl(object param = null)
        {
            StartUpAppProcess();
        }

        private void StartUpAppProcess()
        {
            Debug.Log("[ BingoBrain ] [ MainScene ] Start Up App Process");

            // 初始化资源
            OnPermanentAssetsInitComplete();
        }

        private void OnPermanentAssetsInitComplete(object param = null)
        {
            CtrlDispatcher.Instance.AddListener(CtrlMsg.Login_Succeed, OnLoginSucceed);
            // #if !UNITY_EDITOR && UNITY_ANDROID
                         MaxADKit.Init();
                         Debug.Log("init");
            // #endif
            OnInitAsset();
            AppDispatcher.Instance.AddListener(CsjInfoC.UI_LoadingInitAsset, OnInitAsset);
        }

        private void OnLoginSucceed(object param = null)
        {
            CtrlDispatcher.Instance.RemoveListener(CtrlMsg.Login_Succeed, OnLoginSucceed);
        }

        private void OnInitAsset(object param = null)
        {
            AppDispatcher.Instance.Dispatch(CsjInfoC.AppManagerRegister);
            AppDispatcher.Instance.Dispatch(CsjInfoC.InitUIMgr);
            AppDispatcher.Instance.AddListener(CsjInfoC.LoginInit, OnLoadingComplete);
            PreferencesMgr.Instance.InitPreferences();
            NetworkDispatcher.Instance.Dispatch(ExternalInfo.GetConfig);//quxiaozhushi
            NetworkDispatcher.Instance.AddListener(NetworkMsg.Start,ShowScene);//quxiaozhushi
        }

        private void OnLoadingComplete(object param = null)
        {
            CtrlDispatcher.Instance.Dispatch(CtrlMsg.Game_StartReady);
            TimerHelper.mEasy.AddTimer(0.1f, () =>
            {
                Audio.Instance.InitDefaultButtonClickSound(DoConst.UIButtonDefault);
                ModuleBoardk.Instance.AllModuleGameStart();
                ShowScene();
                SaveingPotHelper.CheckSaveingPot();
                SaveingPotHelper.TestingClearTime();
                // HideLoadingUI();
            });
        }

        private void ShowScene(object a = null)
        {
            UICtrlDispatcher.Instance.Dispatch(SkinInfo.EnterBingoUI_Open);
            GameHelper.PostFunnelLogin("enterButtonShow");
        }

        public override void Dispose()
        {
        }
    }
}