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

public class MyPageItemShop : MyPageItem
{
	private const float SET_ACTIVE_APPEAL_OBJ_DELAY_TIME = 0.15f;

	[SerializeField]
	private ShopSupplyCardPanel _supplyCardPanel;

	[SerializeField]
	private ShopPanelAppealItem _supplyAppealItem;

	[SerializeField]
	private MyPageCardPanel _cardPackCardPanel;

	[SerializeField]
	private ShopPanelAppealItem _cardPackAppealItem;

	[SerializeField]
	private MyPageCardPanel _crystalCardPanel;

	[SerializeField]
	private UIButton _supplyButton;

	[SerializeField]
	private UIButton _buyCardSleeveButton;

	[SerializeField]
	private ShopPanelAppealItem _sleeveAppealItem;

	[SerializeField]
	private UIButton _buyLeaderSkinButton;

	[SerializeField]
	private ShopPanelAppealItem _skinAppealItem;

	[SerializeField]
	private UIButton _buyItemButton;

	[SerializeField]
	private DialogItemPurchase _itemPurchaseDialog;

	[SerializeField]
	private SpotCardExchangeDialog _dialogSpotCardExchange;

	[SerializeField]
	private GameObject _supplyMenuRoot;

	[SerializeField]
	private UIButton _cardButton;

	[SerializeField]
	private GameObject _cardMenuRoot;

	[SerializeField]
	private UIButton _buyCardPackButton;

	[SerializeField]
	private ShopPanelAppealItem _packAppealItem;

	[SerializeField]
	private UIButton _buyDeckButton;

	[SerializeField]
	private ShopPanelAppealItem _deckAppealItem;

	[SerializeField]
	private UIButton _exchangeSpotCardButton;

	[SerializeField]
	private GameObject _cardPackMenuRoot;

	[SerializeField]
	private UIButton _crystalButton;

	[SerializeField]
	private UILabel _supplyMaintenanceBaseLabel;

	[SerializeField]
	private MyPageShopCrystalApeal _crystalAppeal;

	[SerializeField]
	private GameObject _cardBuyCampaignRoot;

	[SerializeField]
	private UILabel _cardBuyCampaignLabel;

	private CardPanelMaintenancePlate _buyCardSleeveMaintenancePlate;

	private CardPanelMaintenancePlate _buyLeaderSkinMaintenancePlate;

	private CardPanelMaintenancePlate _buyItemMaintenancePlate;

	private CardPanelMaintenancePlate _buyCardPackMaintenancePlate;

	private CardPanelMaintenancePlate _buyBuildDeckMaintenancePlate;

	private CardPanelMaintenancePlate _exchangeSpotCardMaintenancePlate;

	private const string SLEEVE_BTN_SPRITE_NAME_BASE = "btn_supply_sleeve";

	private const string SKIN_BTN_SPRITE_NAME_BASE = "btn_supply_skin";

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

	private const int CARD_INDEX_SUPPLY = 0;

	private const int CARD_INDEX_CARD = 1;

	private const int CARD_INDEX_CRYSTAL = 2;

	private bool IsSpecialSleeveMode => Data.MyPageNotifications.data.ShopNotification.AppealSleeve.IsCollaborationPanel;

	private bool IsSpecialSkinMode => Data.MyPageNotifications.data.ShopNotification.AppealLeaderSkin.IsCollaborationPanel;

	public MyPageShopCrystalApeal CrystalAppeal => _crystalAppeal;

	private bool IsTutorial => Data.Load.data._userTutorial.TutorialStep == 41;

