using System;
using UnityEngine;
using UnityEngine.UI;

public class FacilityInfoUI : MonoBehaviour
{
	public FacilityInfoUI.ViewType viewType
	{
		get
		{
			return this.m_ViewType;
		}
		set
		{
			this.m_ViewType = value;
			this.UpdateViewTypeUI();
		}
	}

	public InputField textFacilityName
	{
		get
		{
			return this.m_TextFacilityName;
		}
		set
		{
			this.m_TextFacilityName = value;
		}
	}

	public Image imageFacilityThumbnail
	{
		get
		{
			return this.m_ImageFacilityThumbnail;
		}
	}

	public Facility facility
	{
		get
		{
			return this.m_Facility;
		}
	}

	public void SetFacilityInfo(Facility facility, bool nullCheck = true)
	{
		ScheduleMgr.ScheduleTime scheduleTime = (!GameMain.Instance.CharacterMgr.status.isDaytime) ? ScheduleMgr.ScheduleTime.Night : ScheduleMgr.ScheduleTime.DayTime;
		ScheduleMgr.ScheduleTime nowScheduleTime = this.m_NowScheduleTime;
		if (nowScheduleTime != ScheduleMgr.ScheduleTime.DayTime)
		{
			if (nowScheduleTime == ScheduleMgr.ScheduleTime.Night)
			{
				scheduleTime = this.m_NowScheduleTime;
			}
		}
		else
		{
			scheduleTime = this.m_NowScheduleTime;
		}
		this.SetFacilityInfo(facility, scheduleTime, nullCheck);
	}

	public void SetFacilityInfo(Facility facility, ScheduleMgr.ScheduleTime scheduleTime, bool nullCheck = true)
	{
		this.m_Facility = facility;
		string text = string.Empty;
		string text2 = string.Empty;
		string text3 = string.Empty;
		string text4 = string.Empty;
		string text5 = string.Empty;
		string text6 = string.Empty;
		string text7 = string.Empty;
		Sprite sprite = null;
		int itemCount;
		int itemCount2;
		if (this.m_Facility)
		{
			text = this.m_Facility.facilityName;
			text2 = this.m_Facility.NowMaidCount(scheduleTime).ToString();
			text3 = this.m_Facility.minMaidCount.ToString();
			text4 = this.m_Facility.maxMaidCount.ToString();
			text5 = this.m_Facility.defaultData.cost.ToString();
			text6 = this.m_Facility.facilityLevel.ToString();
			itemCount = this.m_Facility.defaultData.rank;
			itemCount2 = this.m_Facility.GetStaffRank(scheduleTime);
			if (this.m_Facility.defaultData.isBusiness)
			{
				text7 = ((!this.m_Facility.IsOperation(scheduleTime)) ? "未稼働" : "営業可能");
			}
			else
			{
				text7 = ((!this.m_Facility.IsOperation(scheduleTime)) ? "未稼働" : "稼働中");
			}
			sprite = FacilityDataTable.GetFacilityThumbnail(this.m_Facility.param.typeID, true);
		}
		else
		{
			text = "空き部屋";
			text2 = "---";
			text3 = "---";
			text4 = "---";
			text5 = "---";
			text6 = "--";
			text7 = "---";
			itemCount = 0;
			itemCount2 = 0;
		}
		if (this.m_TextFacilityName)
		{
			this.m_TextFacilityName.text = text;
		}
		if (this.m_ImageFacilityThumbnail)
		{
			this.m_ImageFacilityThumbnail.sprite = sprite;
		}
		if (this.m_TextNumberOfPeople)
		{
			this.m_TextNumberOfPeople.text = text2;
		}
		if (this.m_TextNumberOfMinPeople)
		{
			this.m_TextNumberOfMinPeople.text = text3;
		}
		if (this.m_TextNumberOfMaxPeople)
		{
			this.m_TextNumberOfMaxPeople.text = text4;
		}
		if (this.m_TextNumberOfCost)
		{
			this.m_TextNumberOfCost.text = text5;
		}
		if (this.m_TextLevelOfFacility)
		{
			this.m_TextLevelOfFacility.text = text6;
		}
		if (this.m_TextStatusOfFacility)
		{
			this.m_TextStatusOfFacility.text = text7;
		}
		if (this.m_uGUIListRankStar)
		{
			this.m_uGUIListRankStar.Show<Transform>(itemCount, null);
		}
		if (this.m_uGUIListStaffStar)
		{
			this.m_uGUIListStaffStar.Show<Transform>(itemCount2, null);
		}
	}

