/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024

using FL.Battle.Buffs;
using FL.Data;
using XGame.Database;
using XGame.Framework.UI;

namespace FL.FGUI
{
    /// <summary>
    /// UI逻辑处理类
    /// </summary>
    /// <typeparam name=""></typeparam>
    public partial class MainBuffInfoListItemCtrl : UIController<MainBuffInfoListItemVM>
    {
        protected override void OnEnable(object intent)
        {
            AddUIListenres();
        }
        protected override void OnDisable()
        {
            RemoveUIListenres();
        }
        #region UI事件
        private void AddUIListenres()
        {

        }
        private void RemoveUIListenres()
        {

        }

        #endregion

        public void OnRefresh(int index, BuffPreviewDto dto)
        {
            var buffTable = BuffTableRepo.Get(dto.buffTableId);
            VM.BuffIcon.url = buffTable.Icon;
            VM.BuffNameLabel.text = buffTable.Name;
            VM.BuffLayerPar.max = dto.layerLimit;
            VM.BuffLayerPar.value = dto.layer;
            string triggerName;
            EQualityLevel quality;
            if (dto.isSkill)
            {
                var skill = SkillTableRepo.Get(dto.skillId);
                if (skill.BuffTie.Length == 2)
                {
                    var triBuff = BuffTableRepo.Get(skill.BuffTie[1]);
                    triggerName = triBuff.Name;
                }
                else
                {
                    triggerName = skill.Name;
                }
                quality = (EQualityLevel)skill.Quality;
            }
            else
            {
                var epigraph = EpigraphTableRepo.Get(dto.skillId);
                triggerName = epigraph.Name;
                quality = epigraph.Quality;
            }
            VM.TriggerNameLabel.text = string.Format(StringDefine.common_bracket, triggerName);
            VM.TriggerNameLabel.color = quality.ToEquipNameColor();
            VM.TipsLabel.text = dto.layer == dto.layerLimit ? StringDefine.buff_preview_tips_attack : StringDefine.buff_preview_tips_coming;
            //随从icon
            if (PartnersData.Instance.PartnersMap.TryGetValue(dto.partnerUID, out var partner))
            {
                var partnerTable = PartnerTableRepo.Get(partner.TableId);
                VM.PartnerIcon.url = partnerTable.Icon;
            }
        }
    }
}