using Cute;
using UnityEngine;

namespace Wizard;

public class CardSleeveRewardItem : MonoBehaviour
{
	[SerializeField]
	private UITexture _rewardTexture;

	[SerializeField]
	private UILabel _rewardLabel;

	[SerializeField]
	private UILabel _alreadyGetLabel;

	[SerializeField]
	private GameObject _cardObjectParent;

	[SerializeField]
	private GameObject _cardMask;

	public UITexture RewardTexture => _rewardTexture;

	public ShopCommonRewardInfo Info { get; private set; }

	public GameObject CardObjectParent => _cardObjectParent;

	public void SetReward(ShopCommonRewardInfo rewardInfo)
	{
		Info = rewardInfo;
		if (RewardTexture != null)
		{
			if (rewardInfo.Type == 6)
			{
				Sleeve sleeve = Data.Master.SleeveMgr.Get(rewardInfo.UserGoodsId);
				UIManager.GetInstance().getUIBase_CardManager().SetSleeveTexture(RewardTexture, sleeve.sleeve_id);
			}
			else if (rewardInfo.Type == 7)
			{
				string rewardImagePath = ShopCommonUtility.GetRewardImagePath(rewardInfo, isFetch: true);
				RewardTexture.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(rewardImagePath);
				RewardTexture.material = null;
			}
			else
			{
				_ = rewardInfo.Type;
				_ = 5;
			}
		}
		if (_rewardLabel != null)
		{
			if (rewardInfo.Type == 5)
			{
				CardParameter cardParameterFromId = CardMaster.GetInstance(CardMaster.CardMasterId.Default).GetCardParameterFromId((int)rewardInfo.UserGoodsId);
				_rewardLabel.SetWrapText(cardParameterFromId.CardName);
			}
			else
			{
				_rewardLabel.SetWrapText(ShopCommonUtility.GetRewardDetailName(rewardInfo));
			}
		}
	}

	public void SetArleadyGetVisible(bool visible)
	{
		if (!(_alreadyGetLabel == null))
		{
			_alreadyGetLabel.gameObject.SetActive(visible);
			if (RewardTexture != null)
			{
				UIManager.SetObjectToGrey(RewardTexture.gameObject, visible);
			}
			if (_cardMask != null)
			{
				_cardMask.SetActive(visible);
			}
		}
	}

	public void ChangeNameLabelPosition(Vector3 localPosition)
	{
		if (_rewardLabel != null)
		{
			_rewardLabel.transform.localPosition = localPosition;
		}
	}

	public void ChangeNameLabelWidth(int width)
	{
		if (_rewardLabel != null)
		{
			_rewardLabel.width = width;
		}
	}
}
