using System;
using Intrepid.Gameplay.Codex.Visual;
using Intrepid.Utilities;
using TMPro;
using UnityEngine;

namespace Intrepid.Gameplay.Codex.UI.Components
{
    public class CodexTextComponentUI : CodexComponentUI
    {
        [GroupConfigurations, SerializeField] private PictorialTextType textType = PictorialTextType.Primary;
        
        [GroupInjections, SerializeField] private TextMeshProUGUI textMesh;

        public string Value
        {
            get => textMesh.IsNotNull() ? textMesh.text : string.Empty;
            set
            {
                if (textMesh.IsNull()) return;
                textMesh.text = value;
            }
        }

        public override void ApplyCodexVisuals(CodexVisualContext ctx)
        {
            textMesh.color = ctx.Protocol.GetTextColor(textType);
        }
    }
}