using System.Collections.Generic;
using UnityEngine;

namespace Wizard;

public class SealedClassSelectConfirmDialog : MonoBehaviour
{
	[SerializeField]
	private ClassInfoParts _classInfoParts;

	[SerializeField]
	private UILabel _cardListLabel;

	[SerializeField]
	private UIToggle _cardAutoOpenToggleButton;

	private bool isFirstToggleChange = true;

	public void Init(int classId, List<int> cardList)
	{
		_classInfoParts.InitByCharaPrm(GameMgr.GetIns().GetDataMgr().GetCharaPrmByClassId(classId));
		_cardListLabel.text = string.Empty;
		for (int i = 0; i < cardList.Count; i++)
		{
			if (i != 0)
			{
				_cardListLabel.text += "\n";
			}
			_cardListLabel.text += CardMaster.GetInstance(FormatBehaviorManager.GetDefaultBehaviour(Format.Sealed).CardMasterId).GetCardParameterFromId(cardList[i]).CardName;
		}
		_cardAutoOpenToggleButton.value = PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.CARDPACK_CARD_AUTO_OPEN);
		EventDelegate.Add(_cardAutoOpenToggleButton.onChange, OnChangeCardAutoOpenToggleButton);
	}

	private void OnChangeCardAutoOpenToggleButton()
	{
		if (isFirstToggleChange)
		{
			isFirstToggleChange = false;
			return;
		}
		bool value = _cardAutoOpenToggleButton.value;
		GameMgr.GetIns().GetSoundMgr().PlaySe(value ? Se.TYPE.SYS_TOGGLE_ON : Se.TYPE.SYS_TOGGLE_OFF);
		PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.CARDPACK_CARD_AUTO_OPEN, value);
	}
}
