using System.Collections;
using UnityEngine;

namespace Wizard;

public class ShopPanelAppealItem : MonoBehaviour
{
	[SerializeField]
	private GameObject _rootAppealObj;

	[SerializeField]
	private GameObject _objNewMark;

	[SerializeField]
	private UILabel _labelRemainTime;

	[SerializeField]
	[Tooltip("残り{0}日")]
	private string _remainDayTextId = "MyPage_0062";

	[SerializeField]
	[Tooltip("残り{0}時間")]
	private string _remainHourTextId = "MyPage_0063";

	[SerializeField]
	[Tooltip("残り{0}分")]
	private string _remainMinuteTextId = "MyPage_0064";

	public void SetActiveAppealObj(bool isActive)
	{
		_rootAppealObj.SetActive(isActive);
	}

	public void DelaySetActiveAppealObj(bool isActive, float delayTime)
	{
		if (base.gameObject.activeInHierarchy)
		{
			StartCoroutine(DelaySetActiveCoroutin(isActive, delayTime));
		}
	}

	private IEnumerator DelaySetActiveCoroutin(bool isActive, float delayTime)
	{
		yield return new WaitForSeconds(delayTime);
		SetActiveAppealObj(isActive);
	}

	public void SetAppeal(ShopNotification.ShopAppealInfo appealInfo)
	{
		if (appealInfo.NeedsCampaignDisplay)
		{
			SetCampaignDisplay();
			SetActiveNewMark(appealInfo.IsNew);
		}
		else if (appealInfo.RemainTime != null)
		{
			SetRemainTimeLabel(appealInfo.RemainTime.Second);
			SetActiveNewMark(isActive: false);
		}
		else
		{
			SetActiveNewMark(appealInfo.IsNew);
			SetActiveRemainTime(isActive: false);
		}
	}

	public void SetActiveNewMark(bool isActive)
	{
		_objNewMark?.SetActive(isActive);
	}

	public void SetActiveRemainTime(bool isActive)
	{
		_labelRemainTime?.gameObject.SetActive(isActive);
	}

	private void SetRemainTimeLabel(int limitTime)
	{
		if (_labelRemainTime == null)
		{
			return;
		}
		if (limitTime <= 0)
		{
			_labelRemainTime.gameObject.SetActive(value: false);
			return;
		}
		_labelRemainTime.gameObject.SetActive(value: true);
		SystemText systemText = Data.SystemText;
		if (limitTime < 3600)
		{
			int num = limitTime / 60 + 1;
			_labelRemainTime.text = systemText.Get(_remainMinuteTextId, num.ToString());
		}
		else if (limitTime < 86400)
		{
			int num2 = limitTime / 3600;
			_labelRemainTime.text = systemText.Get(_remainHourTextId, num2.ToString());
		}
		else
		{
			int num3 = limitTime / 86400;
			_labelRemainTime.text = systemText.Get(_remainDayTextId, num3.ToString());
		}
	}

	private void SetCampaignDisplay()
	{
		_labelRemainTime.text = Data.SystemText.Get("MyPage_0076");
	}
}
