using UnityEngine;
using BingoBrain.Asset;
using UnityEngine.EventSystems;

namespace BingoBrain.Core
{
    public class PinPon : MonoBehaviour
    {
        public static PinPon Instance { get; private set; }

        [HideInInspector] public GameObject eventObj;
        [HideInInspector] public EventSystem eventSystem;
        [HideInInspector] public StandaloneInputModule inputModule;

        private void Awake()
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);

            Init();
        }

        private void OnDestroy()
        {
            Instance = null;
        }

        private void Init()
        {
            BetKit.Instance.LoadGameObjectAndClone("Prefab", "EngineEventSystem", eventObj1 =>
            {
                eventObj = eventObj1;
                eventObj.transform.SetParent(transform, false);
                eventSystem = eventObj.GetComponent<EventSystem>();
                inputModule = eventObj.GetComponent<StandaloneInputModule>();
                OCConst.EngineEventSystemGo = PinPon.Instance.eventObj.transform.parent.gameObject;
                OCConst.EngineEventSystemGo.name = OCConst.EngineEventSystemGoName;
                UI.Instance.SetEventSystemGo(eventObj);
            });
        }
    }
}