using System.Collections.Generic;
using UnityEngine;

namespace Wizard.Lottery;

public class LotteryMissionDialog : MonoBehaviour
{
	[SerializeField]
	private GameObject _lotteryMissionItemPrefab;

	[SerializeField]
	private UIGrid _grid;

	public static void Create(GameObject prefab, LotteryInfoTask.LotteryInfoData lotteryData)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		LotteryMissionDialog component = Object.Instantiate(prefab).GetComponent<LotteryMissionDialog>();
		dialogBase.SetObj(component.gameObject);
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Data.SystemText.Get("Mission_0075"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
		component.Initialize(lotteryData);
	}

	private void Initialize(LotteryInfoTask.LotteryInfoData lotteryData)
	{
		List<LotteryMissionData> list = new List<LotteryMissionData>(lotteryData.LotteryMissionList);
		if (lotteryData.BigChanceMission != null)
		{
			list.Add(lotteryData.BigChanceMission);
		}
		for (int i = 0; i < list.Count; i++)
		{
			LotteryMissionData lotteryData2 = list[i];
			bool flag = i + 1 == list.Count;
			AchievementWindowBase component = NGUITools.AddChild(_grid.gameObject, _lotteryMissionItemPrefab).GetComponent<AchievementWindowBase>();
			component.gameObject.SetActive(value: true);
			component.SetLottery(lotteryData2, !flag);
		}
		_grid.Reposition();
	}
}
