using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace eagle {
    public class OrganizeTroopsResultRow : MonoBehaviour {
        public RawImage battalionImage;
        public TMP_Text priceLabel;
        public TMP_Text newTrainingLabel;
        public TMP_Text newArmamentLabel;
        public TMP_Text newSizeLabel;
        public TMP_Text sizeCapLabel;
        public TMP_Text totalCostLabel;
        public TMP_Text battalionNameLabel;

        private void Start() {}

        public Texture BattalionImage { set => battalionImage.texture = value; }

        public double Price { set => priceLabel.text = value.ToString("0.##"); }

        public double? Training {
            set {
                if (value is double newVal) newTrainingLabel.text = Math.Floor(newVal).ToString();
                else
                    newTrainingLabel.text = "?";
            }
        }

        public double? Armament {
            set {
                if (value is double newVal) newArmamentLabel.text = Math.Floor(newVal).ToString();
                else
                    newArmamentLabel.text = "?";
            }
        }

        public int Size { set => newSizeLabel.text = value.ToString(); }

        public int Capacity { set => sizeCapLabel.text = value.ToString(); }

        public string Name {
            set {
                if (string.IsNullOrEmpty(value)) {
                    battalionNameLabel.gameObject.SetActive(false);
                } else {
                    battalionNameLabel.gameObject.SetActive(true);
                    battalionNameLabel.text = value;
                }
            }
        }
    }
}