using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace XGame.Editor.Asset.Processor
{
    public class AssetsConfigProvider : SettingsProvider
    {
        private SerializedProperty _script;
        private SerializedObject _serializedObject;

        public AssetsConfigProvider(string path, SettingsScope scopes, IEnumerable<string> keywords = null) : base(path, scopes, keywords)
        {
            Debug.Log($"AssetsConfigProvider Constructor. Path:{path} Scope:{scopes}");
        }

        public override void OnActivate(string searchContext, VisualElement rootElement)
        {
            Debug.Log($"AssetsConfigProvider OnActivate.");
            var config = AssetDatabase.LoadAssetAtPath<AssetsConfig>(PathDefine.AssetsConfigPath);
            _serializedObject = new SerializedObject(config);
            _script = _serializedObject.FindProperty("m_Script");

            base.OnActivate(searchContext, rootElement);
        }
        public override void OnGUI(string searchContext)
        {
            //展示区域，禁止操作
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(_script);
            GUILayout.Space(10);
            EditorGUI.EndDisabledGroup();

            _serializedObject.Update();

            base.OnGUI(searchContext);
        }
        public override void OnDeactivate()
        {
            _script = null;
            _serializedObject = null;
            base.OnDeactivate();
        }
    }

}
