using System;
using System.Collections;
using TMPro;
using UnityEngine;

public class InventoryManager : MonoBehaviour
{
    [SerializeField] // the variable is private, but can be changed in unity
    private TextMeshProUGUI presentText;
    [SerializeField]
    private TextMeshProUGUI healthText;
    [SerializeField]
    private TextMeshProUGUI juiceText;
    [SerializeField]
    private AudioSource hitSound;
    
    private int _presentAmount;
    public int PresentAmount
    {
        get { return _presentAmount; }
        set
        {
            _presentAmount = value;
            presentText.text = _presentAmount + "x";
        }
    }
    
    private int _juiceAmount;
    public int JuiceAmount
    {
        get { return _juiceAmount; }
        set
        {
            _juiceAmount = value;
            juiceText.text = _juiceAmount + "x";
        }
    }

    private bool firstPlay = true;
    private int _healthAmount;
    public int HealthAmount
    {
        get { return _healthAmount; }
        set
        {
            if (!firstPlay)
            {
                hitSound.Play();
            }
            if (firstPlay)
            {
                firstPlay = false;
            }
            _healthAmount = value;
            healthText.text = _healthAmount + "x";
            StartCoroutine(changeColor());
        }
    }

    IEnumerator changeColor()
    {
        healthText.color = Color.red;
        yield return new WaitForSeconds(0.2f);
        healthText.color = Color.black;
    }

    private void Start()
    {
        HealthAmount = 3;
    }
}
