
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.UI;

namespace JohnsonUtils.Canvases
{
    public class ImageUIComponent : UIComponentBase
    {
        [Header("Association")]
#if ODIN_INSPECTOR
        [Required]
#endif
        [SerializeField] private Image image;

        private Color _initialColor;

        private void Awake() => _initialColor = image.color;
        
        private void Start() => Debug.Assert(image, $"A {nameof(image)} must be assigned to a {nameof(ImageUIComponent)}");

        public void ResetColor() => image.color = _initialColor;
        
        public Sprite Sprite
        {
            set => image.sprite = value;
        }

        public Color Color
        {
            set => image.color = value;
        }

        private void OnValidate()
        {
            if (!image)
                image = GetComponent<Image>();
        }
    }
}