using System;
using LitJson;

namespace Wizard;

public class MyPageFinishBattleTask : BaseTask
{
	public class MyPageFinishBattleParam : BaseParam
	{
		public int SDTRB;
	}

	public Action UnfinishedBattleDialogCloseCallBack { get; set; }

	public MyPageFinishBattleTask()
	{
		base.type = ApiType.Type.MypageFinishBattle;
	}

	public void SetParameter()
	{
		MyPageFinishBattleParam myPageFinishBattleParam = new MyPageFinishBattleParam();
		myPageFinishBattleParam.SDTRB = (int)PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.SELF_DISCONNECT_OPEN_STATUS_TO_REPLACE_LOG);
		PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.SELF_DISCONNECT_OPEN_STATUS_TO_REPLACE_LOG, 0f);
		base.Params = myPageFinishBattleParam;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		int num2 = 0;
		string text = "check_unfinished_battle";
		if (base.ResponseData["data"].Keys.Contains(text) && base.ResponseData["data"][text] != null)
		{
			num2 = base.ResponseData["data"][text].ToInt();
		}
		if (base.ResponseData["data"].Keys.Contains("treasure_info"))
		{
			JsonData jsonData = base.ResponseData["data"]["treasure_info"];
			if (jsonData != null)
			{
				Data.MyPageNotifications.data.CampaignBattleWin.Parse(jsonData);
			}
		}
		if (base.ResponseData["data"].TryGetValue("upgrade_treasure_box_info", out var value))
		{
			Data.TreasureBoxCp.Parse(value, base.ResponseData["data_headers"]);
		}
		if (num2 != 0)
		{
			GameMgr.GetIns().GetDataMgr().SetClassPrm(base.ResponseData["data"]["user_class_list"], base.ResponseData["data"]["user_rank_match_list"]);
			Data.Load.data.ParseUserRank(base.ResponseData["data"]);
			if (Data.MyPage.data.IsExistUnfinishedBattle)
			{
				DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
				dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
				dialogBase.SetPanelDepth(15);
				if (UnfinishedBattleDialogCloseCallBack != null)
				{
					dialogBase.OnClose = UnfinishedBattleDialogCloseCallBack;
				}
				switch (num2)
				{
				case 1:
					try
					{
						switch (base.ResponseData["data"]["is_win"].ToInt())
						{
						case 0:
							dialogBase.SetTitleLabel(Data.SystemText.Get("Battle_0410"));
							dialogBase.SetText(Data.SystemText.Get("Battle_0478"));
							dialogBase.SetSize(DialogBase.Size.M);
							break;
						case 1:
							dialogBase.SetTitleLabel(Data.SystemText.Get("Battle_0410"));
							dialogBase.SetText(Data.SystemText.Get("Battle_0479"));
							dialogBase.SetSize(DialogBase.Size.M);
							break;
						case 2:
							dialogBase.SetTitleLabel(Data.SystemText.Get("Battle_0410"));
							dialogBase.SetText(Data.SystemText.Get("Battle_0480"));
							dialogBase.SetSize(DialogBase.Size.M);
							break;
						}
					}
					catch
					{
						dialogBase.SetTitleLabel(Data.SystemText.Get("Battle_0410"));
						dialogBase.SetText(Data.SystemText.Get("Battle_0402"));
						dialogBase.SetSize(DialogBase.Size.M);
					}
					break;
				case 2:
					dialogBase.SetTitleLabel(Data.SystemText.Get("Battle_0412"));
					dialogBase.SetText(Data.SystemText.Get("Battle_0401"));
					break;
				case 3:
					dialogBase.SetTitleLabel(Data.SystemText.Get("Battle_0410"));
					dialogBase.SetText(Data.SystemText.Get("Battle_0413"));
					break;
				case 4:
					dialogBase.SetTitleLabel(Data.SystemText.Get("Battle_0410"));
					dialogBase.SetText(Data.SystemText.Get("Battle_0474"));
					break;
				default:
					dialogBase.SetTitleLabel(Data.SystemText.Get("Battle_0412"));
					dialogBase.SetText(Data.SystemText.Get("Battle_0401"));
					break;
				}
				if (base.ResponseData["data"].Keys.Contains("reward_list"))
				{
					PlayerStaticData.UpdateHaveUserGoodsNumByJsonData(base.ResponseData["data"]["reward_list"]);
				}
				if (base.ResponseData["data"].Keys.Contains("freebie_status"))
				{
					Data.ArenaData.CompetitionData.FreebieStatus = (ArenaCompetition.FreebieStatusType)base.ResponseData["data"]["freebie_status"].ToInt();
				}
			}
		}
		return num;
	}
}
