using System;
using UnityEngine;
using Wizard.Scripts.Network.Data.TaskData.SpotCardExchange;

namespace Wizard;

public class SpotCardExchangePlate : MonoBehaviour
{
	private readonly Quaternion CARDOBJECT_ROTATION_QUATERNION = new Quaternion(0f, 0f, 0f, 0f);

	private const string SPOT_CARD_NUM_FORMAT = "[fcd24a]+{0}[-]";

	[SerializeField]
	private GameObject _objCardRoot;

	[SerializeField]
	private UILabel _labelSpotCardName;

	[SerializeField]
	private UILabel _labelCardPossessionNum;

	[SerializeField]
	private UILabel _labelCardPossessionNumNormal;

	[SerializeField]
	private UILabel _labelCardPossessionNumPremium;

	[SerializeField]
	private UILabel _labelCostSpotCardPoint;

	[SerializeField]
	private UIButton _btnExchangeSpotCard;

	[SerializeField]
	private UILabel _labelExchanged;

	private GameObject _cardObject;

	public void SetData(SpotCardExchangeInfo spotCardInfo, int haveSpotCardPoint, SpotCardExchangeInfoTask.PrereleaseExchangeInfo prereleaseInfo, Action<SpotCardExchangeInfo> onClickExchangButton)
	{
		SystemText systemText = Data.SystemText;
		string text = spotCardInfo.GetExchangeCardTextSmall();
		if (spotCardInfo.IsPrereleaseCard)
		{
			text = systemText.Get("Shop_0183", text);
		}
		_labelSpotCardName.text = text;
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		int possessionCardNum = dataMgr.GetPossessionCardNum(spotCardInfo.CardId, isIncludingSpotCard: false);
		int spotCardNum = dataMgr.SpotCardData.GetSpotCardNum(spotCardInfo.CardId);
		_labelCardPossessionNumNormal.text = possessionCardNum + ((spotCardNum > 0) ? $"[fcd24a]+{spotCardNum}[-]" : string.Empty);
		int cardId = spotCardInfo.CardId + 1;
		int possessionCardNum2 = dataMgr.GetPossessionCardNum(cardId, isIncludingSpotCard: false);
		_labelCardPossessionNumPremium.text = possessionCardNum2.ToString();
		int num = possessionCardNum + possessionCardNum2 + spotCardNum;
		_labelCardPossessionNum.text = num.ToString();
		string typeName = "";
		string detailName = "";
		ShopCommonUtility.GetRewardNames(12, 0L, spotCardInfo.ExchangePoint, out typeName, out detailName);
		_labelCostSpotCardPoint.text = systemText.Get("Shop_0129", typeName, detailName);
		switch (spotCardInfo.SpotCardExchangeStatus)
		{
		case SpotCardExchangeInfo.ExchangeStatus.AlreadyExchange:
			_btnExchangeSpotCard.gameObject.SetActive(value: false);
			_labelExchanged.gameObject.SetActive(value: true);
			break;
		case SpotCardExchangeInfo.ExchangeStatus.EnableExchange:
		{
			_btnExchangeSpotCard.onClick.Clear();
			_btnExchangeSpotCard.onClick.Add(new EventDelegate(delegate
			{
				onClickExchangButton(spotCardInfo);
			}));
			_btnExchangeSpotCard.gameObject.SetActive(value: true);
			_labelExchanged.gameObject.SetActive(value: false);
			bool flag = haveSpotCardPoint < spotCardInfo.ExchangePoint;
			if (prereleaseInfo.IsPrerelease && spotCardInfo.IsPrereleaseCard)
			{
				flag |= prereleaseInfo.RemainingExchangeableCount <= 0;
			}
			UIManager.SetObjectToGrey(_btnExchangeSpotCard.gameObject, flag);
			break;
		}
		case SpotCardExchangeInfo.ExchangeStatus.LimitOver:
			_btnExchangeSpotCard.gameObject.SetActive(value: true);
			_labelExchanged.gameObject.SetActive(value: false);
			UIManager.SetObjectToGrey(_btnExchangeSpotCard.gameObject, b: true);
			break;
		}
	}

	public void SetCardObject(GameObject cardObject, GameObject evacuationParent)
	{
		if (_cardObject != null)
		{
			_cardObject.SetActive(value: false);
			_cardObject.transform.parent = evacuationParent.transform;
		}
		cardObject.transform.parent = _objCardRoot.transform;
		cardObject.transform.localPosition = Vector3.zero;
		cardObject.transform.rotation = CARDOBJECT_ROTATION_QUATERNION;
		cardObject.SetActive(value: true);
		_cardObject = cardObject;
	}
}
