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

namespace eagle {
    public class ExchangedHeroRowController : TableRowController, System.IDisposable {
        public RawImage professionImage;
        public TMP_Text heroNameLabel;
        public TMP_Text strLabel;
        public TMP_Text agiLabel;
        public TMP_Text wisLabel;
        public TMP_Text chrLabel;
        public TMP_Text conLabel;

        public RawImage archeryImage;
        public RawImage fireImage;

        public RawImage prisonerImage;
        public TMP_Text lastFactionLabel;

        private DynamicHeroTextUpdater textUpdater = new DynamicHeroTextUpdater();

        public void SetHostage(HeroView hero, string factionName) {
            SetHero(hero, factionName);
            prisonerImage.gameObject.SetActive(false);
        }

        public void SetPrisoner(HeroView hero, string factionName) {
            SetHero(hero, factionName);
            prisonerImage.gameObject.SetActive(true);
        }

        public void SetHero(HeroView hero, string factionName) {
            professionImage.texture =
                    gameObject.GetComponentInParent<EagleCommonTextures>().Profession(
                            hero.Profession);
            if (professionImage.texture == null) {
                professionImage.color = Color.clear;
            } else {
                professionImage.color = Color.white;
            }
            textUpdater.SetHeroText(heroNameLabel, hero.NameTextId, "Hero");

            if (hero.Strength > 0) {
                strLabel.text = hero.Strength.ToString();
                agiLabel.text = hero.Agility.ToString();
                wisLabel.text = hero.Wisdom.ToString();
                chrLabel.text = hero.Charisma.ToString();
                conLabel.text = hero.Constitution.ToString();

                archeryImage.gameObject.SetActive(hero.ArcheryCapable);
                fireImage.gameObject.SetActive(hero.StartFireCapable);
            } else {
                strLabel.text = "";
                agiLabel.text = "";
                wisLabel.text = "";
                chrLabel.text = "";
                conLabel.text = "";
            }

            lastFactionLabel.text = factionName;
        }

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

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