using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using NaughtyAttributes;
using Variables;

public class TimerController : MonoBehaviour
{

    [SerializeField,Header("References")]
    private Reference<float> m_time;

    [SerializeField]
    private TextMeshProUGUI m_text;

    [SerializeField, BoxGroup("Settings")]
    private Color m_lowTimeColor = Color.red;

    [SerializeField, BoxGroup("Settings")]
    private Color m_defaultColor;

    [SerializeField, BoxGroup("Settings")]
    private float m_lowTimeAmount = 3;

    


    private void Awake()
    {
        OnTimeChange(m_time.Value);
    }


    private void OnEnable()
    {
        m_time.OnValueChanged += OnTimeChange;
    }

    private void OnDisable()
    {
        m_time.OnValueChanged -= OnTimeChange;
    }

    private void OnTimeChange(float value)
    {

        m_text.text = value.ToString("0");

        if (value <= m_lowTimeAmount)
        {
            m_text.color = m_lowTimeColor;
        }
        else
        {
            m_text.color = m_defaultColor;
        }
    }


}