	public void UpdateFacilityInfo(bool nullCheck = true)
	{
		this.SetFacilityInfo(this.m_Facility, nullCheck);
	}

	public void UpdateFacilityInfo(ScheduleMgr.ScheduleTime scheduleTime, bool nullCheck = true)
	{
		this.m_NowScheduleTime = scheduleTime;
		this.SetFacilityInfo(this.m_Facility, scheduleTime, nullCheck);
	}

	public bool IsInteractable
	{
		get
		{
			return this.m_IsInteractable;
		}
		set
		{
			this.m_IsInteractable = value;
			Selectable componentInChildren = base.GetComponentInChildren<Selectable>();
			if (componentInChildren != null)
			{
				componentInChildren.interactable = this.m_IsInteractable;
			}
			Graphic componentInChildren2 = base.GetComponentInChildren<Graphic>();
			if (componentInChildren2 != null)
			{
				componentInChildren2.raycastTarget = this.m_IsInteractable;
			}
			GameObject childObject = UTY.GetChildObject(base.gameObject, "Image Inactive mask", true);
			if (childObject)
			{
				childObject.SetActive(!this.m_IsInteractable);
			}
		}
	}

	public void SetNameChangeEnable(bool enable)
	{
		this.m_TextFacilityName.interactable = enable;
	}

	public void SetMaidIcon(Maid maid, ScheduleMgr.ScheduleTime scheduleTime)
	{
		if (this.m_MaidIconObject == null)
		{
			return;
		}
		if (this.m_Facility == null)
		{
			return;
		}
		if (maid == null)
		{
			this.SetMaidIconShowFlag(false);
			return;
		}
		RawImage componentInChildren = this.m_MaidIconObject.GetComponentInChildren<RawImage>();
		if (componentInChildren == null)
		{
			Debug.LogWarning("メイドの顔アイコン表示オブジェクトが見つかりませんでした。");
			return;
		}
		bool flag = this.IsAllocationMaid(maid, scheduleTime);
		Texture texture = null;
		if (maid != null && flag)
		{
			texture = maid.GetThumIcon();
		}
		componentInChildren.texture = texture;
		this.SetMaidIconShowFlag(texture != null);
	}

	public bool IsAllocationMaid(Maid maid, ScheduleMgr.ScheduleTime scheduleTime)
	{
		return !(this.m_Facility == null) && !(maid == null) && this.m_Facility.IsAllocationMaid(maid, scheduleTime);
	}

	public void SetMaidIconShowFlag(bool isShow)
	{
		if (this.m_MaidIconObject == null)
		{
			return;
		}
		if (isShow)
		{
			if (!this.m_MaidIconObject.activeSelf)
			{
				this.m_MaidIconObject.SetActive(true);
			}
		}
		else if (this.m_MaidIconObject.activeSelf)
		{
			this.m_MaidIconObject.SetActive(false);
		}
	}

