using System;
using System.Collections;
using System.Collections.Generic;
using Schedule;
using TextureBank;
using UnityEngine;

public class DescScheduleWork : DescScheduleTraining
{
	public ScheduleMgr ScheduleMgr
	{
		set
		{
			this.scheduleMgr = value;
		}
	}

	public WorkTaskUnit TaskUnit
	{
		set
		{
			this.taskUnit = value;
		}
	}

	public override void Init(ScheduleTaskCtrl taskCtrl)
	{
		if (taskCtrl == null)
		{
			return;
		}
		base.Init(taskCtrl);
		this.m_FacillityPanel.TaskViewr = taskCtrl.TaskViewer;
		this.m_goTitleOfSalonParameter = UTY.GetChildObject(base.gameObject, "SalonParameter/Title", false);
		this.m_heightOfSalonParameterTitle = this.m_goTitleOfSalonParameter.GetComponent<UISprite>().height;
		this.m_goSalonParameter = UTY.GetChildObject(base.gameObject, "SalonParameter", false);
		this.m_goSalonParameterParent = UTY.GetChildObject(base.gameObject, "SalonParameter/ParameterParent", false);
		this.m_lIncome = new DescScheduleBase.ParamSet(this.m_goSalonParameterParent, "Income", false);
		this.m_listClubParameter = new List<ScheduleCtrl.VariableItem>
		{
			this.m_lIncome.GetVariableItem()
		};
		this.m_goFacilityMiniPanel = UTY.GetChildObject(base.gameObject, "FacilityMiniPanel", false);
		GameObject childObject = UTY.GetChildObject(this.m_goFacilityMiniPanel, "Grid_Value/FacilityLevel", false);
		this.m_lFacilityLevel = childObject.GetComponent<UILabel>();
		GameObject childObject2 = UTY.GetChildObject(this.m_goFacilityMiniPanel, "Sprite_Thumbnail", false);
		this.m_lFacilitThumbnaily = childObject2.GetComponent<UITexture>();
		GameObject childObject3 = UTY.GetChildObject(this.m_goFacilityMiniPanel, "TitleBar/Title_Name", false);
		this.m_lFacilityTitleName = childObject3.GetComponent<UILabel>();
		this.m_lFacilityRankStarParent = UTY.GetChildObject(this.m_goFacilityMiniPanel, "Grid_Value/Parent_Rank/Grid_Star", false);
		GameObject childObject4 = UTY.GetChildObject(base.gameObject, "Btn_Start", false);
		this.m_lFacilityButton = childObject4.GetComponent<UIButton>();
	}

	public void EnableFacillityPanel_Button()
	{
		TaskUnit selectedTaskUnit = this.taskCtrl.TaskViewer.GetSelectedTaskUnit();
		if (selectedTaskUnit.taskType == ScheduleTaskCtrl.TaskType.Work)
		{
			this.taskUnit = (WorkTaskUnit)selectedTaskUnit;
		}
		this.EnableFacillityPanel();
	}

	public void EnableFacillityPanel()
	{
		this.m_FacillityPanel.TaskUnit = this.taskUnit;
		this.m_FacillityPanel.WorkData = this.work_data;
		this.m_FacillityPanel.SelectMaid = this.taskCtrl.ScheduleCtrl.SelectedMaid;
		this.m_FacillityPanel.ScheduleTime = ScheduleTaskViewer.ScheduleTime;
		this.m_FacillityPanel.Active(true);
	}

	public void DisableFacillityPanel()
	{
		this.m_FacillityPanel.Active(false);
	}

	public void AddFacillity(FacilityInfoUI info)
	{
		int facilityCountMax = GameMain.Instance.FacilityMgr.FacilityCountMax;
		info.SetFacilityInfo(info.facility, true);
	}

	protected override void UpdateView(ScheduleCSVData.ScheduleBase work_data)
	{
		this.work_data = (ScheduleCSVData.Work)work_data;
		if (this.work_data.workTyp == ScheduleCSVData.WorkType.Basic)
		{
			this.UpdateFacilityMiniPanel();
			this.UpdateCurentValue();
			MaidParams addValue_Work = this.GetAddValue_Work();
			this.UpdateAddValue(addValue_Work);
			this.m_lIncome.AddValueText = "0";
			this.m_goMaidParameter.SetActive(true);
			this.m_goFacilityMiniPanel.SetActive(true);
			this.m_goSalonParameter.SetActive(true);
			this.m_lFacilityButton.gameObject.SetActive(true);
			this.ExamineDisplayItem();
			Slot slot = this.taskCtrl.ScheduleMgr.GetScheduleApi().slot[this.taskCtrl.CurrentActiveSlotNo];
			Maid maid = slot.maid;
			ScheduleCSVData.ScheduleBase schedule = ScheduleAPI.GetSchedule(maid, ScheduleTaskViewer.ScheduleTime);
			this.m_lFacilityButton.gameObject.SetActive(schedule == work_data);
		}
		else if (this.work_data.workTyp == ScheduleCSVData.WorkType.PowerUp)
		{
			this.m_goMaidParameter.SetActive(false);
			this.m_goFacilityMiniPanel.SetActive(false);
			this.m_goSalonParameter.SetActive(false);
			this.m_lFacilityButton.gameObject.SetActive(false);
		}
	}

