using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static Net.Eagle0.Eagle.Api.OrganizeTroopsAvailableCommand.Types;

namespace eagle {
    public class OrganizeExtrasTable : MonoBehaviour {
        public RawImage unavailableImage;
        public GameObject minimumAgricultureRow;
        public GameObject minimumEconomyRow;
        public TMP_Text minimumAgriculture;
        public TMP_Text minimumEconomy;

        // Start is called before the first frame update
        void Start() {}

        // Update is called once per frame
        void Update() {}

        public void
        Set(bool allowed, BattalionTypeStatus battalionTypeStatus, int agriculture, int economy) {
            var parent = gameObject.transform.parent;
            parent.GetComponentInChildren<Button>().interactable = allowed;
            unavailableImage.gameObject.SetActive(!allowed);

            var color = parent.GetComponentInChildren<RawImage>().color;
            if (allowed) {
                color.a = 255;
            } else {
                color.a = 70;

                if (agriculture < battalionTypeStatus.MinimumAgriculture) {
                    minimumAgriculture.text = battalionTypeStatus.MinimumAgriculture.ToString();
                    minimumAgricultureRow.gameObject.SetActive(true);
                } else {
                    minimumAgricultureRow.gameObject.SetActive(false);
                }

                if (economy < battalionTypeStatus.MinimumEconomy) {
                    minimumEconomy.text = battalionTypeStatus.MinimumEconomy.ToString();
                    minimumEconomyRow.gameObject.SetActive(true);
                } else {
                    minimumEconomyRow.gameObject.SetActive(false);
                }
            }

            parent.GetComponentInChildren<RawImage>().color = color;
        }
    }
}