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

namespace Wizard.Scripts.Network.Data.TaskData.BuildDeckPurchase;

public class BuildDeckDetailWindow : MonoBehaviour
{
	private const int SUPPLY_TYPE_LABEL_INDEX = 0;

	private const int SUPPLY_NAME_LABEL_INDEX = 1;

	private const int DEPTH_COPY_CONFIRM_DIALOG = 20;

	[SerializeField]
	private BuildDeckProductDetail _buildDeckProductDetail;

	[SerializeField]
	private UILabel _labelProductName;

	[SerializeField]
	private UISprite _spriteClassColorIcon;

	[SerializeField]
	private UILabel _labelDeckCode;

	private BuildDeckProductInfo _productInfo;

	private UICardList _uiCardList;

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

	public void SetSingleData(UICardList uiCardList, BuildDeckProductInfo productInfo)
	{
		_productInfo = productInfo;
		_uiCardList = uiCardList;
		_buildDeckProductDetail.SetSingleProductDetail(productInfo);
		ClassCharacterMasterData charaPrmByClassId = GameMgr.GetIns().GetDataMgr().GetCharaPrmByClassId(productInfo.leader_id);
		_labelProductName.text = productInfo.saleInfo.name;
		ClassCharaPrm.SetClassLabelSetting(_labelProductName, charaPrmByClassId.ClassColorId);
		_spriteClassColorIcon.spriteName = ClassCharaPrm.GetIconSpriteName(charaPrmByClassId.clan);
		_uiCardList.SetClan(charaPrmByClassId.clan);
		_uiCardList.SetDeckName(productInfo.saleInfo.name);
		_uiCardList.SetMaxCardNum(40);
		_labelDeckCode.text = Wizard.Data.SystemText.Get("Shop_0117", productInfo.deck_code);
	}

	public void OnCloseWindow()
	{
		_uiCardList.RemoveData();
		Toolbox.ResourcesManager.RemoveAssetGroup(_loadedCardList);
	}

	public void OnBtnCopyDeckCode()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		NativePluginWrapper.SetStringToClipboard(_productInfo.deck_code);
		UIManager.GetInstance().CreateConfirmationDialog(Wizard.Data.SystemText.Get("Shop_0118", _productInfo.deck_code)).SetPanelDepth(20);
	}

	public void OnBtnShowCardList()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		if (_uiCardList.getCardNum() > 0)
		{
			ShowUICardList();
			return;
		}
		UIManager.GetInstance().createInSceneCenterLoading();
		StartCoroutine(LoadCardAndShowUICardList());
	}

	private IEnumerator LoadCardAndShowUICardList()
	{
		List<int> cardIdList = _productInfo.CardIdList;
		List<string> assetList = _uiCardList.GetLoadFileList(cardIdList);
		yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(assetList, null));
		_loadedCardList.AddRange(assetList);
		List<int> list = UIManager.GetInstance().getUIBase_CardManager().SortIDList(cardIdList, CardMaster.CardMasterId.Default);
		for (int i = 0; i < list.Count; i++)
		{
			_uiCardList.addScrollItem(list[i]);
		}
		_uiCardList.SetFormat(Format.Rotation, null);
		yield return null;
		UIManager.GetInstance().closeInSceneCenterLoading();
		ShowUICardList();
	}

	private void ShowUICardList()
	{
		_uiCardList.SetActive(in_Active: true);
		_uiCardList.ResetScroll();
	}
}