	private void UpdateFacilityMiniPanel()
	{
		this.m_lFacilityTitleName.text = this.work_data.name;
		Sprite facilityThumbnail = FacilityDataTable.GetFacilityThumbnail(this.work_data.facility.ID, true);
		if (facilityThumbnail != null)
		{
			this.m_lFacilitThumbnaily.mainTexture = facilityThumbnail.texture;
		}
		this.m_lFacilitThumbnaily.gameObject.SetActive(facilityThumbnail != null);
		int facilityLevel = GameMain.Instance.FacilityMgr.GetFacilityLevel(this.work_data.facility.ID);
		this.m_lFacilityLevel.text = "Lv." + facilityLevel.ToString();
		int rank = this.work_data.facility.rank;
		Transform transform = this.m_lFacilityRankStarParent.transform;
		for (int i = 0; i < transform.childCount; i++)
		{
			Transform child = transform.GetChild(i);
			child.gameObject.SetActive(i < rank);
		}
	}

	private MaidParams GetAddValue_Work()
	{
		foreach (ScheduleBase scheduleBase in this.taskCtrl.GetWorksData(ScheduleTaskCtrl.TaskType.Work))
		{
			if (scheduleBase.workType == ScheduleType.Work)
			{
				ScheduleWork scheduleWork = (ScheduleWork)scheduleBase;
				if (scheduleWork.id == this.intTaskInd)
				{
					MaidParams simulateeMaidParams = scheduleWork.simulateeMaidParams;
					SalonParams simulateeSalonMaidParams = scheduleWork.simulateeSalonMaidParams;
					return simulateeMaidParams;
				}
			}
		}
		return null;
	}

	private new void ExamineDisplayItem()
	{
		int num = ScheduleCtrl.SetActiveExceptForNothing(this.m_listMaidItem, "0");
		bool flag = num > 0;
		this.m_goTitleOfMaidParameter.SetActive(flag);
		int num2 = ScheduleCtrl.SetActiveExceptForNothing(this.m_listClubParameter, "0");
		bool flag2 = num2 > 0;
		this.m_goTitleOfSalonParameter.SetActive(flag2);
		if (!flag && !flag2)
		{
			base.Active(false);
			return;
		}
		base.Active(true);
		DescScheduleBase.Reposition(this.m_goMaidParameterParent);
		DescScheduleBase.Reposition(this.m_goSalonParameterParent);
		this.AdjustParameterViewer(num, num2);
	}

	private void AdjustParameterViewer(int displayMaidParameterCount, int displaySalonParameterCount)
	{
		float num = 15f;
		float num2 = 25f;
		float num3 = 0f;
		if (displayMaidParameterCount > 0)
		{
			num3 += (float)this.m_heightOfMaidParameterTitle + num;
			float y = this.m_goMaidParameterParent.GetComponent<UITable>().padding.y;
			IEnumerator enumerator = this.m_goMaidParameterParent.transform.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object obj = enumerator.Current;
					Transform transform = (Transform)obj;
					if (transform.gameObject.activeSelf)
					{
						UILabel component = transform.GetComponent<UILabel>();
						num3 += (float)component.height + y * 2f;
					}
				}
			}
			finally
			{
				IDisposable disposable;
				if ((disposable = (enumerator as IDisposable)) != null)
				{
					disposable.Dispose();
				}
			}
			num3 += num2;
		}
		float num4 = 0f;
		if (displaySalonParameterCount > 0)
		{
			num4 += (float)this.m_heightOfSalonParameterTitle + num;
			float y = this.m_goSalonParameterParent.GetComponent<UITable>().padding.y;
			IEnumerator enumerator2 = this.m_goSalonParameterParent.transform.GetEnumerator();
			try
			{
				while (enumerator2.MoveNext())
				{
					object obj2 = enumerator2.Current;
					Transform transform2 = (Transform)obj2;
					if (transform2.gameObject.activeSelf)
					{
						UILabel component2 = transform2.GetComponent<UILabel>();
						num4 += (float)component2.height + y * 2f;
					}
				}
			}
			finally
			{
				IDisposable disposable2;
				if ((disposable2 = (enumerator2 as IDisposable)) != null)
				{
					disposable2.Dispose();
				}
			}
			num4 += num2;
		}
		if (num3 + num4 > 0f)
		{
			this.m_spBGOfParameterViewer.height = (int)(num3 + num4);
			float num5 = (num3 <= 0f) ? (-(num3 + num * 2f)) : (-(num3 + num));
			num5 -= 125f;
			this.m_goSalonParameter.transform.localPosition = new Vector3(this.m_goSalonParameter.transform.localPosition.x, num5, 0f);
		}
	}

	private ScheduleMgr scheduleMgr;

	private UIButton roomSettingStartBtn;

	private GameObject m_goTitleOfSalonParameter;

	private int m_heightOfSalonParameterTitle;

	private UIPanel currentRoomPanel;

	private UITexture spriteThumbnail;

	protected List<ScheduleCtrl.VariableItem> m_listClubParameter;

	private GameObject m_goSalonParameter;

	private GameObject m_goSalonParameterParent;

	private WorkTaskUnit taskUnit;

	private ScheduleCSVData.Work work_data;

	private DescScheduleBase.ParamSet m_lIncome;

	private GameObject m_goFacilityMiniPanel;

	private UILabel m_lFacilityLevel;

	private UITexture m_lFacilitThumbnaily;

	private UILabel m_lFacilityTitleName;

	private UIButton m_lFacilityButton;

	private GameObject m_lFacilityRankStarParent;

	public TextureBank textureBank;

	[SerializeField]
	private ScheduleFacillityPanelCtrl m_FacillityPanel;
}
