using System;
using System.Collections;
using UnityEngine;
using Wizard.Bingo;

namespace Wizard;

public class BingoSelectBuyNumPopup : SelectBuyNumPopupBase
{
	[SerializeField]
	private UILabel _sheetLabel;

	[SerializeField]
	private UILabel _sheetNumLabel;

	[SerializeField]
	private UILabel _remainedLabel;

	[SerializeField]
	private UILabel _remainedNumLabel;

	[SerializeField]
	private CenteringUIWidget _line1;

	[SerializeField]
	private CenteringUIWidget _line2;

	protected override string _labelBuyNumPurchaseBtnTextId => "Bingo_0018";

	public void Init(DialogBase dialog, int ableBuyNum, int openedNum, BingoInfoTask.BingoInfoData bingoInfoData, Action<int> OnClickPurchase)
	{
		_dialog = dialog;
		_gachaCostPerPack = 1;
		_ableBuyNum = ableBuyNum;
		InitBuyMeansDisplays(bingoInfoData, openedNum);
		UpdateBuyNumDisplays();
		UIEventListener.Get(_buttonPlus.gameObject).onPress = base.OnPressToPlusBtn;
		UIEventListener.Get(_buttonMinus.gameObject).onPress = base.OnPressToMinusBtn;
		UIEventListener.Get(_buttonMax.gameObject).onClick = delegate
		{
			OnBtnMax();
		};
		UIEventListener.Get(_buttonPurchase.gameObject).onClick = delegate
		{
			dialog.Close();
			OnClickPurchase(_buyNum);
		};
	}

	private void InitBuyMeansDisplays(BingoInfoTask.BingoInfoData bingoInfoData, int openedNum)
	{
		_buyPackLabel.text = Data.SystemText.Get("Bingo_0026");
		_sheetLabel.text = Data.SystemText.Get("Bingo_0027");
		_sheetNumLabel.text = Data.SystemText.Get("Bingo_0028", bingoInfoData.SheetNum.ToString());
		_remainedLabel.text = Data.SystemText.Get("Bingo_0029");
		_remainedNumLabel.text = Data.SystemText.Get("Bingo_0030", (bingoInfoData.MaxSquareNum - openedNum).ToString());
		UIManager.GetInstance().StartCoroutine(LineReposition());
		_labelCostNamePurchaseBtn.text = Data.SystemText.Get("Bingo_0019");
		_labelHaveItemName.text = Data.SystemText.Get("Bingo_0016");
		_labelHaveNumItems.text = bingoInfoData.BingoTicketNum.ToString();
		_labelCostPerPack.text = Data.SystemText.Get("Bingo_0017", bingoInfoData.BingoDrawCost.ToString());
	}

	private IEnumerator LineReposition()
	{
		_sheetLabel.ProcessText();
		_sheetNumLabel.ProcessText();
		_remainedLabel.ProcessText();
		_remainedNumLabel.ProcessText();
		yield return null;
		_line1.Reposition();
		_line2.Reposition();
	}
}
