using UnityEditor;
using UnityEngine;

namespace Genesis.POISystem.Editor
{
    [CustomEditor(typeof(InteractablePOI), true)]
    public class InteractablePOIEditor : UnityEditor.Editor
    {
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            DrawPropertiesExcluding(serializedObject, "data", "onStartPointingEvent", "onStopPointingEvent", "onSelectedEvent", "onDeselectedEvent", "Is Selected");

            GUILayout.Space(20);

            DrawPOIOptionsBoxGroup();
            DrawInteractablePOIEventsBoxGroup();
            DrawInteractablePOIOptionsBoxGroup();

            serializedObject.ApplyModifiedProperties();
        }

        void DrawPOIOptionsBoxGroup()
        {
            EditorUtilities.DrawTitleBox("POI Options", Color.black, new Color(1.0f, 0.812f, 0.314f));

            GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
            boxStyle.padding = new RectOffset(10, 10, 10, 10);

            EditorGUILayout.BeginVertical(boxStyle);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("data"));

            EditorGUILayout.EndVertical();
        }

        void DrawInteractablePOIEventsBoxGroup()
        {
            EditorUtilities.DrawTitleBox("Interactable POI Events", Color.black, new Color(1.0f, 0.812f, 0.314f));

            GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
            boxStyle.padding = new RectOffset(10, 10, 10, 10);

            EditorGUILayout.BeginVertical(boxStyle);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("onStartPointingEvent"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("onStopPointingEvent"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("onSelectedEvent"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("onDeselectedEvent"));

            EditorGUILayout.EndVertical();
        }

        void DrawInteractablePOIOptionsBoxGroup()
        {
            EditorUtilities.DrawTitleBox("Miscellaneous", Color.black, new Color(1.0f, 0.812f, 0.314f));

            GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
            boxStyle.padding = new RectOffset(10, 10, 10, 10);

            EditorGUILayout.BeginVertical(boxStyle);

            GUI.enabled = false;

            EditorGUILayout.Toggle("Is Selected", ((InteractablePOI)target).IsSelected);

            GUI.enabled = true;

            EditorGUILayout.EndVertical();
        }
    }
}
