// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.﻿

using Microsoft.MixedReality.Toolkit.Utilities.Editor;
using UnityEditor;

namespace Microsoft.MixedReality.Toolkit.Teleport.Editor
{
    [CustomEditor(typeof(TeleportPointer))]
    public class TeleportPointerInspector : LinePointerInspector
    {
        private SerializedProperty hotSpotCursorVisibility;
        private SerializedProperty teleportAction;
        private SerializedProperty inputThreshold;
        private SerializedProperty angleOffset;
        private SerializedProperty teleportActivationAngle;
        private SerializedProperty rotateActivationAngle;
        private SerializedProperty rotationAmount;
        private SerializedProperty backStrafeActivationAngle;
        private SerializedProperty strafeAmount;
        private SerializedProperty checkForFloorOnStrafe;
        private SerializedProperty adjustHeightOnStrafe;
        private SerializedProperty maxHeightChangeOnStrafe;
        private SerializedProperty upDirectionThreshold;
        private SerializedProperty lineColorHotSpot;
        private SerializedProperty teleportLayerMasks;
        private SerializedProperty validLayers;
        private SerializedProperty pointerAudioSource;
        private SerializedProperty teleportRequestedClip;
        private SerializedProperty teleportCompletedClip;

        private bool teleportPointerFoldout = true;

        protected override void OnEnable()
        {
            DrawBasePointerActions = false;
            base.OnEnable();

            hotSpotCursorVisibility = serializedObject.FindProperty("hotSpotCursorVisibility");
            teleportAction = serializedObject.FindProperty("teleportAction");
            inputThreshold = serializedObject.FindProperty("inputThreshold");
            angleOffset = serializedObject.FindProperty("angleOffset");
            teleportActivationAngle = serializedObject.FindProperty("teleportActivationAngle");
            rotateActivationAngle = serializedObject.FindProperty("rotateActivationAngle");
            rotationAmount = serializedObject.FindProperty("rotationAmount");
            backStrafeActivationAngle = serializedObject.FindProperty("backStrafeActivationAngle");
            strafeAmount = serializedObject.FindProperty("strafeAmount");
            checkForFloorOnStrafe = serializedObject.FindProperty("checkForFloorOnStrafe");
            adjustHeightOnStrafe = serializedObject.FindProperty("adjustHeightOnStrafe");
            maxHeightChangeOnStrafe = serializedObject.FindProperty("maxHeightChangeOnStrafe");
            upDirectionThreshold = serializedObject.FindProperty("upDirectionThreshold");
            lineColorHotSpot = serializedObject.FindProperty("LineColorHotSpot");
            teleportLayerMasks = serializedObject.FindProperty("teleportRaycastLayerMasks");
            validLayers = serializedObject.FindProperty("ValidTeleportationLayers");
            pointerAudioSource = serializedObject.FindProperty("pointerAudioSource");
            teleportRequestedClip = serializedObject.FindProperty("teleportRequestedClip");
            teleportCompletedClip = serializedObject.FindProperty("teleportCompletedClip");
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            serializedObject.Update();

            teleportPointerFoldout = EditorGUILayout.Foldout(teleportPointerFoldout, "Teleport Pointer Settings", true);

            if (teleportPointerFoldout)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(hotSpotCursorVisibility);
                EditorGUILayout.PropertyField(teleportAction);
                EditorGUILayout.PropertyField(inputThreshold);
                EditorGUILayout.PropertyField(angleOffset);
                EditorGUILayout.PropertyField(teleportActivationAngle);
                EditorGUILayout.PropertyField(rotateActivationAngle);
                EditorGUILayout.PropertyField(rotationAmount);
                EditorGUILayout.PropertyField(backStrafeActivationAngle);
                EditorGUILayout.PropertyField(strafeAmount);
                EditorGUILayout.PropertyField(checkForFloorOnStrafe);
                if (checkForFloorOnStrafe.boolValue)
                {
                    EditorGUILayout.PropertyField(adjustHeightOnStrafe);
                    EditorGUILayout.PropertyField(maxHeightChangeOnStrafe);
                }
                EditorGUILayout.PropertyField(upDirectionThreshold);
                EditorGUILayout.PropertyField(lineColorHotSpot);
                EditorGUILayout.PropertyField(teleportLayerMasks);
                EditorGUILayout.PropertyField(validLayers);
                EditorGUILayout.PropertyField(pointerAudioSource);
                EditorGUILayout.PropertyField(teleportRequestedClip);
                EditorGUILayout.PropertyField(teleportCompletedClip);
                EditorGUI.indentLevel--;
            }

            serializedObject.ApplyModifiedProperties();
        }
    }
}