﻿using UnityEngine;
using UnityEngine.UI;
using Yumon.Template.Lite.Internal;

namespace Yumon.Template.Lite
{
    /// <summary>
    ///     Example of an Image that changes color based on the current league.
    /// </summary>
    [RequireComponent(typeof(Image))]
    public class LeagueBackgroundImage : MonoBehaviour
    {
        Image _image;

        void Awake()
        {
            _image = GetComponent<Image>();
            YumonLeagueManager.OnLeagueChanged += OnLeagueChange;
        }

        void Start() => OnLeagueChange(YumonLeagueManager.CurrentLeague);
        void OnDestroy() => YumonLeagueManager.OnLeagueChanged -= OnLeagueChange;
        void OnLeagueChange(League league) => _image.color = league switch
        {
            League.Practice => Color.white * 0.25f,
            League.Common => Color.green * 0.25f,
            League.Limited => Color.blue * 0.25f,
            League.Epic => Color.magenta * 0.25f,
            _ => Color.white * 0.5f,
        };
    }
}
