using UnityEngine;

public class WrapContentsScrollBarSizeByDirection : MonoBehaviour
{
	[SerializeField]
	private UIScrollView _scrollView;

	[SerializeField]
	private UIWrapContent _wrapContent;

	private UIWidget _uiWidget;

	private void Start()
	{
		ContentUpdate();
	}

	public void ContentUpdate()
	{
		if (_uiWidget == null)
		{
			SetUpUIWidget();
		}
		_uiWidget.pivot = UIWidget.Pivot.TopLeft;
		int num = _wrapContent.itemSize * (Mathf.Abs(_wrapContent.minIndex - _wrapContent.maxIndex) + 1);
		float num2 = (float)_wrapContent.itemSize / 2f;
		switch (_scrollView.movement)
		{
		case UIScrollView.Movement.Vertical:
			_uiWidget.height = num;
			base.transform.localPosition = new Vector3(0f, num2, 0f);
			break;
		case UIScrollView.Movement.Horizontal:
			_uiWidget.width = num;
			base.transform.localPosition = new Vector3(0f - num2, 0f, 0f);
			break;
		}
	}

	private void SetUpUIWidget()
	{
		_uiWidget = base.gameObject.GetComponent<UIWidget>();
		if (_uiWidget == null)
		{
			_uiWidget = base.gameObject.AddComponent<UIWidget>();
		}
	}
}
