using System.Collections.Generic;
using UnityEngine;

namespace Wizard;

public class PracticePuzzleMissionDialog : MonoBehaviour
{
	[SerializeField]
	private SimpleScrollViewUI _simpleScrollView;

	[SerializeField]
	private ResourceHandler _resourceHandler;

	[SerializeField]
	private GameObject _missionNotExist;

	private List<PracticePuzzleMissionData> _missionList;

	public static void Create(List<PracticePuzzleMissionData> missionList, GameObject prefab)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Data.SystemText.Get("Mission_0003"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
		PracticePuzzleMissionDialog component = Object.Instantiate(prefab).GetComponent<PracticePuzzleMissionDialog>();
		dialogBase.SetObj(component.gameObject);
		component.Initialize(missionList);
	}

	private void Initialize(List<PracticePuzzleMissionData> missionList)
	{
		_missionList = missionList;
		_missionNotExist.SetActive(missionList.Count == 0);
		_simpleScrollView.CreateScrollView(missionList.Count, UpdateMissionPlate);
	}

	private void UpdateMissionPlate(int index, GameObject plateObject)
	{
		PracticePuzzleMissionData mission = _missionList[index];
		plateObject.GetComponent<UISprite>().width = 800;
		plateObject.GetComponent<AchievementWindowBase>().SetPracticePuzzleMission(mission, _resourceHandler, canChangeMissions: false, index != _missionList.Count - 1, displayChange: false);
	}
}
