using System;
using UnityEngine.UIElements;

namespace VOID.UserInterface.Game.GameLog
{
    [Serializable]
    public class GameLogMessageUI
    {
        private VisualElement _parentElement;
        private VisualElement _templateElement;
        private Label _timeLabel;
        private Label _contentLabel;
        
        public void InitNew(VisualElement parentWrapperElement, string message)
        {
            _parentElement = parentWrapperElement;
            _templateElement = GameLogUI.current.messageTemplate.CloneTree().contentContainer;
            _parentElement.Add(_templateElement);
            _timeLabel = _templateElement.Q<Label>(className: "time");
            _timeLabel.text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]";
            _contentLabel = _templateElement.Q<Label>(className: "content");
            _contentLabel.text = message;
        }

        public void Destroy()
        {
            _parentElement.Remove(_templateElement);
        }
    }
}