using System;
using Cute;
using UnityEngine;

namespace Wizard;

public class CompleteDeckDecideDialog
{
	private const string DECK_DECISION_PATH = "UI/DeckList/DeckDecision";

	private const int DECK_SELECT_DIALOG_PANEL_DEPTH = 15;

	public DialogBase Dialog { get; private set; }

	public DeckDecisionUI DecisionUI { get; private set; }

	public static CompleteDeckDecideDialog CreateForSingleDeck(DialogBase dialogDeckList, DeckData deck, bool showSimpleStageOption, Action onDecide, ConventionDeckList conventionDeckList = null)
	{
		CompleteDeckDecideDialog completeDeckDecideDialog = new CompleteDeckDecideDialog(showSimpleStageOption);
		completeDeckDecideDialog.InitializeForSingleDeck(dialogDeckList, deck, onDecide, conventionDeckList);
		return completeDeckDecideDialog;
	}

	public static CompleteDeckDecideDialog CreateForMultiDeck(DialogBase dialogDeckList, string textBody, bool showSimpleStageOption, Action onDecide, Action onCancel)
	{
		CompleteDeckDecideDialog completeDeckDecideDialog = new CompleteDeckDecideDialog(showSimpleStageOption);
		completeDeckDecideDialog.InitializeForMultiDeck(dialogDeckList, textBody, onDecide, onCancel);
		return completeDeckDecideDialog;
	}

	private CompleteDeckDecideDialog(bool showSimpleStageOption)
	{
		CreateDialogBase(showSimpleStageOption);
	}

	private void CreateDialogBase(bool showSimpleStageOption)
	{
		Dialog = UIManager.GetInstance().CreateDialogClose();
		Dialog.SetTitleLabel(Data.SystemText.Get("Dia_DeckSelect_001_Title"));
		Dialog.SetPanelDepth(15);
		DecisionUI = UnityEngine.Object.Instantiate(Toolbox.ResourcesManager.LoadObject<DeckDecisionUI>("UI/DeckList/DeckDecision", isServerResources: false));
		DecisionUI.IsShowSimpleStageOption = showSimpleStageOption;
		Dialog.SetObj(DecisionUI.gameObject);
	}

	private void InitializeForSingleDeck(DialogBase dialogDeckList, DeckData deck, Action onDecide, ConventionDeckList conventionDeckList = null)
	{
		Dialog.SetButtonText(Data.SystemText.Get("Common_0004"), Data.SystemText.Get("Card_0083"));
		Dialog.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_GrayBtn);
		Dialog.ClickSe_Btn1 = Se.TYPE.NONE;
		DecisionUI.SetDeckData(deck, conventionDeckList);
		DecisionUI.DeckName = deck.GetDeckName();
		Dialog.onPushButton2 = DecisionUI.OnClickCreateCardList;
		Dialog.ClickSe_Btn2 = Se.TYPE.SYS_BTN_DECIDE;
		Dialog.isNotCloseWindowButton2 = true;
		Dialog.onPushButton1 = delegate
		{
			Dialog.button1.isEnabled = false;
			if (dialogDeckList != null)
			{
				dialogDeckList.CloseWithoutSelect();
			}
			onDecide.Call();
		};
	}

	private void InitializeForMultiDeck(DialogBase dialogDeckList, string textBody, Action onDecide, Action onCancel)
	{
		Dialog.SetButtonText(Data.SystemText.Get("Common_0004"));
		Dialog.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		Dialog.ClickSe_Btn1 = Se.TYPE.NONE;
		DecisionUI.SetText(textBody, string.Empty);
		Dialog.onPushButton1 = delegate
		{
			Dialog.button1.isEnabled = false;
			dialogDeckList.CloseWithoutSelect();
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
			onDecide();
		};
		Dialog.onPushButton2 = delegate
		{
			onCancel();
		};
		Dialog.onCloseWithoutSelect = delegate
		{
			onCancel();
		};
	}
}
