using System;
using System.Collections.Generic;
using Cute;
using UnityEngine;

namespace Wizard;

public class GachaPackAreaLayout : MonoBehaviour
{
	private const int TICKET_BUTTON_TUTORIAL_GUIDE_ROTATION = -45;

	private readonly Vector3 DEFAULT_PACK_TICKET_POSITION = new Vector3(7f, 40.6f, 0f);

	private readonly Vector3 LEGEND_PACK_TICKET_POSITION = new Vector3(7f, -179.6f, 0f);

	private const string REPLACE_REMAIN = "{remaining_purchase_time}";

	private const int SECONDS_PER_DAY = 86400;

	private const int SECONDS_PER_HOUR = 3600;

	private const int SECONDS_PER_MINUTE = 60;

	private const int DEPTH_BANNER_DIALOG = 610;

	private const string LAYER_DIALOG_PURCHASE_REWARD = "MyPage";

	private const int DEPTH_DIALOG_PURCHASE_REWARD = 140;

	private const int SORTODER_DIALOG_PURCHASE_REWARD = 2;

	[SerializeField]
	private UITexture _packTitleTexture;

	[SerializeField]
	private UIButton _rateButton;

	[SerializeField]
	private UITexture _packPosterTexture;

	[SerializeField]
	private UITexture _packPosterLegendPack;

	[SerializeField]
	private UILabel _labelPackDescription;

	[SerializeField]
	private UILabel _labelSpecialPackDescription;

	[SerializeField]
	private GachaLayoutPurchaseButton _layoutPurchaseTicketButton;

	[SerializeField]
	private GachaLayoutPurchaseButton _layoutPurchaseRupyButton;

	[SerializeField]
	private GachaLayoutPurchaseButton _layoutPurchaseCrystalButton;

	[SerializeField]
	private GachaLayoutPurchaseButton _layoutPurchaseDailyButton;

	[SerializeField]
	private GachaLayoutPurchaseButton _layoutPurchaseFree10PacksButton;

	[SerializeField]
	private GachaLayoutPurchaseButton _layoutPurchaseStepupButton;

	[SerializeField]
	private GachaLayoutEffect _free10PackEffect;

	[SerializeField]
	private CenteringUIWidget _free10PackCentering;

	[SerializeField]
	private UITexture _headLineTicketTexture;

	[SerializeField]
	private GameObject _objPrereleaseLayoutRoot;

	[SerializeField]
	private GameObject _noLimitPrereleaseRoot;

	[SerializeField]
	private UIButton _btnPrereleasePurchaseRewards;

	[SerializeField]
	private UILabel _labelPrereleaseRemainTime;

	[SerializeField]
	private UILabel _labelPrereleasePurchaseCount;

	[SerializeField]
	private GameObject _prereleaseRemainTimeRoot;

	[SerializeField]
	private GachaPackPointLayout _packPointLayout;

	[SerializeField]
	private UIButton _btnSpecialPackReward;

	[SerializeField]
	private BannerDialog _prefabDialogPackBanner;

	[SerializeField]
	private GameObject _objUnrestrictedPrereleaseLayoutRoot;

	[SerializeField]
	private UIButton _btnUnrestrictedPrereleasePurchaseRewards;

	[SerializeField]
	private UILabel _labelUnrestrictedPrereleaseRemainTime;

	[SerializeField]
	private UILabel _labelUnrestrictedPrereleasePurchaseCount;

	[SerializeField]
	private UITexture _bonusPosterTexture;

	[SerializeField]
	private GameObject _preReleasePointRoot;

	[SerializeField]
	private UIGauge _preReleasePointGauge;

	[SerializeField]
	private UILabel _preReleasePointLabel;

	[SerializeField]
	private GameObject _appealImage;

	[SerializeField]
	private UITexture _appealTexture;

	private DialogBase _dialogPackBanner;

	private CardDetailUI _cardDetail;

	private TimerMgr _timerManager;

	private RepeatTimer _currentTimer;

	private Action<PackConfig, PackChildGachaInfo> _onClickPurchaseButton;

	private Action<PackConfig> _onClickExchangePackPoint;

	private List<string> _packBannerResources = new List<string>();

	public void SetTimer(TimerMgr timer)
	{
		_timerManager = timer;
	}

	public void SetCardDetailDialog(CardDetailUI cardDetail)
	{
		_cardDetail = cardDetail;
	}

	public void SetOnClickPurchaseButton(Action<PackConfig, PackChildGachaInfo> onClickPurchase)
	{
		_onClickPurchaseButton = onClickPurchase;
	}

	public void SetOnClickExchangePackPoint(Action<PackConfig> onClickExchange)
	{
		_onClickExchangePackPoint = onClickExchange;
	}

	public void SetToGrayRateButton(bool isGary)
	{
		UIManager.SetObjectToGrey(_rateButton.gameObject, isGary);
	}

	public void SetTutorialTicketPurchasebutton()
	{
		MyPageMenu.Instance.SetGuideEffect(_layoutPurchaseTicketButton.PurchaseButtonTransform, Vector3.zero, -45f);
	}

