using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using System.Linq;

namespace SimplifyXR
{
    public class NonXRPanelConfiguration : IXRPanelConfig

    {
        public NonXRPanelConfiguration() { }

        public XRCompatibility Compatibility()
        {
            return XRCompatibility.none;
        }

        public void RemoveConfiguration(GameObject parent, XRPanelType panelType) { }

        public void RemoveConfiguration(List<Button> buttons)
        {        }

        public void SetupConfiguration(GameObject parent, XRPanelType panelType)
        {

            //Ensure only one event system and input module are in the scene

            var inputModules = GameObject.FindObjectsOfType<StandaloneInputModule>(true);
            if (inputModules.Length > 0) inputModules.ToList().ForEach(im => MonoBehaviour.DestroyImmediate(im));

            var eventSystems = GameObject.FindObjectsOfType<EventSystem>(true);
            if (eventSystems.Length > 0) eventSystems.ToList().ForEach(ev => MonoBehaviour.DestroyImmediate(ev)); 

            var eventSystem = parent.GetComponentInChildren<EventSystem>();
            if (!eventSystem) eventSystem = parent.transform.Find("EventSystem").gameObject.AddComponent<EventSystem>();
         
            eventSystem.gameObject.GetOrAddNewComponent<StandaloneInputModule>();
        }

        public void SetupConfiguration(List<Button> buttons)
        {
        }
    }
}


