using System.Collections.Generic;
using UnityEngine;

namespace Wizard;

public class StorySummaryDialog : MonoBehaviour
{
	public enum SummaryType
	{
		SummaryOnly,
		ClassNameList,
		CharaSelect
	}

	private readonly Vector3 SUMMARY_LABEL_POS = Vector3.zero;

	private readonly Vector3 SUMMARY_LABEL_POS_BATTLESKIP = new Vector3(0f, 52f, 0f);

	private readonly Vector3 SUMMARY_LABEL_POS_CLASSLIST = new Vector3(0f, 62f, 0f);

	private readonly Vector3 SUMMARY_LABEL_POS_CHARALIST = new Vector3(0f, 131f, 0f);

	private readonly Vector3 SUMMARY_LABEL_POS_BATTLESKIP_CLASSLIST = new Vector3(0f, 96f, 0f);

	private readonly Vector3 SUMMARY_LABEL_POS_BATTLESKIP_CHARALIST = new Vector3(0f, 131f, 0f);

	private readonly Vector3 CLASS_PARENT_POS = new Vector3(0f, -70f, 0f);

	private readonly Vector3 CLASS_PARENT_POS_BATTLESKIP = Vector3.zero;

	private readonly Vector3 CHARA_PARENT_POS = new Vector3(0f, -53f, 0f);

	private readonly Vector3 CHARA_LINE_POS = new Vector3(0f, 24f, 0f);

	[SerializeField]
	private UILabel _summaryLabel;

	[SerializeField]
	private GameObject _toggleParent;

	[SerializeField]
	private UIToggle _toggleSingle;

	[SerializeField]
	private UILabel _labelToggleSingle;

	[SerializeField]
	private UIToggle _toggleBattleSkip;

	[SerializeField]
	private UIToggle _toggleMovieSubtitles;

	[SerializeField]
	private GameObject _iconObjectParent;

	[SerializeField]
	private UITable _classIconNameTable_1;

	[SerializeField]
	private UITable _classIconNameTable_2;

	[SerializeField]
	private ClassIconName _classIconNameOriginal;

	[SerializeField]
	private GameObject _charaSlectLineObject;

	private SummaryType _summaryType;

	public void SetSummary(string summary, bool isBattleSkipToggle, bool isMovieSubtitles, StoryChapterData chapterData, SummaryType summaryType)
	{
		_summaryType = summaryType;
		SetToggleButtons(isBattleSkipToggle, isMovieSubtitles);
		bool flag = isBattleSkipToggle || isMovieSubtitles;
		_summaryLabel.height = (flag ? 208 : 264);
		_summaryLabel.SetWrapText(summary);
		switch (_summaryType)
		{
		case SummaryType.SummaryOnly:
			SetLayoutSummaryOnly(flag);
			break;
		case SummaryType.ClassNameList:
			SetLayoutClassNameList(flag, chapterData);
			break;
		case SummaryType.CharaSelect:
			SetLayoutCharaSelect(flag);
			break;
		}
	}

	public void SetLayoutSummaryOnly(bool isToggle)
	{
		_iconObjectParent.gameObject.SetActive(value: false);
		_summaryLabel.transform.localPosition = (isToggle ? SUMMARY_LABEL_POS_BATTLESKIP : SUMMARY_LABEL_POS);
	}

	public void SetLayoutClassNameList(bool isToggle, StoryChapterData chapterData)
	{
		SetAbleDeckClassList(chapterData.AvailableDeckClassList);
		_iconObjectParent.gameObject.SetActive(value: true);
		_summaryLabel.transform.localPosition = (isToggle ? SUMMARY_LABEL_POS_BATTLESKIP_CLASSLIST : SUMMARY_LABEL_POS_CLASSLIST);
		_iconObjectParent.transform.localPosition = (isToggle ? CLASS_PARENT_POS_BATTLESKIP : CLASS_PARENT_POS);
	}

	public void SetLayoutCharaSelect(bool isToggle)
	{
		_summaryLabel.transform.localPosition = (isToggle ? SUMMARY_LABEL_POS_BATTLESKIP_CHARALIST : SUMMARY_LABEL_POS_CHARALIST);
		if (!isToggle)
		{
			_iconObjectParent.transform.localPosition = CHARA_PARENT_POS;
			_charaSlectLineObject.transform.localPosition = CHARA_LINE_POS;
		}
	}

	private void SetToggleButtons(bool isBattleSkip, bool isMovieSubtitles)
	{
		if (!isBattleSkip && !isMovieSubtitles)
		{
			_toggleParent.SetActive(value: false);
			return;
		}
		_toggleParent.SetActive(value: true);
		_toggleSingle.gameObject.SetActive(value: false);
		_toggleBattleSkip.gameObject.SetActive(value: false);
		_toggleMovieSubtitles.gameObject.SetActive(value: false);
		if (isBattleSkip && isMovieSubtitles)
		{
			SetBattleSkipToggle(_toggleBattleSkip);
			SetMovieSubtitlesToggle(_toggleMovieSubtitles);
		}
		else if (isBattleSkip)
		{
			SetBattleSkipToggle(_toggleSingle);
			_labelToggleSingle.text = Data.SystemText.Get("Story_0035");
		}
		else if (isMovieSubtitles)
		{
			SetMovieSubtitlesToggle(_toggleSingle);
			_labelToggleSingle.text = Data.SystemText.Get("OtherConfig_0064");
		}
	}

	private void SetBattleSkipToggle(UIToggle toggle)
	{
		toggle.gameObject.SetActive(value: true);
		toggle.value = PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.IS_SKIP_CLEARED_STORY_BATTLE);
		bool isFirst = true;
		EventDelegate.Add(toggle.onChange, delegate
		{
			if (!isFirst)
			{
				GameMgr.GetIns().GetSoundMgr().PlayToggleSe(toggle.value);
			}
			isFirst = false;
			PlayerPrefsWrapper.SetBool(PlayerPrefsWrapper.IS_SKIP_CLEARED_STORY_BATTLE, toggle.value);
		});
	}

	private void SetMovieSubtitlesToggle(UIToggle toggle)
	{
		toggle.gameObject.SetActive(value: true);
		toggle.value = PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.MOVIE_SUBTITLES);
		bool isFirst = true;
		EventDelegate.Add(toggle.onChange, delegate
		{
			if (!isFirst)
			{
				GameMgr.GetIns().GetSoundMgr().PlayToggleSe(toggle.value);
			}
			isFirst = false;
			PlayerPrefsWrapper.SetBool(PlayerPrefsWrapper.MOVIE_SUBTITLES, toggle.value);
		});
	}

	private void SetAbleDeckClassList(List<int> classIds)
	{
		_classIconNameOriginal.gameObject.SetActive(value: false);
		_classIconNameTable_1.gameObject.SetActive(value: true);
		if (classIds.Count > _classIconNameTable_1.columns)
		{
			_classIconNameTable_2.gameObject.SetActive(value: true);
		}
		else
		{
			_classIconNameTable_2.gameObject.SetActive(value: false);
		}
		for (int i = 0; i < classIds.Count; i++)
		{
			ClassIconName classIconName = null;
			classIconName = ((i >= _classIconNameTable_1.columns) ? NGUITools.AddChild(_classIconNameTable_2.gameObject, _classIconNameOriginal.gameObject).GetComponent<ClassIconName>() : NGUITools.AddChild(_classIconNameTable_1.gameObject, _classIconNameOriginal.gameObject).GetComponent<ClassIconName>());
			classIconName.SetClass(classIds[i]);
			classIconName.gameObject.SetActive(value: true);
		}
	}
}
