using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using TMPro;

public class MedicineBottle : MonoBehaviour
{
    private Button medicineButton;

    [SerializeField] TextMeshProUGUI clickAmount;

    [SerializeField] ActionSO statDecreaseAction;

    protected Button MedicineButton { get => medicineButton; set => medicineButton = value; }
    protected ActionSO StatDecreaseAction { get => statDecreaseAction; set => statDecreaseAction = value; }
    protected TextMeshProUGUI ClickAmount { get => clickAmount; set => clickAmount = value; }

    private void Start()
    {
    }

    protected virtual void OnEnable()
    {
        if (MedicineButton == null)
            Init();

        MedicineButton.interactable = ResourceManager.Instance.ResourceAmount > 0;
        ClickAmount.text = "0/" + GameManager.Instance.MedicineClickAmount.ToString();
    }

    protected virtual void OnDisable()
    {
        
    }

    protected void Init()
    {
        MedicineButton = GetComponent<Button>();
        MedicineButton.onClick.AddListener(ButtonClick);
    }

    protected virtual void ButtonClick()
    {
        Debug.Log("click");
        ResourceManager.Instance.MedicineClicks++;
        ResourceManager.Instance.ResourceAmount--;
        //statDecreaseAction.InvokeAction();
        ClickAmount.text = ResourceManager.Instance.MedicineClicks.ToString() + "/" + GameManager.Instance.MedicineClickAmount.ToString();

        MedicineButton.interactable = ResourceManager.Instance.ResourceAmount > 0;

        if(ResourceManager.Instance.MedicineClicks >= GameManager.Instance.MedicineClickAmount)
        {
            SceneManager.LoadScene("WinScene");
        }
    }
}