using System;
using System.Collections;
using System.Collections.Generic;
using Cute;
using UnityEngine;

namespace Wizard;

public class BattlePassResultPanel : MonoBehaviour
{
	[SerializeField]
	private BattlePassGuage _battlePassGuage;

	[SerializeField]
	private UIButton _tapTrriger;

	[SerializeField]
	private ParticleSystem _lineEfc;

	[Header("ラベル")]
	[SerializeField]
	private GameObject _battleWin;

	[SerializeField]
	private UILabel _battleWinLabel;

	[SerializeField]
	private UILabel _battleWinPointLabel;

	[SerializeField]
	private GameObject _missionClear;

	[SerializeField]
	private UILabel _missionClearLabel;

	[SerializeField]
	private UILabel _missionClearPointLabel;

	[SerializeField]
	private GameObject _battleMissionClear;

	[SerializeField]
	private UILabel _battleMissionClearLabel;

	[SerializeField]
	private UILabel _battleMissionClearPointLabel;

	[SerializeField]
	private UILabel _weeklyGetLimitLabel;

	[SerializeField]
	private UILabel _weeklyGetLimitPointLabel;

	[SerializeField]
	private UIGrid _uiGrid;

	private float GAUGEUP_LABEL_DURATION = 0.5f;

	private float GAUGEUP_LABEL_MOVE_DISTANCE = 50f;

	private BattlePassGaugeInfo _battlePassGaugeInfo;

	private List<string> _loadedEffectResources = new List<string>();

	private Action _closeAction;

	private bool _isClosePanel;

	public void Initialize(BattlePassGaugeInfo battlePassGaugeInfo)
	{
		_battlePassGuage.LvUpInitialize(battlePassGaugeInfo);
		_tapTrriger.onClick.Add(new EventDelegate(Close));
		base.gameObject.SetActive(value: false);
		_battleWinLabel.text = Data.SystemText.Get("BattlePass_0014");
		_battleWin.SetActive(value: false);
		_battleWinPointLabel.text = "+" + battlePassGaugeInfo.BattleResultPoint;
		_missionClearLabel.text = Data.SystemText.Get("BattlePass_0015");
		_missionClear.SetActive(value: false);
		_missionClearPointLabel.text = "+" + battlePassGaugeInfo.DailryMissionPoint;
		_battleMissionClearLabel.text = Data.SystemText.Get("BattlePass_0016");
		_battleMissionClear.SetActive(value: false);
		_battleMissionClearPointLabel.text = "+" + battlePassGaugeInfo.BattlePassMissionPoint;
		_weeklyGetLimitLabel.text = Data.SystemText.Get("BattlePass_0017");
		_weeklyGetLimitPointLabel.text = battlePassGaugeInfo.WeeklyBattlePassPoint + "/" + battlePassGaugeInfo.WeeklyLimitPoint;
		_battlePassGaugeInfo = battlePassGaugeInfo;
	}

	public void SetPointupAnimation(Action closeAction)
	{
		_closeAction = closeAction;
		List<GameObject> list = new List<GameObject>();
		list.Add(_lineEfc.gameObject);
		list.Add(_battlePassGuage.GaugeEfc.gameObject);
		_loadedEffectResources.AddRange(GameMgr.GetIns().GetEffectMgr().SetUIParticleShader(list, delegate
		{
			base.gameObject.SetActive(value: true);
			StartCoroutine(FadeAction(isIn: true));
			_lineEfc.gameObject.SetActive(value: true);
			_lineEfc.Play();
			_battlePassGuage.AddBattlePassPoint();
			StartCoroutine(SetLvupAnimation());
		}));
	}

	private IEnumerator SetLvupAnimation()
	{
		_battleWin.SetActive(_battlePassGaugeInfo.BattleResultPoint != 0);
		_missionClear.SetActive(_battlePassGaugeInfo.DailryMissionPoint != 0);
		_battleMissionClear.SetActive(_battlePassGaugeInfo.BattlePassMissionPoint != 0);
		_uiGrid.Reposition();
		_battleWin.SetActive(value: false);
		_missionClear.SetActive(value: false);
		_battleMissionClear.SetActive(value: false);
		yield return new WaitForSeconds(0.5f);
		if (_battlePassGaugeInfo.BattleResultPoint != 0)
		{
			_battleWin.SetActive(value: true);
			TextAnimation(_battleWinLabel.gameObject);
			TextAnimation(_battleWinPointLabel.gameObject);
		}
		if (_battlePassGaugeInfo.DailryMissionPoint != 0)
		{
			_missionClear.SetActive(value: true);
			TextAnimation(_missionClearLabel.gameObject);
			TextAnimation(_missionClearPointLabel.gameObject);
		}
		if (_battlePassGaugeInfo.BattlePassMissionPoint != 0)
		{
			_battleMissionClear.SetActive(value: true);
			TextAnimation(_battleMissionClearLabel.gameObject);
			TextAnimation(_battleMissionClearPointLabel.gameObject);
		}
	}

	private void Close()
	{
		if (_battlePassGuage.IsAnimationComplete && !_isClosePanel)
		{
			_isClosePanel = true;
			_lineEfc.Clear();
			StartCoroutine(FadeAction(isIn: false, delegate
			{
				base.gameObject.SetActive(value: false);
				UnLoadEffect();
				_closeAction();
			}));
		}
	}

	private void UnLoadEffect()
	{
		Toolbox.ResourcesManager.RemoveAssetGroup(_loadedEffectResources);
		_loadedEffectResources.Clear();
	}

	private void TextAnimation(GameObject label)
	{
		label.SetActive(value: true);
		TweenAlpha.Begin(label.gameObject, GAUGEUP_LABEL_DURATION, 1f);
		iTween.MoveFrom(label, iTween.Hash("x", label.transform.localPosition.x - GAUGEUP_LABEL_MOVE_DISTANCE, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
	}

	public IEnumerator FadeAction(bool isIn, Action fadeEndAction = null)
	{
		float num = 0.2f;
		float alpha = (isIn ? 0f : 1f);
		float alpha2 = (isIn ? 1f : 0f);
		TweenAlpha.Begin(base.gameObject, 0f, alpha);
		TweenAlpha.Begin(base.gameObject, num, alpha2);
		yield return new WaitForSeconds(num);
		fadeEndAction.Call();
	}
}
