using System.Collections.Generic;
using UnityEngine;
using Wizard.Scripts.Network.Data.TaskData.SleevePurchase;

namespace Wizard;

public class CardSleeveDetailWindow : MonoBehaviour
{
	private const int GRID_CELL_WIDTH_BOUNDARY_COUNT = 5;

	private const int GRID_CELL_WIDTH_DEFAULT = 182;

	private const int GRID_CELL_WIDTH_5_ITEMS = 160;

	[SerializeField]
	private UIGrid _rewardGrid;

	[SerializeField]
	private GameObject _specialLayoutParent;

	[SerializeField]
	private UILabel _labelDescription;

	[SerializeField]
	private CardSleeveRewardView _cardSleeveRewardView;

	public void SetData(SleeveProductInfo productInfo, Dictionary<int, UIBase_CardManager.CardObjData> cardPool)
	{
		string description = Data.SystemText.Get("Shop_0102", productInfo.saleInfo.name.Replace("\n", ""));
		SetData(productInfo.rewardInfoList, description, cardPool);
	}

	public void SetData(List<ShopCommonRewardInfo> rewardInfoList, string description, Dictionary<int, UIBase_CardManager.CardObjData> cardPool)
	{
		_labelDescription.text = description;
		GameObject parent = (_cardSleeveRewardView.IsSpecialLayout(rewardInfoList) ? _specialLayoutParent : _rewardGrid.gameObject);
		_cardSleeveRewardView.SetRewardItems(rewardInfoList, parent, cardPool);
		if (rewardInfoList.Count >= 5)
		{
			_rewardGrid.cellWidth = 160f;
		}
		else
		{
			_rewardGrid.cellWidth = 182f;
		}
		_rewardGrid.Reposition();
		_cardSleeveRewardView.CheckSpecialLayout(parent, rewardInfoList);
	}
}
