using System;
using System.Collections.Generic;
using MaidStatus;
using MaidStatus.CsvData;
using PlayerStatus;
using UnityEngine;

public class MaidExaminationMgr : BaseCreatePanel
{
	public override void Init()
	{
		this.m_goPanel = base.GetPanel("MaidExaminationPanel");
		this.m_ctrl = base.GetCtrl<MaidExaminationCtrl>();
		this.m_ctrl.Init(this, this.m_goPanel);
		this.m_api = new CompetitiveShowAPI();
		this.m_goPanel.SetActive(false);
	}

	public void OpenMaidExaminationPanel(Maid visible_maid, List<Maid> check_maid_list, CompetitiveShowAPI.dgOnSceneStartCallBack call_back = null)
	{
		if (call_back == null)
		{
			call_back = new CompetitiveShowAPI.dgOnSceneStartCallBack(this.OpenMaidExaminationCallBack);
		}
		this.m_check_maid_list.Clear();
		if (check_maid_list != null)
		{
			for (int i = 0; i < check_maid_list.Count; i++)
			{
				this.m_check_maid_list.Add(check_maid_list[i]);
			}
		}
		this.m_api.SceneStart(this, visible_maid, call_back);
	}

	protected void OpenMaidExaminationCallBack()
	{
	}

	protected override void OpenPanel()
	{
		this.m_currentMaidNo = 0;
		this.m_listData = this.LoadData();
		this.m_ctrl.CreateMaidExaminationViewer(this.m_listData, this.m_currentMaidNo);
	}

	private List<MaidExaminationCtrl.MaidExamination> LoadData()
	{
		List<MaidExaminationCtrl.MaidExamination> list = new List<MaidExaminationCtrl.MaidExamination>();
		CompetitiveShowMgr component = UTY.GetChildObject(GameObject.Find("UI Root"), "Manager/CompetitiveShowMgr", false).GetComponent<CompetitiveShowMgr>();
		bool lockNTRPlay = GameMain.Instance.CharacterMgr.status.lockNTRPlay;
		for (int i = 0; i < this.m_check_maid_list.Count; i++)
		{
			Maid maid = this.m_check_maid_list[i];
			if (maid == null)
			{
				Debug.LogWarning(string.Format("GameMain.Instance.CharacterMgr.GetMaid({0})でmaidがNULLでした。", i));
			}
			else
			{
				MaidExaminationCtrl.MaidExamination maidExamination = new MaidExaminationCtrl.MaidExamination();
				maidExamination.maidIcon = maid.GetThumCard();
				PlayerStatus.Status status = GameMain.Instance.CharacterMgr.status;
				AbstractClassData.ClassType classType = AbstractClassData.ClassType.Share;
				classType |= ((!CompetitiveShowMgr.compatibilityMode) ? AbstractClassData.ClassType.New : AbstractClassData.ClassType.Old);
				List<JobClass.Data> learnPossibleClassDatas = maid.status.jobClass.GetLearnPossibleClassDatas(false, classType);
				List<int> list2 = new List<int>();
				foreach (JobClass.Data data in learnPossibleClassDatas)
				{
					bool flag = !maid.status.jobClass.Contains(data.id);
					maid.status.jobClass.Add(data, true, true);
					if (flag)
					{
						list2.Add(data.id);
					}
				}
				maidExamination.arrayAcquiredMaidClassType = list2.ToArray();
				List<YotogiClass.Data> learnPossibleClassDatas2 = maid.status.yotogiClass.GetLearnPossibleClassDatas(false, classType);
				if (lockNTRPlay)
				{
					List<YotogiClass.Data> list3 = new List<YotogiClass.Data>();
					foreach (YotogiClass.Data data2 in learnPossibleClassDatas2)
					{
						if (YotogiClass.IsNTRClass(data2.id, CompetitiveShowMgr.compatibilityMode))
						{
							list3.Add(data2);
						}
					}
					foreach (YotogiClass.Data item in list3)
					{
						learnPossibleClassDatas2.Remove(item);
					}
				}
				list2.Clear();
				foreach (YotogiClass.Data data3 in learnPossibleClassDatas2)
				{
					bool flag2 = !maid.status.yotogiClass.Contains(data3.id);
					maid.status.yotogiClass.Add(data3, true, true);
					if (flag2)
					{
						list2.Add(data3.id);
					}
				}
				maidExamination.arrayAcquiredYotogiClassType = list2.ToArray();
				maidExamination.firstName = maid.status.firstName;
				maidExamination.lastName = maid.status.lastName;
				maidExamination.contractType = maid.status.contract;
				bool flag3 = maidExamination.arrayAcquiredMaidClassType != null && maidExamination.arrayAcquiredMaidClassType.Length > 0;
				bool flag4 = maidExamination.arrayAcquiredYotogiClassType != null && maidExamination.arrayAcquiredYotogiClassType.Length > 0;
				if (flag3 || flag4)
				{
					list.Add(maidExamination);
				}
				if (!CompetitiveShowMgr.compatibilityMode)
				{
					GameMain.Instance.CharacterMgr.status.CheckTrophyJobClassAndYotogiClass(maid);
				}
			}
		}
		return list;
	}

