using TMPro;
using UnityEngine;

namespace RothenburgAR.UI
{
    public class TutorialHighlightBehaviour : MonoBehaviour
    {
        public RectTransform HorizontalLine;
        public RectTransform DiagonalLine;
        public TextMeshProUGUI TextMesh;

        public void SetText(string text)
        {
            TextMesh.SetText(text);

            // Update Recttransform

            var preferredValues = TextMesh.GetPreferredValues();
            var rectTransform = TextMesh.transform.parent.GetComponent<RectTransform>();

            var currentSize = rectTransform.sizeDelta.x;
            var newSize = preferredValues.x;
            var sizeDiff = (currentSize - newSize) / 2f;
            rectTransform.sizeDelta = new Vector2(newSize, 32);

            if (HorizontalLine != null) HorizontalLine.sizeDelta += new Vector2(sizeDiff, 0);
            if (DiagonalLine != null) DiagonalLine.localPosition += new Vector3(sizeDiff, 0);
        }
    }
}