using Net.Eagle0.Eagle.Views;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace eagle {
    public class CombatUnitRowController : TableRowController, System.IDisposable {
        public RawImage professionImage;
        public TMP_Text heroNameLabel;
        public RawImage battalionImage;
        public TMP_Text sizeLabel;
        public TMP_Text trainingLabel;
        public TMP_Text armamentLabel;

        private DynamicHeroTextUpdater textUpdater = new DynamicHeroTextUpdater();

        public HeroView Hero {
            set {
                professionImage.texture = CommonTextures.Profession(value.Profession);
                professionImage.color = professionImage.texture == null ? Color.clear : Color.white;
                textUpdater.SetHeroText(heroNameLabel, value.NameTextId, "Hero");
            }
        }

        public BattalionView Battalion {
            set {
                if (value == null) {
                    battalionImage.texture = null;
                    sizeLabel.text = "0";
                    trainingLabel.text = null;
                    armamentLabel.text = null;
                } else {
                    battalionImage.texture = CommonTextures.BattalionType(value.Type);
                    sizeLabel.text = value.Size.ToString();
                    trainingLabel.text = ((int)value.Training).ToString();
                    armamentLabel.text = ((int)value.Armament).ToString();
                }

                battalionImage.color = battalionImage.texture == null ? Color.clear : Color.white;
            }
        }

        public void Dispose() { textUpdater?.Dispose(); }

        private void OnDestroy() { Dispose(); }
    }
}