using System;
using I2.Loc;
using UnityEngine;

[DisallowMultipleComponent]
[RequireComponent(typeof(UIWidget))]
public class UIWidgetlLocalizeSupport : MonoBehaviour
{
	private void Awake()
	{
		if (this.callAwake)
		{
			return;
		}
		this.callAwake = true;
		this.widget = base.GetComponent<UIWidget>();
		if (this.widget != null)
		{
			this.holdWidth = this.widget.width;
			this.holdHeight = this.widget.height;
			LocalizationManager.OnLocalizeEvent -= this.OnLocalize;
			LocalizationManager.OnLocalizeEvent += this.OnLocalize;
			this.OnLocalize();
		}
	}

	public void OnDestroy()
	{
		LocalizationManager.OnLocalizeEvent -= this.OnLocalize;
	}

	public void OnLocalize()
	{
		if (!this.callAwake)
		{
			this.Awake();
		}
		if (LocalizationManager.CurrentLanguageCode == "ja")
		{
			this.widget.width = this.holdWidth;
			this.widget.height = this.holdHeight;
		}
		else
		{
			this.Apply(this.overRidePropertys);
			if (this.languageOverRidePropertys != null)
			{
				foreach (UIWidgetlLocalizeSupport.LanguageOverRideProperty languageOverRideProperty in this.languageOverRidePropertys)
				{
					if (languageOverRideProperty.LanguageCode == LocalizationManager.CurrentLanguageCode)
					{
						this.Apply(languageOverRideProperty.Property);
						break;
					}
				}
			}
		}
	}

	public void Apply(UIWidgetlLocalizeSupport.OverRideProperty property)
	{
		if (!this.callAwake)
		{
			this.Awake();
		}
		this.widget.width = ((!property.width.enabled) ? this.holdWidth : property.width.value);
		this.widget.height = ((!property.height.enabled) ? this.holdHeight : property.height.value);
	}

	[SerializeField]
	public UIWidgetlLocalizeSupport.OverRideProperty overRidePropertys = default(UIWidgetlLocalizeSupport.OverRideProperty);

	[SerializeField]
	public UIWidgetlLocalizeSupport.LanguageOverRideProperty[] languageOverRidePropertys;

	private int holdWidth;

	private int holdHeight;

	private UIWidget widget;

	private bool callAwake;

	[Serializable]
	public struct OverRideProperty
	{
		public UIWidgetlLocalizeSupport.OverRideProperty.IntValue width;

		public UIWidgetlLocalizeSupport.OverRideProperty.IntValue height;

		[Serializable]
		public struct IntValue
		{
			public bool enabled;

			public int value;
		}
	}

	[Serializable]
	public struct LanguageOverRideProperty
	{
		public string LanguageCode;

		public UIWidgetlLocalizeSupport.OverRideProperty Property;
	}
}
