using System;
using UnityEngine;
using UnityEngine.UI;

public class RealTimeEnemyNumChanger : MonoBehaviour
{
    public GameObject Agent;

    public InputField enemyNumInputField;
    public Text enemyNumPlaceholder;

    public void EnemyChangeBTPresses()
    {
        AgentWithGun agentWithGun = Agent.GetComponent<AgentWithGun>();
        InGameMessages messenger = gameObject.GetComponent<InGameMessages>();
        int enemyNum = Math.Abs(int.Parse(enemyNumInputField.GetComponent<InputField>().text));


        if (enemyNumInputField.GetComponent<InputField>().text == "-")
        {
            // input chara not illegal
            enemyNumPlaceholder.color = Color.red;
            enemyNumPlaceholder.text = "Wrong Type!";
            enemyNumInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Wrong enemyNum Type!", Message.MessageType.error);
        }
        else if (enemyNumInputField.GetComponent<InputField>().text == "")
        {
            // empty chara
            enemyNumPlaceholder.color = Color.gray;
            enemyNumPlaceholder.text = "nonR";
        }
        else
        {
            // good to go~
            enemyNumPlaceholder.color = Color.gray;
            enemyNumPlaceholder.text = "nonR";
            agentWithGun.enemyNum = enemyNum;
            enemyNumInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox($"Enemy Num = {enemyNum} add Success. Valid in the next round.", Message.MessageType.success);
        }
    }
}
