using System;
using System.Collections.Generic;
using System.Linq;
using Cute;
using UnityEngine;

namespace Wizard;

public class StoryLeaderSelectSummaryDialog : StorySummaryDialog
{
	[SerializeField]
	private GameObject _charaSelectionButton;

	[SerializeField]
	private UISprite _selectMarkSprite;

	[SerializeField]
	private UIGrid _charaButtonGrid;

	private List<string> _loadPathList = new List<string>();

	private List<ClassSelectionButton> _charaSelectionButtons = new List<ClassSelectionButton>();

	private ClassSelectionButton _selectCharaSelectionButton;

	private TweenAlpha _selectMarkTweenAlpha;

	private Action<ClassCharacterMasterData> _selectCharaAction;

	public void SetLeaderSelectSummary(string summary, bool isBattleSkipToggle, bool isMovieSubtitles, StoryChapterData chapterData, Action<ClassCharacterMasterData> selectCharaAction)
	{
		_selectCharaAction = selectCharaAction;
		_selectMarkTweenAlpha = _selectMarkSprite.GetComponent<TweenAlpha>();
		List<ClassCharacterMasterData> _classCharacterMasterDatas = new List<ClassCharacterMasterData>();
		foreach (int charaId in chapterData.CharaIdList)
		{
			_classCharacterMasterDatas.Add(GameMgr.GetIns().GetDataMgr().GetCharaPrmByCharaId(charaId));
		}
		ResourcesManager resMgr = Toolbox.ResourcesManager;
		foreach (ClassCharacterMasterData item in _classCharacterMasterDatas)
		{
			_loadPathList.Add(resMgr.GetAssetTypePath(item.skin_id.ToString(), ResourcesManager.AssetLoadPathType.ClassCharaButton));
		}
		StartCoroutine(resMgr.LoadAssetGroupAsync(_loadPathList, delegate
		{
			SetSummary(summary, isBattleSkipToggle, isMovieSubtitles, chapterData, SummaryType.CharaSelect);
			_charaSelectionButton.gameObject.SetActive(value: false);
			foreach (ClassCharacterMasterData item2 in _classCharacterMasterDatas)
			{
				ClassSelectionButton component = UnityEngine.Object.Instantiate(_charaSelectionButton, _charaSelectionButton.transform.parent).GetComponent<ClassSelectionButton>();
				component.gameObject.SetActive(value: true);
				component.Init(item2, resMgr.LoadObject<Texture>(resMgr.GetAssetTypePath(item2.skin_id.ToString(), ResourcesManager.AssetLoadPathType.ClassCharaButton, isfetch: true)), OnClickCharaButton, isShowStoryClearLabel: false, isShowUsedLabel: false, showNotificationIcon: false);
				_charaSelectionButtons.Add(component);
			}
			_charaButtonGrid.Reposition();
			SelectChara(_charaSelectionButtons.First());
		}));
	}

	private void OnClickCharaButton(ClassSelectionButton classButton)
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON);
		SelectChara(classButton);
	}

	private void SelectChara(ClassSelectionButton charaButton)
	{
		if (!(_selectCharaSelectionButton == charaButton))
		{
			_selectCharaSelectionButton = charaButton;
			_selectMarkSprite.transform.position = charaButton.transform.position;
			_selectMarkTweenAlpha.PlayPingPong(isIncreaseAlpha: false);
			_selectCharaAction(_selectCharaSelectionButton.ClassCharacterMasterData);
		}
	}
}
