﻿using System.Collections.Generic;
using TMPro;
using UnityEngine;
using Yumon.Template.Lite.Internal;

namespace Yumon.Template.Lite
{
    [RequireComponent(typeof(TextMeshProUGUI))]
    public class GameStateTextDebugger : MonoBehaviour
    {
        // Map the states to colors for fancier debugging
        readonly Dictionary<State, string> _stateColors = new Dictionary<State, string>
        {
            { GameState.Home, "green" },
            { GameState.Gameplay, "yellow" },
            { GameState.EndGame, "red" },
        };

        TextMeshProUGUI _text;

        void Awake()
        {
            _text = GetComponent<TextMeshProUGUI>();
            GameState.OnStateChange += OnStateChange;
        }

        void Start() => OnStateChange(GameState.CurrentState);
        void OnStateChange(State state) => _text.text =
            _stateColors.TryGetValue(state, out string color)
                ? $"Current State: <color={color}>{state.stateEnum}</color>" :
                $"Current State: {state.stateEnum}";
    }
}