	public override void Initialize(MyPageMenu parent)
	{
		base.Initialize(parent);
		_buyCardSleeveButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushBuyCardSleeve();
		}));
		_buyLeaderSkinButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushBuyLeaderSkin();
		}));
		_buyItemButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushBuyItem();
		}));
		_buyCardPackButton.onClick.Add(new EventDelegate(delegate
		{
			OnPusBuyCardPack();
		}));
		_buyDeckButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushBuyBuildDeck();
		}));
		_exchangeSpotCardButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushExchangeSpotCard();
		}));
		SaveDefaultPosition(_cardPackMenuRoot);
		SaveDefaultPosition(_cardPackMenuRoot);
		SaveDefaultPosition(_supplyMenuRoot);
	}

	public override void Show(bool skipCardAnimation = false)
	{
		base.Show(skipCardAnimation);
		_supplyMenuRoot.SetActive(value: false);
		_cardPackMenuRoot.SetActive(value: false);
		RestoreCardPanelPosition();
		StartCardPanelAppearAnimation();
		_supplyButton.onClick.Clear();
		_supplyButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushSupplyButton();
		}));
		_cardButton.onClick.Clear();
		_cardButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushCardButton();
		}));
		RestoreDefaultPosition(_cardPackMenuRoot);
		RestoreDefaultPosition(_supplyMenuRoot);
		if (IsTutorial)
		{
			SetTutorial();
			UIManager.GetInstance()._Footer.SetButtonEnableColorChange(5, btnIsEnable: false);
		}
		ShowCardPanelAppeal();
		UIManager.GetInstance().StartCoroutine(_crystalCardPanel.DisablePanel(Data.SystemText.Get("System_0074")));
		UIManager.GetInstance().StartCoroutine(LoadCardPanelCoroutine());
	}

	private IEnumerator LoadCardPanelCoroutine()
	{
		ShopNotification shopNotification = Data.MyPageNotifications.data.ShopNotification;
		bool flag = shopNotification.AppealSleeve.IsCollaborationPanel || shopNotification.AppealLeaderSkin.IsCollaborationPanel;
		if ((flag && !_supplyCardPanel.IsLoadedSpecialCardPanelResource) || (!flag && !_supplyCardPanel.IsLoadedDefaultCardPanelResource))
		{
			_shopCardPanelResource.Add(_supplyCardPanel.GetResourcePath(isfetch: false));
			yield return Toolbox.ResourcesManager.LoadAssetGroupSync(_shopCardPanelResource, null);
			_supplyCardPanel.AttachCardPanelTexture();
		}
	}

	private void OnDestroy()
	{
		Toolbox.ResourcesManager.RemoveAssetGroup(_shopCardPanelResource);
		_shopCardPanelResource.Clear();
	}

	public override void OnMyPageInfoReceive()
	{
		base.OnMyPageInfoReceive();
		if (IsTutorial)
		{
			SetTutorial();
		}
	}

	private void SetCardPanelTutorialMode()
	{
		UIManager.SetObjectToGrey(_supplyCardPanel.gameObject, b: true);
		UIManager.SetObjectToGrey(_crystalButton.gameObject, b: true);
	}

	private void SetTutorial()
	{
		SetCardPanelTutorialMode();
		UIManager.SetObjectToGrey(base.TopBar.BackButton.gameObject, b: true);
		UIManager.SetObjectToGrey(base.TopBar.BuyCrystalButton.gameObject, b: true);
		base.TopBar.BuyCrystalButton.isEnabled = false;
		Footer footer = UIManager.GetInstance()._Footer;
		for (int i = 0; i < footer._underButtons.Length; i++)
		{
			if (i == 5)
			{
				footer.SetButtonEnableColorChange(i, !base.gameObject.activeInHierarchy);
			}
			else
			{
				footer.SetButtonEnableColorChange(i, btnIsEnable: false);
			}
		}
		if (base.gameObject.activeInHierarchy)
		{
			base.Parent.SetGuideEffect(_cardPackCardPanel.transform, new Vector3(-40f, 0f, 0f), -45f);
		}
	}

	private void OnPushCardButton()
	{
		if (!base.IsCardMoving)
		{
			base.Parent.SetDefaultBackButtonHandler();
			base.CardAnimation.OnClicked(1);
			ShowCardMenu();
			if (IsTutorial)
			{
				base.Parent.SetGuideEffect(_buyCardPackButton.transform, Vector3.zero, -45f);
			}
		}
	}

	private void OnPushSupplyButton()
	{
		if (!IsTutorial && !base.IsCardMoving)
		{
			base.Parent.SetDefaultBackButtonHandler();
			ShowSupplyMenu();
			base.CardAnimation.OnClicked(0);
		}
	}

	private void ShowSupplyMenu()
	{
		base.IsEnableFooterCurrentMenu = true;
		base.Parent.SetBackButtonEnable();
		_supplyButton.onClick.Clear();
		base.TopBar.SetTitleLabel(Data.SystemText.Get("MyPage_0017"));
		SetSpriteSpecialBtn(_buyCardSleeveButton, "btn_supply_sleeve", IsSpecialSleeveMode);
		SetSpriteSpecialBtn(_buyLeaderSkinButton, "btn_supply_skin", IsSpecialSkinMode);
		_supplyAppealItem.DelaySetActiveAppealObj(isActive: false, 0.15f);
		MoveCardPanelLeftPosition(_supplyCardPanel.gameObject);
		FadeOutCardPanelAndNonActive(_cardPackCardPanel);
		FadeOutCardPanelAndNonActive(_crystalCardPanel);
		_supplyMenuRoot.SetActive(value: true);
		AppearAnimationFromRight(_supplyMenuRoot);
		bool isMaintenance = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_SLEEVE_MAINTENANCE);
		bool isMaintenance2 = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_SKIN_MAINTENANCE);
		bool isMaintenance3 = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_ITEM_MAINTENANCE);
		_buyCardSleeveMaintenancePlate = MyPageItem.SetMaintenanceVisible(isMaintenance, _buyCardSleeveButton, _buyCardSleeveMaintenancePlate, _supplyMaintenanceBaseLabel.depth);
		_buyLeaderSkinMaintenancePlate = MyPageItem.SetMaintenanceVisible(isMaintenance2, _buyLeaderSkinButton, _buyLeaderSkinMaintenancePlate, _supplyMaintenanceBaseLabel.depth);
		_buyItemMaintenancePlate = MyPageItem.SetMaintenanceVisible(isMaintenance3, _buyItemButton, _buyItemMaintenancePlate, _supplyMaintenanceBaseLabel.depth);
	}

	private void SetSpriteSpecialBtn(UIButton button, string buttonSpriteNameBase, bool isSpecial)
	{
		button.normalSprite = (isSpecial ? (buttonSpriteNameBase + "_special") : buttonSpriteNameBase);
	}

	public void GoToShopSupply()
	{
		ShowSupplyMenu();
	}

	public void GoToShopCard()
	{
		ShowCardMenu();
	}

	private void OnPushBuyCardSleeve()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.CardSleevePurchasePage);
	}

	private void OnPushBuyLeaderSkin()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.ClassSkinPurchasePage);
	}

	private void OnPushBuyItem()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		_itemPurchaseDialog.CreateItemPurcahseDialog();
	}

	private void ShowCardMenu()
	{
		if (!IsTutorial)
		{
			base.IsEnableFooterCurrentMenu = true;
		}
		base.Parent.SetBackButtonEnable();
		_cardButton.onClick.Clear();
		base.TopBar.SetTitleLabel(Data.SystemText.Get("MyPage_0016"));
		_cardPackAppealItem.DelaySetActiveAppealObj(isActive: false, 0.15f);
		RestoreCardPanelPosition();
		MoveCardPanelLeftPosition(_cardPackCardPanel.gameObject);
		FadeOutCardPanelAndNonActive(_supplyCardPanel);
		FadeOutCardPanelAndNonActive(_crystalCardPanel);
		_cardPackMenuRoot.SetActive(value: true);
		AppearAnimationFromRight(_cardPackMenuRoot);
		bool isMaintenance = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_CARDPACK_MAINTENANCE);
		bool isMaintenance2 = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_BUILDDECK_MAINTENANCE);
		bool isMaintenance3 = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SPOTCARD_EXCHANGE);
		_buyCardPackMaintenancePlate = MyPageItem.SetMaintenanceVisible(isMaintenance, _buyCardPackButton, _buyCardPackMaintenancePlate, _supplyMaintenanceBaseLabel.depth);
		_buyBuildDeckMaintenancePlate = MyPageItem.SetMaintenanceVisible(isMaintenance2, _buyDeckButton, _buyBuildDeckMaintenancePlate, _supplyMaintenanceBaseLabel.depth);
		_exchangeSpotCardMaintenancePlate = MyPageItem.SetMaintenanceVisible(isMaintenance3, _exchangeSpotCardButton, _exchangeSpotCardMaintenancePlate, _supplyMaintenanceBaseLabel.depth);
		if (IsTutorial)
		{
			UIManager.SetObjectToGrey(_buyDeckButton.gameObject, b: true);
			UIManager.SetObjectToGrey(_exchangeSpotCardButton.gameObject, b: true);
			SetCardPanelTutorialMode();
		}
	}

	private void OnPusBuyCardPack()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Gacha, null, new GachaUIParam());
		if (IsTutorial)
		{
			base.Parent.SetGuideEffect(base.Parent.transform, Vector3.zero, 0f);
			base.Parent.FirstGuidEffect.gameObject.SetActive(value: false);
		}
	}

	private void OnPushBuyBuildDeck()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.BuildDeckPurchasePage);
	}

	private void OnPushExchangeSpotCard()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		_dialogSpotCardExchange.CreateSpotCardExchangeDialog();
	}

	private void OnPushBuyCrystal()
	{
	}

	private void ShowCardPanelAppeal()
	{
		if (IsTutorial)
		{
			_supplyAppealItem.SetActiveAppealObj(isActive: false);
			_cardPackAppealItem.SetActiveAppealObj(isActive: false);
			_sleeveAppealItem.SetActiveAppealObj(isActive: false);
			_skinAppealItem.SetActiveAppealObj(isActive: false);
			_packAppealItem.SetActiveAppealObj(isActive: false);
			_deckAppealItem.SetActiveAppealObj(isActive: false);
			_crystalAppeal.gameObject.SetActive(value: false);
			_cardBuyCampaignRoot.SetActive(value: false);
			return;
		}
		bool flag = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_SLEEVE_MAINTENANCE);
		bool flag2 = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_SKIN_MAINTENANCE);
		bool flag3 = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_CARDPACK_MAINTENANCE);
		bool flag4 = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.SHOP_BUILDDECK_MAINTENANCE);
		ShopNotification shopNotification = Data.MyPageNotifications.data.ShopNotification;
		ShopNotification.ShopAppealInfo appeal = PriorizeAppealInfo(new List<ShopNotification.ShopAppealInfo> { shopNotification.AppealSleeve, shopNotification.AppealLeaderSkin });
		_supplyAppealItem.SetAppeal(appeal);
		ShopNotification.ShopAppealInfo appeal2 = PriorizeAppealInfo(new List<ShopNotification.ShopAppealInfo> { shopNotification.AppealCardPack, shopNotification.AppealBuildDeck });
		_cardPackAppealItem.SetAppeal(appeal2);
		_sleeveAppealItem.SetAppeal(shopNotification.AppealSleeve);
		_skinAppealItem.SetAppeal(shopNotification.AppealLeaderSkin);
		_packAppealItem.SetAppeal(shopNotification.AppealCardPack);
		_deckAppealItem.SetAppeal(shopNotification.AppealBuildDeck);
		_supplyAppealItem.SetActiveAppealObj(!flag && !flag2);
		_cardPackAppealItem.SetActiveAppealObj(!flag3 && !flag4);
		_sleeveAppealItem.SetActiveAppealObj(!flag);
		_skinAppealItem.SetActiveAppealObj(!flag2);
		_packAppealItem.SetActiveAppealObj(!flag3);
		_deckAppealItem.SetActiveAppealObj(!flag4);
		if (!flag3 && Prerelease.Status == Prerelease.eStatus.PRE_ROTATION)
		{
			_cardBuyCampaignRoot.SetActive(value: true);
			_cardBuyCampaignLabel.text = Data.SystemText.Get("MyPage_0048", ConvertTime.ToLocal(Prerelease.Instance.EndTime));
			_cardPackAppealItem.SetActiveAppealObj(isActive: false);
		}
		else
		{
			_cardBuyCampaignRoot.SetActive(value: false);
		}
		_crystalAppeal.gameObject.SetActive(value: false);
	}

	private ShopNotification.ShopAppealInfo PriorizeAppealInfo(List<ShopNotification.ShopAppealInfo> appealInfoList)
	{
		List<ShopNotification.ShopAppealInfo> list = appealInfoList.FindAll((ShopNotification.ShopAppealInfo info) => info.NeedsCampaignDisplay);
		if (list.Count > 0)
		{
			return list[0];
		}
		List<ShopNotification.ShopAppealInfo> list2 = appealInfoList.FindAll((ShopNotification.ShopAppealInfo info) => info.RemainTime != null);
		if (list2.Count > 0)
		{
			return list2.FindMin((ShopNotification.ShopAppealInfo info) => info.RemainTime.Second);
		}
		ShopNotification.ShopAppealInfo shopAppealInfo = appealInfoList.Find((ShopNotification.ShopAppealInfo info) => info.IsNew);
		if (shopAppealInfo == null)
		{
			return new ShopNotification.ShopAppealInfo();
		}
		return shopAppealInfo;
	}
}
