using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ActionTimer : MonoBehaviour
{
     
    [SerializeField] private GameObject timerBar;

    public GameObject timerHandler;

    public PlayerInteract pInteract;

    public float maxTime;
    public float minTime;
    private float timer;

    private void Awake()
    {
        timerBar = this.gameObject.transform.GetChild(0).GetChild(0).gameObject;
        timer = minTime;
        timerHandler.SetActive(false);
    }

    public void SetSize(float sizeNormalized)
    {
        timerBar.transform.localScale = new Vector3(sizeNormalized, 1f);
    }

    private void Update()
    {
        if (timer <= maxTime && timerHandler == true && pInteract.isCounting && pInteract.hasNegativeThoughts)
        {
            timer += .01f;
            SetSize(timer);
            if (timer >= maxTime)
            {
                Debug.Log("Item Process Succesful");
                pInteract.hasNegativeThoughts = false;
                pInteract.hasPositiveThoughts = true;
                pInteract.negativeThoughts.SetActive(false);
                pInteract.positiveThoughts.SetActive(true);
            }
        }
        else
        {
            timer = minTime;
            pInteract.isCounting = false;
            timerHandler.gameObject.SetActive(false);
        }
    }
}
