using System;
using Schedule;
using UnityEngine;

public class OnHoverTaskIcon : MonoBehaviour
{
	public void Init(string taskName, Maid maid, ScheduleMgr.ScheduleTime time)
	{
		this.taskName = taskName;
		this.maid = maid;
		if (string.IsNullOrEmpty(taskName))
		{
			return;
		}
		this.m_goNamePlate = UTY.GetChildObject(base.gameObject, "NamePlate", false);
		this.spritePlate = this.m_goNamePlate.GetComponent<UISprite>();
		this.labelName = UTY.GetChildObject(this.m_goNamePlate, "Name", false).GetComponent<UILabel>();
		this.labelName.width = 0;
		this.SetText(taskName);
		this.m_goNamePlate.SetActive(false);
		this.WariningFacilty = UTY.GetChildObject(base.gameObject, "WarningFacilty", false).GetComponent<UISprite>();
		this.WariningFacilty.gameObject.SetActive(false);
		this.time = time;
		int key = 0;
		if (maid != null)
		{
			if (time == ScheduleMgr.ScheduleTime.DayTime)
			{
				key = maid.status.noonWorkId;
			}
			else if (time == ScheduleMgr.ScheduleTime.Night)
			{
				key = maid.status.nightWorkId;
			}
			ScheduleCSVData.ScheduleBase scheduleBase = ScheduleCSVData.AllData[key];
			if (scheduleBase.type == ScheduleTaskCtrl.TaskType.Work)
			{
				this.workData = (ScheduleCSVData.Work)scheduleBase;
				this.facility = GameMain.Instance.FacilityMgr.GetMaidAssignedFacility(maid, time);
			}
		}
	}

	private void Update()
	{
		if (this.workData != null && this.workData.id != ScheduleCSVData.faclilityPowerUpWorkId)
		{
			this.WariningFacilty.gameObject.SetActive(!this.facility.IsOperation(this.time));
		}
	}

	public void SetText(string message)
	{
		UISprite component = this.m_goNamePlate.GetComponent<UISprite>();
		this.labelName.text = message;
		this.labelName.MakePixelPerfect();
		string[] array = message.Split(new char[]
		{
			'\n'
		});
		int num = 0;
		foreach (string text in array)
		{
			if (num < text.Length)
			{
				num = text.Length;
			}
		}
		component.width = this.labelName.width + 15;
		component.height = array.Length * 33;
	}

	private void OnHover(bool isOver)
	{
		if (isOver)
		{
			if (this.m_goNamePlate != null)
			{
				this.m_goNamePlate.SetActive(true);
			}
			if (this.workData != null && this.workData.id != ScheduleCSVData.faclilityPowerUpWorkId)
			{
				this.CheckFacilityState();
			}
		}
		else
		{
			if (this.m_goNamePlate != null)
			{
				this.m_goNamePlate.SetActive(false);
			}
			if (this.WariningFacilty != null)
			{
				this.WariningFacilty.gameObject.SetActive(false);
			}
		}
	}

	private void CheckFacilityState()
	{
		if (!this.facility.IsOperation(this.time))
		{
			int num;
			if (this.time == ScheduleMgr.ScheduleTime.DayTime)
			{
				num = this.facility.minMaidCount - this.facility.nowDayTimeMaidCount;
			}
			else
			{
				num = this.facility.minMaidCount - this.facility.nowNightMaidCount;
			}
			this.SetText(string.Concat(new object[]
			{
				this.taskName,
				"\nあと[FF0000]",
				num,
				"人[-]必要です"
			}));
		}
		else
		{
			this.SetText(this.taskName);
		}
	}

	private GameObject m_goNamePlate;

	private UISprite spritePlate;

	private UILabel labelName;

	private const int SIDE_OFFSET = 15;

	private const int VERT_OFFSET = 33;

	private string taskName;

	private ScheduleCSVData.Work workData;

	public UISprite WariningFacilty;

	private ScheduleMgr.ScheduleTime time;

	private Facility facility;

	private Maid maid;
}
