using System;
using System.Linq;
using UnityEngine;

namespace Wizard;

public class StoryChapterSelectDialog : MonoBehaviour
{
	[SerializeField]
	private GameObject _originalObject;

	[SerializeField]
	private Transform _objRoot;

	[SerializeField]
	private UILabel _descriptionText;

	public void Initialize(ScenarioSummary scenarioSummary, StoryChapterData chapterData, Action<StoryChapterData.SubChapterData> unitReadAction, Action allReadAction)
	{
		string chapterId = chapterData.ChapterId;
		_descriptionText.text = Data.SystemText.Get("Story_0074", chapterId, chapterData.NextChapterId);
		_originalObject.gameObject.SetActive(value: false);
		bool isExistMaintenanceSubChapter = chapterData.SubChapterDatas.Any((StoryChapterData.SubChapterData item) => item.IsMaintenanceChapter);
		GameObject obj = UnityEngine.Object.Instantiate(_originalObject, _objRoot);
		obj.SetActive(value: true);
		obj.GetComponent<SubChapterStorySectionBtn>().AllRead(allReadAction, chapterData.AllReadButtonPath, isExistMaintenanceSubChapter);
		foreach (StoryChapterData.SubChapterData subChapterData in chapterData.SubChapterDatas)
		{
			GameObject obj2 = UnityEngine.Object.Instantiate(_originalObject, _objRoot);
			obj2.SetActive(value: true);
			obj2.GetComponent<SubChapterStorySectionBtn>().UnitRead(scenarioSummary.GetData(chapterId, subChapterData.SubChapterId), subChapterData, unitReadAction);
		}
		_objRoot.GetComponent<UIGrid>().Reposition();
	}
}
