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

public class HUDController : MonoBehaviour
{
    public bool chartOn = false;
    public Toggle chartOnToggleObj;
    public TMP_InputField chartOnTimeOutInputObj;
    public TMP_InputField enemyNumInputObj;
    public float chartOnTimeOut = 1;
    public int enemyNum= 3;
    public float chartOnTimeOutDefault = 120f;
    private float chatOntimeStart = 0;

    private void Update()
    {
        if (chartOn)
        {
            if (Time.time - chatOntimeStart >= chartOnTimeOut )
            {
                chartOn = false;
                chartOnToggleObj.isOn = false;
            }
        }
    }

    public void onChartOnToggleChange()
    {
        chatOntimeStart = Time.time;
        chartOn = chartOnToggleObj.isOn;
    }

    public void onEnemyNumTextChange()
    {
        try
        {
            enemyNum = Math.Abs(int.Parse(enemyNumInputObj.GetComponent<TMP_InputField>().text));
        }
        catch (NullReferenceException)
        {
            enemyNum = 3;
        }
    }

    public void onChartTimeOutTextChange()
    {
        try
        {
            chartOnTimeOut = Math.Abs(int.Parse(chartOnTimeOutInputObj.GetComponent<TMP_InputField>().text));
        }
        catch (NullReferenceException)
        {
            chartOnTimeOut = chartOnTimeOutDefault;
        }
    }
}
