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

public class FacilityUIPowerUpList : MonoBehaviour
{
	public void Show(Facility facility, Action<Facility.PowerUpRecipe> callbackSelect)
	{
		this.SetupFacilityPowerUpListButton(facility, callbackSelect);
	}

	private void SetupFacilityPowerUpListButton(Facility facility, Action<Facility.PowerUpRecipe> callbackSelect)
	{
		FacilityUIPowerUpList.<SetupFacilityPowerUpListButton>c__AnonStorey0 <SetupFacilityPowerUpListButton>c__AnonStorey = new FacilityUIPowerUpList.<SetupFacilityPowerUpListButton>c__AnonStorey0();
		<SetupFacilityPowerUpListButton>c__AnonStorey.callbackSelect = callbackSelect;
		<SetupFacilityPowerUpListButton>c__AnonStorey.$this = this;
		this.m_uGUIListViewer.parentItemArea.gameObject.SetActive(true);
		<SetupFacilityPowerUpListButton>c__AnonStorey.powerUpRecipeIDArray = new int[0];
		if (FacilityDataTable.IsExistFacilityPowerUpRecipe(facility.param.typeID, true))
		{
			<SetupFacilityPowerUpListButton>c__AnonStorey.powerUpRecipeIDArray = FacilityDataTable.GetFacilityPowerUpRecipeIDArray(facility.param.typeID, true);
		}
		this.m_uGUIListViewer.Show<Transform>(<SetupFacilityPowerUpListButton>c__AnonStorey.powerUpRecipeIDArray.Length, delegate(int i, Transform trans)
		{
			Facility.PowerUpRecipe powerUpRecipe = FacilityDataTable.GetFacilityPowerUpRecipe(<SetupFacilityPowerUpListButton>c__AnonStorey.powerUpRecipeIDArray[i]);
			Toggle componentInChildren = trans.GetComponentInChildren<Toggle>();
			Text componentInChildren2 = trans.GetComponentInChildren<Text>();
			componentInChildren2.text = powerUpRecipe.name;
			componentInChildren.onValueChanged.RemoveAllListeners();
			componentInChildren.onValueChanged.AddListener(delegate(bool isOn)
			{
				if (!isOn)
				{
					return;
				}
				if (<SetupFacilityPowerUpListButton>c__AnonStorey.callbackSelect != null)
				{
					<SetupFacilityPowerUpListButton>c__AnonStorey.callbackSelect(powerUpRecipe);
				}
				<SetupFacilityPowerUpListButton>c__AnonStorey.UpdateConditionsText(powerUpRecipe.id);
			});
		});
		if (<SetupFacilityPowerUpListButton>c__AnonStorey.powerUpRecipeIDArray.Length <= 0)
		{
			this.m_uGUIListViewer.Show<Transform>(1, delegate(int i, Transform trans)
			{
				Toggle componentInChildren = trans.GetComponentInChildren<Toggle>();
				Text componentInChildren2 = trans.GetComponentInChildren<Text>();
				componentInChildren.enabled = false;
				componentInChildren2.text = "レシピは存在しません。";
			});
		}
		this.m_uGUIListConditions.ResetList();
	}

	private void UpdateConditionsText(int recipeID)
	{
		FacilityDataTable.FacilityRecipeData facilityRecipeData = FacilityDataTable.GetFacilityRecipeData(recipeID);
		if (facilityRecipeData == null)
		{
			this.m_uGUIListConditions.ResetList();
			return;
		}
		string[] conditions = facilityRecipeData.conditions;
		List<string> strConditionsList = new List<string>();
		for (int j = 0; j < conditions.Length; j++)
		{
			if (!string.IsNullOrEmpty(conditions[j]))
			{
				strConditionsList.Add(conditions[j]);
			}
		}
		this.m_uGUIListConditions.Show<RectTransform>(strConditionsList.Count, delegate(int i, RectTransform trans)
		{
			string text = strConditionsList[i];
			Text[] componentsInChildren = trans.GetComponentsInChildren<Text>();
			componentsInChildren[0].text = (i + 1).ToString();
			componentsInChildren[1].text = text;
			Image componentInChildren = trans.GetComponentInChildren<Image>();
			componentInChildren.enabled = (i % 2 != 0);
		});
	}

	public void Hide()
	{
		this.m_uGUIListViewer.parentItemArea.gameObject.SetActive(false);
	}

	[SerializeField]
	private uGUIListViewer m_uGUIListViewer;

	[SerializeField]
	private uGUIListViewer m_uGUIListConditions;
}
