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

using XGame.Framework.FGUI;
using XGame.Framework.UI;

namespace FL.FGUI
{
    public class EggQualityItemData
    {
        public int quality; // 品质等级
        public int curVal;  // 当前等级的概率值(概率-10万分比)
        public int nextVal; // 下一等级的概率值
        public bool bMaxLv; // 当前是否满级状态
        public bool bLock;  // 是否未解锁
    }


    /// <summary>
    /// UI逻辑处理类
    /// </summary>
    /// <typeparam name=""></typeparam>
    public partial class DragonEggEggQualityListCtrl : UIController<DragonEggEggQualityListVM>
    {
        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, EggQualityItemData data)
        {
            string dragonEggPkgName = AddressableDefine.GetDragonEggPkgName();
            VM.QualityBg.icon = FguiUtils.ToUrl(dragonEggPkgName, AddressableDefine.EggQuality(data.quality));
            VM.QualityIcon.icon = FguiUtils.ToUrl(dragonEggPkgName, AddressableDefine.EggQuality(data.quality));
            VM.CurLab.text = GetProbability(data.curVal);
            VM.NextLab.text = GetProbability(data.nextVal);
            VM.LockImg.visible = data.bLock;
        }

        /// <summary>
        /// 十万分比
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private string GetProbability(int val)
        {
            return $"{(val * 0.00001f).ToString("F3")}%";
        }

    }
}