using System;
using Cute;
using UnityEngine;

namespace Wizard;

public class GachaPackPointLayout : MonoBehaviour
{
	[SerializeField]
	private GameObject _packPointGaugeRoot;

	[SerializeField]
	private UIGauge _packPointGauge;

	[SerializeField]
	private UILabel _packPointGaugePointLabel;

	[SerializeField]
	private UIButton _packPointExchangeButton;

	[SerializeField]
	private UILabel _packPointExchangeButtonLabel;

	public void SetActivePackPointLayout(bool isActive)
	{
		_packPointGaugeRoot.gameObject.SetActive(isActive);
	}

	public void SetPackPointLayout(PackConfig packConfig, Action onClickExchange)
	{
		if ((packConfig.Category != PackCategory.None && packConfig.Category != PackCategory.LeaderSkinPack) || packConfig.GachaPointData == null)
		{
			SetActivePackPointLayout(isActive: false);
			return;
		}
		SetActivePackPointLayout(isActive: true);
		GachaPointData gachaPointData = packConfig.GachaPointData;
		SetPointGauge(gachaPointData);
		SetExchangeButton(gachaPointData, onClickExchange);
	}

	private void SetPointGauge(GachaPointData pointData)
	{
		_packPointGauge.Value = (float)pointData.GachaPoint / (float)pointData.ExchangeableGachaPoint;
		_packPointGaugePointLabel.text = pointData.GachaPoint + "/" + pointData.ExchangeableGachaPoint;
	}

	private void SetExchangeButton(GachaPointData pointData, Action onClickExchange)
	{
		if (pointData.IsExchangeableGachaPoint)
		{
			_packPointExchangeButtonLabel.text = Data.SystemText.Get("Shop_0168");
			_packPointExchangeButton.normalSprite = "btn_common_03_s_off";
			_packPointExchangeButton.pressedSprite = "btn_common_03_s_on";
		}
		else
		{
			_packPointExchangeButtonLabel.text = Data.SystemText.Get("Shop_0169");
			_packPointExchangeButton.normalSprite = "btn_common_02_s_off";
			_packPointExchangeButton.pressedSprite = "btn_common_02_s_on";
		}
		_packPointExchangeButton.onClick.Clear();
		_packPointExchangeButton.onClick.Add(new EventDelegate(delegate
		{
			onClickExchange.Call();
		}));
	}
}
