using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.UIElements;
using Logger = RebootKit.Engine.Foundation.Logger;

namespace RebootKit.Engine.UI {
    public abstract class UIDocumentView : MonoBehaviour, IView, IVisualElementBuilder {
        static readonly Logger s_logger = new Logger(nameof(UIDocumentView));

        [SerializeField] UIDocument m_Document;

        void OnEnable() {
            Rebuild();
        }

        protected void Rebuild() {
            Profiler.BeginSample("UI Tree Build");
            VisualElement child = Build();
            Profiler.EndSample();

            m_Document.rootVisualElement.Q<VisualElement>("root__container").Clear();
            m_Document.rootVisualElement.Q<VisualElement>("root__container").Add(child);
        }

        public abstract VisualElement Build();
        public void Show() {
        }

        public void Hide() {
        }

        public void Dispose() {
        }
    }
}