using System.Collections;
using Cute;
using UnityEngine;
using Wizard;

public class MyPageCardPanel : MonoBehaviour
{
	[SerializeField]
	private UITexture _texture;

	[SerializeField]
	private string _filePath;

	[SerializeField]
	private UILabel _titleLabel;

	[SerializeField]
	private GameObject _effect;

	[SerializeField]
	private bool enableMaintenanceCheck;

	[SerializeField]
	protected NetworkDefine.MAINTENANCE_TYPE maintenanceType;

	[SerializeField]
	private NetworkDefine.MAINTENANCE_TYPE[] _maintenanceTypeList;

	private CardPanelMaintenancePlate _maintenancePlate;

	private Vector3? _savedPosition;

	public UITexture Texture => _texture;

	public string FilePath => _filePath;

	protected UILabel TitleLabel => _titleLabel;

	public int Index { get; set; }

	public bool EffectActive
	{
		set
		{
			if (_effect != null)
			{
				_effect.SetActive(value);
			}
		}
	}

	public NetworkDefine.MAINTENANCE_TYPE MaintenanceType
	{
		get
		{
			return maintenanceType;
		}
		set
		{
			enableMaintenanceCheck = true;
			maintenanceType = value;
		}
	}

	public virtual string GetResourcePath(bool isfetch)
	{
		return Toolbox.ResourcesManager.GetAssetTypePath(FilePath, ResourcesManager.AssetLoadPathType.CardMenu, isfetch);
	}

	public void AttachCardPanelTexture()
	{
		Texture.mainTexture = Toolbox.ResourcesManager.LoadObject(GetResourcePath(isfetch: true)) as Texture;
	}

	public virtual void CheckMaintenanceType()
	{
		if (!enableMaintenanceCheck)
		{
			return;
		}
		bool flag = false;
		if (Data.MaintenanceCodeList.Contains(maintenanceType))
		{
			flag = true;
		}
		if (_maintenanceTypeList != null && _maintenanceTypeList.Length != 0)
		{
			bool flag2 = true;
			NetworkDefine.MAINTENANCE_TYPE[] maintenanceTypeList = _maintenanceTypeList;
			foreach (NetworkDefine.MAINTENANCE_TYPE item in maintenanceTypeList)
			{
				if (!Data.MaintenanceCodeList.Contains(item))
				{
					flag2 = false;
					break;
				}
			}
			if (flag2)
			{
				flag = true;
			}
		}
		if (flag)
		{
			ShowMaintenance();
		}
		else
		{
			HideMaintenance();
		}
	}

	private void ShowMaintenance()
	{
		if (_maintenancePlate == null)
		{
			GameObject prefab = GameMgr.GetIns().GetPrefabMgr().Get("Prefab/UI/Menu/CardPanelMaintenancePlate");
			_maintenancePlate = NGUITools.AddChild(base.gameObject, prefab).GetComponent<CardPanelMaintenancePlate>();
		}
		_maintenancePlate.gameObject.SetActive(value: true);
		UIManager.SetObjectToGrey(base.gameObject, b: true);
		UIManager.SetObjectToGrey(_maintenancePlate.gameObject, b: false);
	}

	private void HideMaintenance()
	{
		if (_maintenancePlate != null)
		{
			_maintenancePlate.gameObject.SetActive(value: false);
		}
		UIManager.SetObjectToGrey(base.gameObject, b: false);
	}

	public void SetDisableForTutorial(bool isGrey)
	{
		UIManager.SetObjectToGrey(base.gameObject, isGrey);
	}

	public Vector3 SavePosition()
	{
		_savedPosition = base.transform.localPosition;
		return _savedPosition.Value;
	}

	public void RestoreSavedPosition()
	{
		base.transform.localPosition = _savedPosition.Value;
	}

	public IEnumerator DisablePanel(string text)
	{
		ShowMaintenance();
		yield return null;
		_maintenancePlate.SetText(text);
	}
}
