// <auto-generated>
// These Unity wrappers are auto-generated.
// </auto-generated>

namespace Apex.Editor
{
    using System.Collections.Generic;
    using System.Reflection;
    using UnityEditor;
    using UnityEngine;
    using Utilities;
    public static class EditorUtilities
    {
        private static readonly HashSet<string> _keywords = new HashSet<string>()
        {
            "abstract", "as",  "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue",
            "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface",
            "public", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof",
            "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while"
        };

        public static bool IsReservedWord(string s)
        {
            return _keywords.Contains(s);
        }

        public static string Elipsify(this string s, int maxLength)
        {
            if (s.Length <= maxLength || s.Length <= 3)
            {
                return s;
            }

            return string.Concat(s.Substring(0, maxLength - 3), "...");
        }

        public static void Section(string label)
        {
            if (EditorGUI.indentLevel > 0)
            {
                EditorGUI.indentLevel -= 1;
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField(label);
            EditorGUI.indentLevel += 1;
        }

        public static List<SerializedProperty> GetProperties(this Editor editorInstance, params string[] exlude)
        {
            var props = new List<SerializedProperty>();

            var t = editorInstance.target.GetType();
            var bf = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
            if (exlude == null || exlude.Length == 0)
            {
                bf |= BindingFlags.DeclaredOnly;
            }

            if (exlude == null)
            {
                exlude = Empty<string>.array;
            }

            foreach (var f in t.GetFields(bf))
            {
                if (((f.IsPrivate || f.IsFamily) && !f.IsDefined<SerializeField>(false)) || f.IsDefined<HideInInspector>(false) || exlude.IndexOf(f.Name) >= 0)
                {
                    continue;
                }

                props.Add(editorInstance.serializedObject.FindProperty(f.Name));
            }

            return props;
        }
    }
}