namespace Marro.PacManUdon
{
    using UdonSharp;
    using UnityEngine;
    using VRC.SDKBase;
    using VRC.Udon;

    public class ScoreBonusDisplay : UdonSharpBehaviour
    {
        private Animator animator;
        private float countdownSeconds;
        private bool countingDown;
        public void Initialize()
        {
            animator = GetComponent<Animator>();
            countdownSeconds = 0;
            countingDown = false;
            gameObject.SetActive(false);
        }

        void Update()
        {
            if (countingDown)
            {
                countdownSeconds -= Time.deltaTime;
                if (countdownSeconds <= 0)
                {
                    Hide();
                }
            }
        }

        public void DisplayTemporarily(int score, int seconds)
        {
            Display(score);
            countdownSeconds = seconds;
            countingDown = true;
        }

        public void Display(int score)
        {
            gameObject.SetActive(true);
            animator.SetFloat("Score", score);
        }

        public void Hide()
        {
            countingDown = false;
            gameObject.SetActive(false);
        }
    }
}
