using UnityEngine;
using Wizard;

[RequireComponent(typeof(UIDragScrollView), typeof(UICenterOnClick), typeof(UIEventListener))]
[RequireComponent(typeof(BoxCollider))]
public class UtilityDrumrollItem : MonoBehaviour
{
	[SerializeField]
	private UILabel _childLabel;

	[SerializeField]
	private UtilityDrumrollItemCustomize _customizeItem;

	private const float COLOR_DIFF_Y = 20f;

	private UIPanel _scrollView;

	private Vector2 _scrollSize = Vector2.zero;

	public int _index { get; private set; }

	public UtilityDrumrollItemCustomize CustomizeItem => _customizeItem;

	public void Init(UIPanel scroll, int index, string text)
	{
		_index = index;
		_childLabel.text = text;
		_scrollView = scroll;
		_scrollSize = _scrollView.GetViewSize();
	}

	private void Update()
	{
		if (_childLabel != null)
		{
			float num = _scrollView.clipOffset.y - base.gameObject.transform.localPosition.y;
			float num2 = _scrollSize.y / 2f;
			float num3 = Mathf.Clamp(Mathf.Abs(num), 0f, num2);
			float num4 = Mathf.LerpAngle(0f, 90f, num3 * (num3 / num2) / num2);
			if (num > 0f)
			{
				num4 *= -1f;
			}
			_childLabel.transform.localEulerAngles = Vector3.right * num4;
			Color32 color3;
			if (num3 > 20f)
			{
				Color color = (_childLabel.color = LabelDefine.TEXT_COLOR_B0B0B0);
				color3 = color;
			}
			else
			{
				Color color = (_childLabel.color = LabelDefine.TEXT_COLOR_NORMAL);
				color3 = color;
			}
			if (_customizeItem != null)
			{
				_customizeItem.OnUpdate(num4, color3);
			}
		}
	}
}
