using Intrepid.Utilities;
using UnityEngine;
using UnityEngine.UI;

namespace Intrepid.Core.UI.Gauge
{
    public class SimpleGaugeUI : MonoBehaviour
    {
        [GroupInjections, SerializeField] private Image filling;
        [GroupInjections, SerializeField] private Image counterFilling;
        [GroupDebug, SerializeField, Range(0, 1)] private float value;

        public Image Filling => filling;
        public Image CounterFilling => counterFilling;

        public float Value
        {
            get => value;
            set => this.value = value;
        }

        protected virtual void Update()
        {
            UpdateComponents();
        }

        protected virtual void UpdateComponents()
        {
            if (float.IsNaN(Value)) return;
            filling.rectTransform.localScale = new Vector3(Value, 1f, 1f);
            counterFilling.rectTransform.localScale = new Vector3(1f - Value, 1f, 1f);
        }
    }
}