	private void UpdateViewTypeUI()
	{
		if (this.m_ViewType == FacilityInfoUI.ViewType.Free)
		{
			return;
		}
		bool active = false;
		bool active2 = false;
		bool active3 = false;
		bool active4 = false;
		bool active5 = false;
		bool active6 = false;
		bool active7 = false;
		bool active8 = false;
		switch (this.m_ViewType)
		{
		case FacilityInfoUI.ViewType.DefaultMode:
		case FacilityInfoUI.ViewType.MiniDefaultMode:
			active2 = (active = (active3 = (active4 = (active5 = true))));
			break;
		case FacilityInfoUI.ViewType.MaidAllocateMode:
			active2 = (active = (active3 = (active6 = (active4 = true))));
			break;
		case FacilityInfoUI.ViewType.ConstructMode:
			active6 = (active = (active7 = (active4 = (active8 = true))));
			break;
		}
		if (this.m_uGUIListRankStar)
		{
			this.m_uGUIListRankStar.gameObject.SetActive(active);
		}
		if (this.m_uGUIListStaffStar)
		{
			this.m_uGUIListStaffStar.gameObject.SetActive(active2);
		}
		if (this.m_TextNumberOfPeople)
		{
			this.m_TextNumberOfPeople.gameObject.SetActive(active3);
		}
		if (this.m_TextLevelOfFacility)
		{
			this.m_TextLevelOfFacility.gameObject.SetActive(active4);
		}
		if (this.m_TextStatusOfFacility)
		{
			this.m_TextStatusOfFacility.gameObject.SetActive(active5);
		}
		if (this.m_TextNumberOfMinPeople)
		{
			this.m_TextNumberOfMinPeople.gameObject.SetActive(active6);
		}
		if (this.m_TextNumberOfMaxPeople)
		{
			this.m_TextNumberOfMaxPeople.gameObject.SetActive(active7);
		}
		if (this.m_TextNumberOfCost)
		{
			this.m_TextNumberOfCost.gameObject.SetActive(active8);
		}
		Image image = null;
		GameObject childObject = UTY.GetChildObject(base.gameObject, "Parent Info", true);
		if (childObject != null)
		{
			image = childObject.GetComponent<Image>();
		}
		if (image == null)
		{
			image = base.gameObject.GetComponent<Image>();
		}
		if (image != null)
		{
			image.sprite = this.GetViewTypePlate(this.m_ViewType);
		}
	}

	private Sprite GetViewTypePlate(FacilityInfoUI.ViewType viewType)
	{
		Sprite result = null;
		switch (viewType)
		{
		case FacilityInfoUI.ViewType.DefaultMode:
			result = Resources.Load<Sprite>("SceneFacilityPowerUp/Sprites/myroom_info_plate");
			break;
		case FacilityInfoUI.ViewType.MaidAllocateMode:
			result = Resources.Load<Sprite>("SceneFacilityManagement/Sprites/shisetsu_infoplate_s2");
			break;
		case FacilityInfoUI.ViewType.ConstructMode:
			result = Resources.Load<Sprite>("SceneFacilityPowerUp/Sprites/myroom_info_plate2");
			break;
		case FacilityInfoUI.ViewType.MiniDefaultMode:
			result = Resources.Load<Sprite>("SceneFacilityManagement/Sprites/shisetsu_infoplate_s");
			break;
		}
		return result;
	}

	private FacilityInfoUI.ViewType m_ViewType = FacilityInfoUI.ViewType.Free;

	[SerializeField]
	protected InputField m_TextFacilityName;

	[SerializeField]
	protected Image m_ImageFacilityThumbnail;

	[SerializeField]
	protected Text m_TextNumberOfPeople;

	[SerializeField]
	protected Text m_TextLevelOfFacility;

	[SerializeField]
	protected Text m_TextStatusOfFacility;

	[SerializeField]
	protected uGUIListViewer m_uGUIListRankStar;

	[SerializeField]
	protected uGUIListViewer m_uGUIListStaffStar;

	[SerializeField]
	protected Text m_TextNumberOfMinPeople;

	[SerializeField]
	protected Text m_TextNumberOfMaxPeople;

	[SerializeField]
	protected Text m_TextNumberOfCost;

	[SerializeField]
	protected GameObject m_MaidIconObject;

	private ScheduleMgr.ScheduleTime m_NowScheduleTime = (ScheduleMgr.ScheduleTime)(-1);

	protected Facility m_Facility;

	private bool m_IsInteractable = true;

	public enum ViewType
	{
		DefaultMode,
		MaidAllocateMode,
		ConstructMode,
		MiniDefaultMode,
		Free
	}
}
