using System.Collections;
using GHZLangChao;
using Blue;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;

public class ChooseManager : MonoBehaviour,IController
{
    public bool Test = false;
    [SerializeField] private GameObject Tip;
    [SerializeField] private GameObject ShowDevice => SceneIOCContainer.Instance.Pull("ShowDevice") as GameObject;
    [SerializeField] private Toggle ShowHide_Toggle;

    public UnityEvent OnReset = new UnityEvent();
    private IQueueSystem mQueueSystem;
    void Awake()
    {

#if UNITY_EDITOR
        Test = true;
#endif
        // transform.localPosition = new Vector3(0,0,500f);
        Invoke("ControlTip",3);
        ShowDevice.SetActive(true);

        ShowHide_Toggle.onValueChanged.AddListener(ShowHideLevel3);
        mQueueSystem = this.GetService<IQueueSystem>();
        mQueueSystem.Level3QueueCount.Register(mQueueSystemCountNotNull).UnRegisterWhenGameObjectDestroyed(gameObject);

        SceneIOCContainer.Instance.Push("ShowChoose",gameObject);
    }

    public void GotoXunJian()
    {
        ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowXunJian);
    }
    public void GetInspectionInfo()
    {
        this.GetService<IInspectionService>().Get();
    }

    public void GotoSupport()
    {
        Debug.Log("DGJ   =====>GotoSupport ");
        ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowRTC);

        BladeServerManager.Instance.isDaoHang = true;
        WayFindingManager.Instance.CloseWayFind();
    }

    public void GotoNav()
    {
        Debug.Log("=====>GotoNav ");
        ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowXunJian);
        ShowXunJian.Instance.gotoWindow(ScenesManager.SceneType.ShowDH);

        BladeServerManager.Instance.isDaoHang = true;
    }

    private void ControlTip()
    {
        Tip.SetActive(false);
    }

    private void OnEnable()
    {
        if(mQueueSystem.Level3QueueCount.Value>0)
            ShowHide_Toggle.interactable = true;
        Debug.Log($"打开的数量:{mQueueSystem.Level3QueueCount.Value}");

        //OnReset?.Invoke();
        /*
        transform.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
        Vector3 pos = OpenXRCamera.Instance.head.position+ OpenXRCamera.Instance.head.forward * 2.5f;
        transform.position = new Vector3(pos.x, 0.5f, pos.z);
        */
        Debug.Log("DGJ  =======> " +transform.position);

        BladeServerManager.Instance.isDaoHang = false;

    }

    private void Update()
    {
        if (Test) return;
#if UNITY_EDITOR
            return;
#endif
        OnReset?.Invoke();
    }
    private void ShowHideLevel3(bool on)
    {
        Debug.Log("Level3Queue:"+mQueueSystem.Level3List.Count);
        foreach(var go in mQueueSystem.Level3List)
        {
            go.SetActive(!on);
        }
    }

    #region 事件监听
    private void mQueueSystemCountNotNull(int newCount)
    {
        if(newCount>0)
            ShowHide_Toggle.interactable = true;
        Debug.Log($"打开的数量:{mQueueSystem.Level3QueueCount.Value}");
    }
    #endregion
}