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

using FL.Nodes.DragonEgg;
using XGame.Database;
using XGame.Framework.UI;


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

        }
        private void RemoveUIListenres()
        {

        }

        #endregion

        public void ShowUI(EAttributeType attributeType, long attributeVal, eCompareType compareType, bool bShow)
        {
            VM.Show.selectedIndex = bShow ? 1 : 0;
            if (!bShow) return;
            VM.Compare.selectedIndex = (int)compareType;
            var attributeInfo = AttrDescTableRepo.Get((int)attributeType);

            VM.AttrLabel.text = GetAttributeDesc(attributeInfo, attributeVal, attributeType == EAttributeType.AtkSpeed);

            bool bSpecialAttr = attributeType.IsItemSpecial();
            VM.DescLabel.visible = bSpecialAttr;
            if (bSpecialAttr)
            {
                VM.DescLabel.text = attributeInfo.ShowName;
            }
        }

        private string GetAttributeDesc(AttrDescTable attributeInfo, long attrVal, bool bAtkSpeed)
        {
            string desc = attributeInfo.Num_type == 1 ? TableUtils.ToRealDouble(attrVal).ToString("F3") + "%" :
                            (bAtkSpeed ? TableUtils.ToRealDouble(attrVal).ToString("F1") : attrVal.ToString());
            return $"{attributeInfo.ShowName} {desc}";

        }

        public void ResetUI()
        {
            VM.Compare.selectedIndex = 0;
            VM.AttrLabel.text = string.Empty;
            VM.DescLabel.text = string.Empty;
        }
    }
}