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

namespace Intrepid.Gameplay.Codex.UI.Components
{
    public class CodexColorEffectTargetUI : MonoBehaviour
    {
        [GroupInjections, SerializeField] private Graphic target;
        [GroupInjections, SerializeField] private CodexColorEffectUI colorEffectUI;
        
        public void Apply(Color targetColor)
        {
            if (target.IsNull()) return;

            if (colorEffectUI.IsNotNull() && colorEffectUI.isActiveAndEnabled)
            {
                colorEffectUI.Apply(target, targetColor);
            }
            else
            {
                target.color = targetColor;
            }
        }

        public void Stop()
        {
            if (target.IsNull()) return;
            
            if (colorEffectUI.IsNotNull() && colorEffectUI.isActiveAndEnabled)
            {
                colorEffectUI.Stop(target);
            }
        }
    }
}