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

public class FacilityDetailsListViewer : MonoBehaviour
{
	public void CreateFacilityDetailsList<T>(int itemCount, Action<int, T> onCreateItem) where T : FacilityDetailsListViewer.FacilityDetailsUI
	{
		this.m_ListViewerFacilityDetails.Show<Transform>(itemCount, delegate(int index, Transform trans)
		{
			onCreateItem(index, trans.gameObject.AddComponent<T>());
		});
	}

	public bool IsExistItemList()
	{
		NDebug.Assert(this.m_ListViewerFacilityDetails != null, "FacilityDetailsListViewer.cs\nUI項目を並べるコンポーネントがアタッチされていません");
		return this.m_ListViewerFacilityDetails.ItemArray != null && this.m_ListViewerFacilityDetails.ItemArray.Length > 0;
	}

	public int GetItemCount()
	{
		NDebug.Assert(this.m_ListViewerFacilityDetails != null, "FacilityDetailsListViewer.cs\nUI項目を並べるコンポーネントがアタッチされていません");
		if (!this.IsExistItemList())
		{
			return 0;
		}
		return this.m_ListViewerFacilityDetails.ItemArray.Length;
	}

	public T GetItem<T>(int index) where T : Component
	{
		NDebug.Assert(this.m_ListViewerFacilityDetails != null, "FacilityDetailsListViewer.cs\nUI項目を並べるコンポーネントがアタッチされていません");
		GameObject[] itemArray = this.m_ListViewerFacilityDetails.ItemArray;
		if (itemArray == null)
		{
			return (T)((object)null);
		}
		if (itemArray.Length <= index)
		{
			return (T)((object)null);
		}
		return itemArray[index].GetComponent<T>();
	}

	public List<T> GetAllItem<T>() where T : Component
	{
		NDebug.Assert(this.m_ListViewerFacilityDetails != null, "FacilityDetailsListViewer.cs\nUI項目を並べるコンポーネントがアタッチされていません");
		GameObject[] itemArray = this.m_ListViewerFacilityDetails.ItemArray;
		if (itemArray == null)
		{
			return null;
		}
		List<T> list = new List<T>();
		int num = itemArray.Length;
		for (int i = 0; i < num; i++)
		{
			list.Add(this.GetItem<T>(i));
		}
		return list;
	}

	[SerializeField]
	private uGUIListViewer m_ListViewerFacilityDetails;

	public class FacilityDetailsUI : MonoBehaviour
	{
		public FacilityInfoUI facilityInfoUI
		{
			get
			{
				FacilityInfoUI result;
				if ((result = this.m_InfoUI) == null)
				{
					result = (this.m_InfoUI = base.GetComponent<FacilityInfoUI>());
				}
				return result;
			}
		}

		private FacilityInfoUI m_InfoUI;
	}
}