	public void UpdateRupyCount(int rupyCount)
	{
		_layoutPurchaseRupyButton.SetHaveItemLabel(rupyCount);
	}

	public void UpdateCrystalCount(int crystalCount)
	{
		_layoutPurchaseCrystalButton.SetHaveItemLabel(crystalCount);
	}

	public void ShowPackLayout(PackConfig packConfig, List<string> resourceList)
	{
		HidePackLayoutObject(packConfig.IsUseLongPoster);
		SetPackLayoutTexture(packConfig);
		SetEventPackInfo(packConfig);
		if (packConfig.IsPrerelease)
		{
			ShowPrereleaseLayout(packConfig);
			return;
		}
		if (packConfig.IsLegendCardPack)
		{
			ShowLegendLayout(packConfig, resourceList);
			return;
		}
		if (packConfig.IsSpecialCardPack)
		{
			ShowSpecialLayout(packConfig);
			return;
		}
		if (packConfig.IsRotationStarterCardPack)
		{
			ShowRotationStarterLayout(packConfig, resourceList);
			return;
		}
		ShowStandardLayout(packConfig, resourceList);
		if (packConfig.IsNeedRemainTime)
		{
			UpdateDetailString(packConfig);
		}
		if (packConfig.IsShowAppealImage)
		{
			_appealImage.SetActive(value: true);
			ResourcesManager resourcesManager = Toolbox.ResourcesManager;
			string path = $"card_pack_{packConfig.PackId}_poster_sub";
			string assetTypePath = resourcesManager.GetAssetTypePath(path, ResourcesManager.AssetLoadPathType.ShopCardPack, isfetch: true);
			_appealTexture.mainTexture = resourcesManager.LoadObject(assetTypePath) as Texture;
		}
	}

	private void HidePackLayoutObject(bool isLongPoster)
	{
		_labelPackDescription.gameObject.SetActive(value: false);
		_labelSpecialPackDescription.gameObject.SetActive(value: false);
		_packPosterTexture.gameObject.SetActive(!isLongPoster);
		_packPosterLegendPack.gameObject.SetActive(isLongPoster);
		_layoutPurchaseRupyButton.SetActiveLayout(isActive: false);
		_layoutPurchaseTicketButton.SetActiveLayout(isActive: false);
		_layoutPurchaseDailyButton.SetActivePurchaseButton(isActive: false);
		_layoutPurchaseDailyButton.SetRibbonActive(active: false);
		_layoutPurchaseCrystalButton.SetActiveLayout(isActive: false);
		_layoutPurchaseCrystalButton.SetRibbonActive(active: false);
		_layoutPurchaseFree10PacksButton.SetActiveLayout(isActive: false);
		_layoutPurchaseFree10PacksButton.SetIconActive(active: false, string.Empty);
		_layoutPurchaseFree10PacksButton.SetRemainCountRootVisible(visible: true);
		_layoutPurchaseFree10PacksButton.SetFreePackApealTextVisible(visible: false);
		_layoutPurchaseStepupButton.SetActivePurchaseButton(isActive: false);
		_bonusPosterTexture.gameObject.SetActive(value: false);
		_layoutPurchaseCrystalButton.SetPurchasedVisible(visible: false);
		_layoutPurchaseRupyButton.SetPurchasedVisible(visible: false);
		_layoutPurchaseTicketButton.SetPurchasedVisible(visible: false);
		_layoutPurchaseCrystalButton.SetPurchasedLabel("Shop_0100");
		_layoutPurchaseRupyButton.SetPurchasedLabel("Shop_0100");
		_layoutPurchaseTicketButton.SetPurchasedLabel("Shop_0100");
		_objPrereleaseLayoutRoot.SetActive(value: false);
		_objUnrestrictedPrereleaseLayoutRoot.SetActive(value: false);
		_preReleasePointRoot.SetActive(value: false);
		_packPointLayout.SetActivePackPointLayout(isActive: false);
		_btnSpecialPackReward.gameObject.SetActive(value: false);
		_appealImage.SetActive(value: false);
	}

	private void SetEventPackInfo(PackConfig packConfig)
	{
		_rateButton.onClick.Clear();
		_rateButton.onClick.Add(new EventDelegate(delegate
		{
			OnBtnShowGachaRate(packConfig);
		}));
		UIEventListener.Get(_labelSpecialPackDescription.gameObject).onClick = delegate
		{
			OpenPackBannerDialog(packConfig);
		};
		if (_currentTimer != null)
		{
			_timerManager.Remove(_currentTimer);
		}
		UIEventListener.Get(_packPosterLegendPack.gameObject).onClick = delegate
		{
			OpenPackBannerDialog(packConfig);
		};
		UIEventListener.Get(_packPosterTexture.gameObject).onClick = delegate
		{
			OpenPackBannerDialog(packConfig);
		};
	}

