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

namespace KitsuneCafe.UI
{
    public readonly struct ModalElementInstance : IUIElement
    {
        public readonly string Title;
        public readonly string Content;

        private readonly ModalElement so;
        public readonly VisualTreeAsset VisualTreeAsset => so.VisualTreeAsset;

        public ModalElementInstance(string title, string content, ModalElement so)
        {
            Title = title;
            Content = content;
            this.so = so;
        }

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

        public void Configure(VisualElement ve)
        {
            ve.Q<Label>(so.TitleId).text = Title;
            ve.Q<Label>(so.ContentId).text = Content;
        }
    }

    [CreateAssetMenu(menuName = KitsuneCafeMenu.UiElement + "Modal")]
    public class ModalElement : UIElementSO
    {
        [SerializeField]
        private string titleId = "title";
        public string TitleId => titleId;

        [SerializeField]
        private string contentId = "content";
        public string ContentId => contentId;

        public ModalElementInstance Create(string title, string content)
        {
            return new ModalElementInstance(title, content, this);
        }
    }
}
