using KitsuneCafe.System;
using UnityEngine;
using UnityEngine.UIElements;

namespace KitsuneCafe.UI
{
    public interface IUIElement
    {
        VisualTreeAsset VisualTreeAsset { get; }

        VisualElement Instantiate();
        void Configure(VisualElement element);
    }

    [CreateAssetMenu(menuName = KitsuneCafeMenu.UiElement + "Element")]
    public abstract class UIElementSO : ScriptableObject, IUIElement
    {
        [SerializeField]
        private VisualTreeAsset visualTreeAsset;
        public VisualTreeAsset VisualTreeAsset => visualTreeAsset;

        public virtual VisualElement Instantiate()
        {
            var instance = visualTreeAsset.CloneTree();
            Configure(instance);
            return instance;
        }

        public virtual void Configure(VisualElement ve) { }
    }
}