	private void SetPackLayoutTexture(PackConfig packConfig)
	{
		ResourcesManager resourcesManager = Toolbox.ResourcesManager;
		if (packConfig.IsSpecialLayout || packConfig.IsPrerelease)
		{
			if (packConfig.IsUseLongPoster)
			{
				_packPosterLegendPack.mainTexture = resourcesManager.LoadObject(packConfig.GetPackPosterTexturePath(isFetch: true)) as Texture;
			}
			else
			{
				_packPosterTexture.mainTexture = resourcesManager.LoadObject(packConfig.GetPackPosterTexturePath(isFetch: true)) as Texture;
				_bonusPosterTexture.mainTexture = resourcesManager.LoadObject(packConfig.GetPackBounsPosterTexturePath(isFetch: true)) as Texture;
				_bonusPosterTexture.gameObject.SetActive(value: true);
			}
		}
		else
		{
			_packPosterTexture.mainTexture = resourcesManager.LoadObject(packConfig.GetPackPosterTexturePath(isFetch: true)) as Texture;
		}
		_packTitleTexture.mainTexture = resourcesManager.LoadObject(packConfig.GetPackTitleLogoTexturePath(isFetch: true)) as Texture;
		if (!packConfig.IsSpecialCardPack)
		{
			_headLineTicketTexture.mainTexture = resourcesManager.LoadObject(packConfig.GetPackIconTexturePath(isFetch: true)) as Texture;
		}
	}

	private void OpenPackBannerDialog(PackConfig packConfig)
	{
		List<string> packBannerResources = GetPackBannerResources(packConfig);
		if (packBannerResources.Count > 0)
		{
			UIManager.GetInstance().createInSceneCenterLoading();
			Toolbox.ResourcesManager.StartCoroutine_LoadAssetGroupAsync(packBannerResources, delegate
			{
				CreatePackBannerDialog(packConfig);
				UIManager.GetInstance().closeInSceneCenterLoading();
			});
		}
		else
		{
			CreatePackBannerDialog(packConfig);
		}
	}

	private List<string> GetPackBannerResources(PackConfig packConfig)
	{
		ResourcesManager resourcesManager = Toolbox.ResourcesManager;
		List<PackBannerData> listPackBanner = packConfig.ListPackBanner;
		List<string> list = new List<string>();
		for (int i = 0; i < listPackBanner.Count; i++)
		{
			string assetTypePath = resourcesManager.GetAssetTypePath(listPackBanner[i].BannerFileName, ResourcesManager.AssetLoadPathType.ShopCardPack);
			if (!_packBannerResources.Contains(assetTypePath))
			{
				list.Add(assetTypePath);
			}
		}
		_packBannerResources.AddRange(list);
		return list;
	}

	private void CreatePackBannerDialog(PackConfig packConfig)
	{
		List<PackBannerData> listPackBanner = packConfig.ListPackBanner;
		if (listPackBanner.Count <= 0 || Data.Load.data._userTutorial.TutorialStep == 41 || _dialogPackBanner != null || packConfig.IsSpecialCardPack)
		{
			return;
		}
		List<string> list = new List<string>();
		foreach (PackBannerData item in listPackBanner)
		{
			list.Add(item.BannerTitle);
		}
		_dialogPackBanner = UIManager.GetInstance().CreateDialogClose();
		_dialogPackBanner.SetSize(DialogBase.Size.M);
		_dialogPackBanner.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		_dialogPackBanner.SetPanelDepth(610);
		BannerDialog bannerDialog = UnityEngine.Object.Instantiate(_prefabDialogPackBanner);
		_dialogPackBanner.SetObj(bannerDialog.gameObject);
		List<Texture> list2 = new List<Texture>();
		for (int i = 0; i < listPackBanner.Count; i++)
		{
			list2.Add(Toolbox.ResourcesManager.LoadObject(Toolbox.ResourcesManager.GetAssetTypePath(listPackBanner[i].BannerFileName, ResourcesManager.AssetLoadPathType.ShopCardPack, isfetch: true)) as Texture);
		}
		bannerDialog.Init(list2, list, _dialogPackBanner);
	}

	public void ClearPackBannerResources()
	{
		Toolbox.ResourcesManager.RemoveAssetGroup(_packBannerResources);
		_packBannerResources.Clear();
	}

