using UnityEngine;

namespace Wizard;

public class MyRotationParts : MonoBehaviour
{
	[SerializeField]
	private UISprite _backGround;

	[SerializeField]
	private UILabel _packNameLabel;

	[SerializeField]
	private FlexibleGrid _backGroundGrid;

	[SerializeField]
	private UIGrid _bonusIconGrid;

	[SerializeField]
	private GameObject _bonusIconOriginal;

	private const int BACK_GROUND_PACK_NAME_OFFSET = 20;

	private const int BACK_GROUND_ICON_OFFSET = 28;

	public void SetMyRotationInfo(MyRotationInfo myRotationInfo)
	{
		if (myRotationInfo == null)
		{
			return;
		}
		if (_packNameLabel != null)
		{
			_packNameLabel.text = myRotationInfo.LastPackText;
		}
		_bonusIconOriginal.SetActive(value: false);
		_bonusIconGrid.transform.DestroyChildren();
		foreach (MyRotationInfo.MyRotationBonus ability in myRotationInfo.Abilities)
		{
			GameObject obj = NGUITools.AddChild(_bonusIconGrid.gameObject, _bonusIconOriginal);
			obj.GetComponent<UISprite>().spriteName = ability.IconName;
			obj.SetActive(value: true);
		}
		_bonusIconGrid.Reposition();
		if (_backGround != null)
		{
			_backGround.rightAnchor.target = ((myRotationInfo.Abilities.Count > 0) ? _bonusIconGrid.transform : _packNameLabel.transform);
			_backGround.rightAnchor.absolute = ((myRotationInfo.Abilities.Count > 0) ? 28 : 20);
		}
	}

	public void Reposition()
	{
		_backGroundGrid.Reposition();
		StartCoroutine(_backGroundGrid.RepositionNextFrame());
	}
}