	public void ClickNext()
	{
		int maidNo = ++this.m_currentMaidNo;
		this.m_ctrl.CreateMaidExaminationViewer(this.m_listData, maidNo);
	}

	public void ClickOk()
	{
		this.m_ctrl.DispSystemDialog();
	}

	public void CloseMaidExaminationPanel()
	{
		GameMain.Instance.SysDlg.Close();
		base.BaseClosePanel();
	}

	protected override void AfterClose()
	{
		if (this.sceneMgr != null)
		{
			this.m_api.EndNextScene(new CompetitiveShowAPI.dgOnSceneFinalCallBack(this.OnAfterCloseEnd));
		}
	}

	private void OnAfterCloseEnd()
	{
		GameMain.Instance.BgMgr.DeleteBg();
		GameMain.Instance.MainCamera.SetControl(true);
		GameMain.Instance.ScriptMgr.StopMotionScript();
		Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
		maid.FaceAnime("通常", 0f, 0);
		maid.FaceBlend("無し");
		maid.Visible = false;
		this.sceneMgr.CloseScene();
	}

	protected override void SetFadeTargetPanel()
	{
		this.fadeTargetPanel = this.m_goPanel;
	}

	private List<MaidExaminationCtrl.MaidExamination> MakeDummyData()
	{
		List<MaidExaminationCtrl.MaidExamination> list = new List<MaidExaminationCtrl.MaidExamination>();
		MaidExaminationCtrl.MaidExamination maidExamination = new MaidExaminationCtrl.MaidExamination();
		maidExamination.arrayAcquiredMaidClassType = new int[]
		{
			JobClass.uniqueNameToId("Charm"),
			JobClass.uniqueNameToId("Innocent")
		};
		maidExamination.arrayAcquiredYotogiClassType = new int[]
		{
			YotogiClass.uniqueNameToId("Escort"),
			YotogiClass.uniqueNameToId("Rudeness")
		};
		maidExamination.contractType = Contract.Free;
		int num = 5;
		for (int i = 0; i < num; i++)
		{
			MaidExaminationCtrl.MaidExamination maidExamination2 = maidExamination.Copy();
			if (i % 2 == 0)
			{
				maidExamination2.arrayAcquiredMaidClassType = null;
				maidExamination2.arrayAcquiredYotogiClassType = null;
			}
			maidExamination2.firstName = "メイド名_" + i;
			maidExamination2.lastName = "メイド姓_" + i;
			bool flag = maidExamination2.arrayAcquiredMaidClassType != null && maidExamination2.arrayAcquiredMaidClassType.Length > 0;
			bool flag2 = maidExamination2.arrayAcquiredYotogiClassType != null && maidExamination2.arrayAcquiredYotogiClassType.Length > 0;
			if (flag || flag2)
			{
				list.Add(maidExamination2);
			}
		}
		return list;
	}

	private List<MaidExaminationCtrl.MaidExamination> m_listData;

	private List<Maid> m_check_maid_list = new List<Maid>();

	private MaidExaminationCtrl m_ctrl;

	private CompetitiveShowAPI m_api;

	private int m_currentMaidNo;

	private const int FIRST_MAID_NO = 0;
}
