using UnityEditor;
using UnityEngine;

namespace AssetBank.Settings
{
    [CustomPropertyDrawer(typeof(IgnoredUnityType))]
    public class IgnoredUnityTypeDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            var indent = EditorGUI.indentLevel;
            EditorGUI.indentLevel = 0;

            var assetTypeRect = new Rect(position.x, position.y, position.width * 0.5f, position.height);
            var customTypeRect = new Rect(position.x + position.width * 0.5f + 5, position.y, position.width * 0.5f - 5, position.height);

            var assetTypeProp = property.FindPropertyRelative("assetType");
            EditorGUI.PropertyField(assetTypeRect, assetTypeProp, GUIContent.none);

            if ((UnityAssetType)assetTypeProp.enumValueIndex == UnityAssetType.Custom)
            {
                EditorGUI.PropertyField(customTypeRect, property.FindPropertyRelative("customType"), GUIContent.none);
            }

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
    }
}
