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

using FairyGUI;
using FL.Data;
using XGame.Database;
using XGame.Framework.UI;

namespace FL.FGUI
{
    public class PartnerListItemData
    {
        public int tableId;
        /// <summary>
        /// 未获取的uid为0
        /// </summary>
        public long uid;
        /// <summary>
        /// 0:未获取
        /// 1:已获取未上阵
        /// 2:已上阵
        /// </summary>
        public int state;
        /// <summary>
        /// 是否显示已上阵的遮罩
        /// </summary>
        public bool isShowUpMask;
    }
    /// <summary>
    /// UI逻辑处理类
    /// </summary>
    /// <typeparam name=""></typeparam>
    public partial class PartnerInfoListItemCtrl : UIController<PartnerInfoListItemVM>
    {
        private PartnerListItemData _data;
        protected override void OnEnable(object intent)
        {
            AddUIListenres();
        }
        protected override void OnDisable()
        {
            RemoveUIListenres();
        }
        #region UI事件
        private void AddUIListenres()
        {
            VM.DownBtn.onClick.Add(OnClickDownBtn);
            VM.UpBtn.onClick.Add(OnClickUpBtn);

        }
        private void RemoveUIListenres()
        {
            VM.DownBtn.onClick.Remove(OnClickDownBtn);
            VM.UpBtn.onClick.Remove(OnClickUpBtn);

        }
        private void OnClickDownBtn(EventContext context)
        {
            PartnersService.Instance.RequestPartnerDown(_data.uid);
        }
        private void OnClickUpBtn(EventContext context)
        {
            PartnersService.Instance.RequestPartnerUp(_data.uid);
        }

        #endregion
        public void OnRefresh(int index, PartnerListItemData data)
        {
            _data = data;
            var table = PartnerTableRepo.Get(data.tableId);
            VM.StateCtrl.selectedIndex = data.state;
            VM.GoneUpMaskCtrl.selectedIndex = data.isShowUpMask ? 1 : 0;
            VM.QualityImg.icon = AddressableDefine.PartnerQualityFrame(table.Quality);
            VM.PartnerImg.icon = table.Icon;
            VM.LevelTxt.text = table.Name;
        }
    }
}