	private void OnBtnShowGachaRate(PackConfig packConfig)
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
		CheckTimeSlipRotationPeriodTask task = new CheckTimeSlipRotationPeriodTask();
		StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			UIManager.GetInstance().WebViewHelper.OpenGachaRateWebView(packConfig.PackId, (int)packConfig.Category);
		}));
	}

	private void ShowPurchaseRewardDialog(List<PurchaseRewardInfo> purchaseRewardList)
	{
		_cardDetail.IsShowFlavorTextButton = false;
		_cardDetail.IsShowVoiceButton = false;
		_cardDetail.IsShowEvolutionButton = false;
		DialogBase dialogBase = PurchaseRewardDialog.Create(purchaseRewardList, _cardDetail, useLargeDetailDialog: true, PurchaseRewardDialog.Layout.NORMAL, null, null, isPaging: true);
		dialogBase.OnClose = (Action)Delegate.Combine(dialogBase.OnClose, (Action)delegate
		{
			_cardDetail.IsShowFlavorTextButton = true;
			_cardDetail.IsShowVoiceButton = true;
			_cardDetail.IsShowEvolutionButton = true;
		});
		dialogBase.SetLayer("MyPage");
		dialogBase.SetDepthAndSortingOrder(140, 2);
	}

	private void ShowStandardLayout(PackConfig packConfig, List<string> resourceList)
	{
		SetStanderdInfoText(packConfig.Description);
		bool flag = false;
		for (int i = 0; i < packConfig.ChildGachaInfoList.Count; i++)
		{
			PackChildGachaInfo gachaInfo = packConfig.ChildGachaInfoList[i];
			switch (gachaInfo.PackType)
			{
			case GachaUI.CardPackType.DAILY:
				if (flag)
				{
					break;
				}
				_layoutPurchaseCrystalButton.SetActiveLayout(isActive: true);
				if (!gachaInfo.IsDailySingle)
				{
					_layoutPurchaseDailyButton.SetActivePurchaseButton(isActive: false);
					_layoutPurchaseCrystalButton.SetActivePurchaseButton(isActive: true);
					if (packConfig.GachaPointData != null && gachaInfo.OverrideIncreaseGachaPoint > packConfig.GachaPointData.IncreaseGachaPoint)
					{
						_layoutPurchaseCrystalButton.SetRibbonActive(active: true);
					}
					break;
				}
				_layoutPurchaseDailyButton.SetBuyCostLabel(gachaInfo.Cost);
				_layoutPurchaseDailyButton.SetActivePurchaseButton(isActive: true);
				_layoutPurchaseDailyButton.SetToGrayPurchaseButton(isDisable: false);
				_layoutPurchaseDailyButton.SetOnClickPurchaseButton(delegate
				{
					_onClickPurchaseButton(packConfig, gachaInfo);
				});
				_layoutPurchaseCrystalButton.SetActivePurchaseButton(isActive: false);
				if (packConfig.GachaPointData != null && gachaInfo.OverrideIncreaseGachaPoint > packConfig.GachaPointData.IncreaseGachaPoint)
				{
					_layoutPurchaseDailyButton.SetRibbonActive(active: true);
				}
				break;
			case GachaUI.CardPackType.CRYSTAL_MULTI:
				if (!flag)
				{
					_layoutPurchaseCrystalButton.SetActiveLayout(isActive: true);
					_layoutPurchaseCrystalButton.SetBuyCostLabel(gachaInfo.Cost, "Shop_0058");
					_layoutPurchaseCrystalButton.SetToGrayPurchaseButton(isDisable: false);
					_layoutPurchaseCrystalButton.SetOnClickPurchaseButton(delegate
					{
						_onClickPurchaseButton(packConfig, gachaInfo);
					});
				}
				break;
			case GachaUI.CardPackType.TICKET_MULTI:
				_layoutPurchaseTicketButton.SetActiveLayout(isActive: true);
				_layoutPurchaseTicketButton.SetActivePurchaseButton(isActive: true);
				_layoutPurchaseTicketButton.LayoutLocalPosition = DEFAULT_PACK_TICKET_POSITION;
				_layoutPurchaseTicketButton.SetHaveItemLabel(gachaInfo.CostGoodsCount);
				_layoutPurchaseTicketButton.SetBuyCostLabel(gachaInfo.Cost, "Shop_0057");
				if (gachaInfo.CostGoodsCount >= gachaInfo.Cost)
				{
					_layoutPurchaseTicketButton.SetToGrayPurchaseButton(isDisable: false);
					_layoutPurchaseTicketButton.SetOnClickPurchaseButton(delegate
					{
						_onClickPurchaseButton(packConfig, gachaInfo);
					});
				}
				else
				{
					_layoutPurchaseTicketButton.SetToGrayPurchaseButton(isDisable: true);
				}
				break;
			case GachaUI.CardPackType.RUPY_MULTI:
				_layoutPurchaseRupyButton.SetActiveLayout(isActive: true);
				_layoutPurchaseRupyButton.SetActivePurchaseButton(isActive: true);
				_layoutPurchaseRupyButton.SetBuyCostLabel(gachaInfo.Cost, "Shop_0059");
				if (PlayerStaticData.UserRupyCount >= gachaInfo.Cost)
				{
					_layoutPurchaseRupyButton.SetToGrayPurchaseButton(isDisable: false);
					_layoutPurchaseRupyButton.SetOnClickPurchaseButton(delegate
					{
						_onClickPurchaseButton(packConfig, gachaInfo);
					});
				}
				else
				{
					_layoutPurchaseRupyButton.SetToGrayPurchaseButton(isDisable: true);
				}
				break;
			case GachaUI.CardPackType.FREE_PACKS:
			case GachaUI.CardPackType.FREE_PACK_WITH_SKIN:
			{
				flag = true;
				_layoutPurchaseCrystalButton.SetActiveLayout(isActive: false);
				_layoutPurchaseDailyButton.SetActivePurchaseButton(isActive: false);
				_layoutPurchaseFree10PacksButton.SetActiveLayout(isActive: true);
				_layoutPurchaseFree10PacksButton.SetActivePurchaseButton(isActive: true);
				_layoutPurchaseFree10PacksButton.SetToGrayPurchaseButton(isDisable: false);
				_layoutPurchaseFree10PacksButton.SetOnClickPurchaseButton(delegate
				{
					_onClickPurchaseButton(packConfig, gachaInfo);
				});
				_layoutPurchaseFree10PacksButton.SetHaveItemLabel(gachaInfo.AvailableCount / gachaInfo.PackCountBuyPer);
				_layoutPurchaseFree10PacksButton.SetBuyCostLabel(gachaInfo.PackCountBuyPer, (gachaInfo.PackCountBuyPer == 1) ? "Shop_0222" : "Shop_0233");
				bool flag2 = packConfig.Category == PackCategory.FreePackLeaderSkin || packConfig.Category == PackCategory.LeaderSkinPack || packConfig.Category == PackCategory.LegendAndLeaderSkinSinglePack;
				_layoutPurchaseFree10PacksButton.SetRemainLabelVisible(!flag2);
				_layoutPurchaseFree10PacksButton.SetFreePackLeaderSkinVisible(flag2);
				if (packConfig.Category == PackCategory.LeaderSkinPack)
				{
					string freePackLeaderSkinText = Data.SystemText.Get("Shop_0251");
					_layoutPurchaseFree10PacksButton.SetFreePackLeaderSkinText(freePackLeaderSkinText);
				}
				else if (packConfig.Category == PackCategory.LegendAndLeaderSkinSinglePack)
				{
					string freePackLeaderSkinText2 = Data.SystemText.Get("Shop_0252");
					_layoutPurchaseFree10PacksButton.SetFreePackLeaderSkinText(freePackLeaderSkinText2);
				}
				_layoutPurchaseFree10PacksButton.SetIconActive(gachaInfo.IsShowAnniversaryIcon, gachaInfo.AnniversaryIconSpriteName);
				_layoutPurchaseFree10PacksButton.SetPinkRibbon(gachaInfo.IsShowPinkRibbon);
				_layoutPurchaseFree10PacksButton.SetWinterSprite(gachaInfo.IsShowWinterUI);
				_free10PackCentering.Reposition();
				_free10PackEffect.Setup("cmn_frame_glow_1", 0, resourceList);
				break;
			}
			}
		}
		if (packConfig.IsUsePackPointLayout)
		{
			_packPointLayout.SetPackPointLayout(packConfig, delegate
			{
				_onClickExchangePackPoint(packConfig);
			});
		}
	}

	private void SetStanderdInfoText(string packDescription)
	{
		_labelPackDescription.gameObject.SetActive(value: true);
		_labelPackDescription.text = packDescription;
	}

	private void ShowPrereleaseLayout(PackConfig packConfig)
	{
		PrereleasePurchaseInfo prereleasePurchaseInfo = packConfig.PrereleasePurchaseInfo;
		_preReleasePointRoot.SetActive(value: true);
		_ = packConfig.GachaPointData;
		_preReleasePointGauge.Value = (float)prereleasePurchaseInfo.PreReleasePointCurent / (float)prereleasePurchaseInfo.PreReleasePointLimit;
		_preReleasePointLabel.text = prereleasePurchaseInfo.PreReleasePointCurent + "/" + prereleasePurchaseInfo.PreReleasePointLimit;
		_noLimitPrereleaseRoot.SetActive(!prereleasePurchaseInfo.IsCountLimitedPrerelease);
		if (prereleasePurchaseInfo.IsCountLimitedPrerelease)
		{
			_objPrereleaseLayoutRoot.SetActive(value: true);
		}
		else
		{
			_objUnrestrictedPrereleaseLayoutRoot.SetActive(value: true);
			if (packConfig.IsUsePackPointLayout)
			{
				_packPointLayout.SetPackPointLayout(packConfig, delegate
				{
					_onClickExchangePackPoint(packConfig);
				});
			}
		}
		SetPrereleasePurchaseButton(packConfig, prereleasePurchaseInfo, packConfig.ChildGachaInfoList[0]);
		SetPrereleasePurchaseRewards(prereleasePurchaseInfo);
		SetPrereleaseInfoText(prereleasePurchaseInfo, packConfig.Description);
	}

	private void SetPrereleasePurchaseButton(PackConfig packConfig, PrereleasePurchaseInfo purchaseInfo, PackChildGachaInfo gachaInfo)
	{
		_layoutPurchaseCrystalButton.SetActiveLayout(isActive: true);
		_layoutPurchaseCrystalButton.SetBuyCostLabel(gachaInfo.Cost, "Shop_0058");
		ShowStandardLayout(packConfig, null);
		_layoutPurchaseCrystalButton.SetPurchasedLabel("Shop_0206");
		_layoutPurchaseRupyButton.SetPurchasedLabel("Shop_0206");
		_layoutPurchaseTicketButton.SetPurchasedLabel("Shop_0206");
		if (purchaseInfo.TicketRupyCountRemain == 0)
		{
			_layoutPurchaseRupyButton.SetPurchasedMode(isPurchased: true);
			_layoutPurchaseTicketButton.SetPurchasedMode(isPurchased: true);
		}
		else
		{
			_layoutPurchaseRupyButton.SetPurchasedMode(isPurchased: false);
			_layoutPurchaseTicketButton.SetPurchasedMode(isPurchased: false);
		}
		if (!purchaseInfo.IsCountLimitedPrerelease || purchaseInfo.GetAbleBuyPackNum() > 0)
		{
			_layoutPurchaseCrystalButton.SetPurchasedMode(isPurchased: false);
			_layoutPurchaseCrystalButton.SetToGrayPurchaseButton(isDisable: false);
			_layoutPurchaseCrystalButton.SetOnClickPurchaseButton(delegate
			{
				_onClickPurchaseButton(packConfig, gachaInfo);
			});
		}
		else
		{
			_layoutPurchaseCrystalButton.SetPurchasedMode(isPurchased: true);
		}
	}

	private void SetPrereleasePurchaseRewards(PrereleasePurchaseInfo purchaseInfo)
	{
		UIButton uIButton = (purchaseInfo.IsCountLimitedPrerelease ? _btnPrereleasePurchaseRewards : _btnUnrestrictedPrereleasePurchaseRewards);
		if (purchaseInfo.RewardsList.Count == 0)
		{
			uIButton.gameObject.SetActive(value: false);
			return;
		}
		uIButton.onClick.Clear();
		uIButton.onClick.Add(new EventDelegate(delegate
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
			ShowPurchaseRewardDialog(purchaseInfo.RewardsList);
		}));
	}

	private void SetPrereleaseInfoText(PrereleasePurchaseInfo purchaseInfo, string packDescription)
	{
		UILabel obj = (purchaseInfo.IsCountLimitedPrerelease ? _labelPrereleaseRemainTime : _labelUnrestrictedPrereleaseRemainTime);
		UILabel uILabel = (purchaseInfo.IsCountLimitedPrerelease ? _labelPrereleasePurchaseCount : _labelUnrestrictedPrereleasePurchaseCount);
		string showText = purchaseInfo.RemainTime.GetShowText("Shop_0179", "Shop_0178", "Shop_0177");
		_labelPackDescription.gameObject.SetActive(value: true);
		_labelPackDescription.text = packDescription.Replace("{remaining_purchase_time}", showText);
		obj.text = purchaseInfo.RemainTime.GetShowText("Shop_0179", "Shop_0178", "Shop_0177");
		if (purchaseInfo.IsCountLimitedPrerelease)
		{
			uILabel.text = Data.SystemText.Get("Shop_0181", purchaseInfo.CurrentCount.ToString(), purchaseInfo.LimitCount.ToString());
			_prereleaseRemainTimeRoot.SetActive(value: false);
		}
		else
		{
			uILabel.text = Data.SystemText.Get("Shop_0046", purchaseInfo.CurrentCount.ToString());
		}
	}

	private void ShowSpecialLayout(PackConfig packConfig)
	{
		UpdateDetailString(packConfig);
		SetSpecialPurchaseButton(packConfig, packConfig.ChildGachaInfoList[0], packConfig.OpenCountLimit > packConfig.OpenCount);
		SetSpecialPurchaseRewards(packConfig);
	}

	private static string ReplaceDetailString(PackConfig packConfig)
	{
		string description = packConfig.Description;
		if (!packConfig.IsNeedRemainTime)
		{
			return description;
		}
		int second = packConfig.RemainTime.Second;
		string newValue;
		if (second < 3600)
		{
			int num = ((second > 0) ? (second / 60 + 1) : 0);
			newValue = Data.SystemText.Get("Shop_0147", num.ToString());
		}
		else if (second < 86400)
		{
			int num2 = second / 3600;
			newValue = Data.SystemText.Get("Shop_0146", num2.ToString());
		}
		else
		{
			int num3 = second / 86400;
			newValue = Data.SystemText.Get("Shop_0145", num3.ToString());
		}
		description = description.Replace("{remaining_purchase_time}", newValue);
		int num4 = (packConfig.OpenCountLimit - packConfig.OpenCount) / 10;
		if (GachaUI.IsTsStepupPackId(packConfig.PackId))
		{
			num4 = packConfig.RemainStepupOpenCount;
		}
		return string.Format(description, num4);
	}

	private void UpdateDetailString(PackConfig packConfig)
	{
		if (_currentTimer != null)
		{
			_timerManager.Remove(_currentTimer);
		}
		RepeatTimer repeatTimer = new RepeatTimer((float)(60.0 - packConfig.RemainTime.NowUnixTime % 60.0), delegate
		{
			UpdateDetailString(packConfig);
		});
		_timerManager.Add(repeatTimer);
		_currentTimer = repeatTimer;
		if (packConfig.Category == PackCategory.LeaderSkinPack)
		{
			_labelPackDescription.gameObject.SetActive(value: true);
			_labelSpecialPackDescription.gameObject.SetActive(value: false);
			_labelPackDescription.text = ReplaceDetailString(packConfig);
		}
		else
		{
			_labelSpecialPackDescription.gameObject.SetActive(value: true);
			_labelPackDescription.gameObject.SetActive(value: false);
			_labelSpecialPackDescription.text = ReplaceDetailString(packConfig);
		}
	}

	private void SetSpecialPurchaseButton(PackConfig packConfig, PackChildGachaInfo gachaInfo, bool isPurchasable)
	{
		_layoutPurchaseCrystalButton.SetActiveLayout(isActive: true);
		if (isPurchasable)
		{
			if (GachaUI.IsTsStepupPackId(packConfig.PackId))
			{
				_layoutPurchaseCrystalButton.SetActivePurchaseButton(isActive: false);
				_layoutPurchaseStepupButton.SetActivePurchaseButton(isActive: true);
				_layoutPurchaseStepupButton.SetToGrayPurchaseButton(isDisable: false);
				_layoutPurchaseStepupButton.SetOnClickPurchaseButton(delegate
				{
					_onClickPurchaseButton(packConfig, gachaInfo);
				});
				int num = packConfig.TotalStepupOpenCount - packConfig.RemainStepupOpenCount + 1;
				_layoutPurchaseStepupButton.SetInButtonText(Data.SystemText.Get("Shop_0186", num.ToString()));
			}
			else
			{
				_layoutPurchaseCrystalButton.SetActivePurchaseButton(isActive: true);
				_layoutPurchaseCrystalButton.SetToGrayPurchaseButton(isDisable: false);
				_layoutPurchaseCrystalButton.SetOnClickPurchaseButton(delegate
				{
					_onClickPurchaseButton(packConfig, gachaInfo);
				});
				_layoutPurchaseStepupButton.SetActivePurchaseButton(isActive: false);
			}
		}
		else
		{
			_layoutPurchaseCrystalButton.SetPurchasedVisible(visible: true);
			_layoutPurchaseCrystalButton.SetActivePurchaseButton(isActive: false);
			_layoutPurchaseStepupButton.SetActivePurchaseButton(isActive: false);
		}
		int cost = gachaInfo.Cost * 10;
		_layoutPurchaseCrystalButton.SetBuyCostLabel(cost, "Shop_0112");
	}

	private void SetSpecialPurchaseRewards(PackConfig packConfig)
	{
		if (packConfig.IsExistSpecialPackPurchaseRewards && packConfig.SpecialPackRewardsList.Count != 0)
		{
			_btnSpecialPackReward.gameObject.SetActive(value: true);
			_btnSpecialPackReward.onClick.Clear();
			_btnSpecialPackReward.onClick.Add(new EventDelegate(delegate
			{
				GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
				ShowPurchaseRewardDialog(packConfig.SpecialPackRewardsList);
			}));
		}
	}

	private void ShowLegendLayout(PackConfig packConfig, List<string> resourceList)
	{
		SetLegendInfoText(packConfig.Description);
		PackChildGachaInfo packChildGachaInfo = packConfig.CanFreeBuyInfo();
		if (packChildGachaInfo != null)
		{
			SetFreeLegendTicketButton(packConfig, packChildGachaInfo, resourceList);
		}
		else
		{
			SetLegendPurchaseButton(packConfig, packConfig.ChildGachaInfoList[0]);
		}
	}

	private void SetLegendPurchaseButton(PackConfig packConfig, PackChildGachaInfo gachaInfo)
	{
		_layoutPurchaseFree10PacksButton.SetActiveLayout(isActive: false);
		_layoutPurchaseTicketButton.SetActiveLayout(isActive: true);
		_layoutPurchaseTicketButton.SetPurchasedMode(isPurchased: false);
		_layoutPurchaseTicketButton.LayoutLocalPosition = LEGEND_PACK_TICKET_POSITION;
		_layoutPurchaseTicketButton.SetHaveItemLabel(gachaInfo.CostGoodsCount);
		_layoutPurchaseTicketButton.SetBuyCostLabel(gachaInfo.Cost, "Shop_0057");
		if (gachaInfo.CostGoodsCount >= gachaInfo.Cost)
		{
			_layoutPurchaseTicketButton.SetToGrayPurchaseButton(isDisable: false);
			_layoutPurchaseTicketButton.SetOnClickPurchaseButton(delegate
			{
				_onClickPurchaseButton(packConfig, gachaInfo);
			});
		}
		else
		{
			_layoutPurchaseTicketButton.SetToGrayPurchaseButton(isDisable: true);
		}
	}

	private void SetFreeLegendTicketButton(PackConfig packConfig, PackChildGachaInfo gachaInfo, List<string> resourceList)
	{
		_layoutPurchaseTicketButton.SetActiveLayout(isActive: false);
		_layoutPurchaseFree10PacksButton.SetActiveLayout(isActive: true);
		_layoutPurchaseFree10PacksButton.SetRemainCountRootVisible(visible: false);
		_layoutPurchaseFree10PacksButton.SetPinkRibbon(gachaInfo.IsShowPinkRibbon);
		_layoutPurchaseFree10PacksButton.SetActivePurchaseButton(isActive: true);
		_layoutPurchaseFree10PacksButton.SetToGrayPurchaseButton(isDisable: false);
		_layoutPurchaseFree10PacksButton.SetOnClickPurchaseButton(delegate
		{
			_onClickPurchaseButton(packConfig, gachaInfo);
		});
		_layoutPurchaseFree10PacksButton.SetFreePackLeaderSkinVisible(visible: false);
		_layoutPurchaseFree10PacksButton.SetRemainLabelVisible(visible: true);
		_layoutPurchaseFree10PacksButton.SetHaveItemLabel(gachaInfo.AvailableCount / gachaInfo.PackCountBuyPer);
		_layoutPurchaseFree10PacksButton.SetBuyCostLabel(gachaInfo.PackCountBuyPer, (gachaInfo.PackCountBuyPer == 1) ? "Shop_0222" : "Shop_0233");
		_layoutPurchaseFree10PacksButton.SetIconActive(gachaInfo.IsShowAnniversaryIcon, gachaInfo.AnniversaryIconSpriteName);
		_free10PackCentering.Reposition();
		_free10PackEffect.Setup("cmn_frame_glow_1", 0, resourceList);
	}

	private void SetLegendInfoText(string packDescription)
	{
		_labelSpecialPackDescription.gameObject.SetActive(value: true);
		_labelSpecialPackDescription.text = packDescription;
	}

	private void ShowRotationStarterLayout(PackConfig packConfig, List<string> resourceList)
	{
		PackChildGachaInfo packChildGachaInfo = packConfig.CanFreeBuyInfo();
		_layoutPurchaseFree10PacksButton.SetActiveLayout(isActive: false);
		_layoutPurchaseFree10PacksButton.SetPinkRibbon(packConfig.ChildGachaInfoList[0].IsShowPinkRibbon);
		if (packChildGachaInfo == null)
		{
			SetRotationStarterButton(packConfig, packConfig.ChildGachaInfoList[0], packConfig.OpenCountLimit > packConfig.OpenCount);
		}
		else
		{
			SetFreeRotationStarter(packConfig, packChildGachaInfo, resourceList);
		}
		SetRotationStarterInfoText(packConfig);
	}

	private void SetRotationStarterInfoText(PackConfig packConfig)
	{
		_labelSpecialPackDescription.gameObject.SetActive(value: true);
		int num = (packConfig.OpenCountLimit - packConfig.OpenCount) / 10;
		_labelSpecialPackDescription.text = string.Format(packConfig.Description, num);
	}

	private void SetFreeRotationStarter(PackConfig packConfig, PackChildGachaInfo gachaInfo, List<string> resourceList)
	{
		_layoutPurchaseCrystalButton.SetActiveLayout(isActive: false);
		_layoutPurchaseFree10PacksButton.SetActiveLayout(isActive: true);
		_layoutPurchaseFree10PacksButton.SetRemainCountRootVisible(visible: false);
		_layoutPurchaseFree10PacksButton.SetActivePurchaseButton(isActive: true);
		_layoutPurchaseFree10PacksButton.SetToGrayPurchaseButton(isDisable: false);
		_layoutPurchaseFree10PacksButton.SetOnClickPurchaseButton(delegate
		{
			_onClickPurchaseButton(packConfig, gachaInfo);
		});
		_layoutPurchaseFree10PacksButton.SetFreePackLeaderSkinVisible(visible: false);
		_layoutPurchaseFree10PacksButton.SetFreePackApealTextVisible(visible: true);
		_layoutPurchaseFree10PacksButton.SetFreePackApealText(Data.SystemText.Get("Shop_0255", gachaInfo.PackCountBuyPer.ToString()));
		_layoutPurchaseFree10PacksButton.SetBuyCostLabel(gachaInfo.PackCountBuyPer, (gachaInfo.PackCountBuyPer == 1) ? "Shop_0222" : "Shop_0233");
		_free10PackEffect.Setup("cmn_frame_glow_1", 0, resourceList);
	}

	private void SetRotationStarterButton(PackConfig packConfig, PackChildGachaInfo gachaInfo, bool isPurchasable)
	{
		_layoutPurchaseCrystalButton.SetActiveLayout(isActive: true);
		if (isPurchasable)
		{
			_layoutPurchaseCrystalButton.SetActivePurchaseButton(isActive: true);
			_layoutPurchaseCrystalButton.SetToGrayPurchaseButton(isDisable: false);
			_layoutPurchaseCrystalButton.SetOnClickPurchaseButton(delegate
			{
				_onClickPurchaseButton(packConfig, gachaInfo);
			});
			int cost = gachaInfo.Cost * 10;
			_layoutPurchaseCrystalButton.SetBuyCostLabel(cost, "Shop_0112");
		}
		else
		{
			_layoutPurchaseCrystalButton.SetPurchasedVisible(visible: true);
			_layoutPurchaseCrystalButton.SetActivePurchaseButton(isActive: false);
		}
	}
}
