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

namespace Kasizuki
{
	public class MaidAppealComment : MonoBehaviour
	{
		public Action onClickRight { get; set; }

		public Action onClickLeft { get; set; }

		private void Awake()
		{
			if (this.m_ButtonRight != null)
			{
				EventDelegate.Add(this.m_ButtonRight.onClick, delegate()
				{
					if (this.onClickRight != null)
					{
						this.onClickRight();
					}
				});
			}
			if (this.m_ButtonLeft != null)
			{
				EventDelegate.Add(this.m_ButtonLeft.onClick, delegate()
				{
					if (this.onClickLeft != null)
					{
						this.onClickLeft();
					}
				});
			}
		}

		private void Start()
		{
			if (Product.supportMultiLanguage)
			{
				this.appealLanguageSprites.Add(Product.Language.Japanese.ToString(), this.m_ImageAppealComment);
				string[] names = Enum.GetNames(typeof(Product.Language));
				for (int i = 1; i < names.Length; i++)
				{
					GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_ImageAppealComment.gameObject);
					gameObject.transform.SetParent(this.m_ImageAppealComment.transform.parent);
					gameObject.transform.localScale = Vector3.one;
					gameObject.transform.localPosition = this.m_ImageAppealComment.transform.localPosition;
					this.appealLanguageSprites.Add(names[i], gameObject.GetComponent<UI2DSprite>());
					gameObject.name = names[i];
				}
				this.OnLocalize();
			}
		}

		private void OnDestroy()
		{
			this.DestroyImage();
		}

		public void OnLocalize()
		{
			if (!Product.supportMultiLanguage)
			{
				return;
			}
			foreach (KeyValuePair<string, UI2DSprite> keyValuePair in this.appealLanguageSprites)
			{
				keyValuePair.Value.gameObject.SetActive(keyValuePair.Key == Product.systemLanguage.ToString());
			}
		}

		public void DestroyImage()
		{
			if (this.m_ImageAppealComment != null && this.m_ImageAppealComment.sprite2D != null)
			{
				if (this.m_ImageAppealComment.sprite2D.texture != null)
				{
					UnityEngine.Object.DestroyImmediate(this.m_ImageAppealComment.sprite2D.texture, true);
				}
				this.m_ImageAppealComment.sprite2D = null;
			}
			foreach (KeyValuePair<string, UI2DSprite> keyValuePair in this.appealLanguageSprites)
			{
				UI2DSprite value = keyValuePair.Value;
				if (value != null && value.sprite2D != null)
				{
					if (value.sprite2D.texture != null)
					{
						UnityEngine.Object.DestroyImmediate(value.sprite2D.texture, true);
					}
					value.sprite2D = null;
				}
			}
		}

		public void ChangeImage(Texture2D texture)
		{
			this.DestroyImage();
			if (texture == null)
			{
				return;
			}
			Sprite sprite = Sprite.Create(texture, new Rect(0f, 0f, (float)texture.width, (float)texture.height), default(Vector2));
			sprite.name = "Image _" + texture.name;
			this.m_ImageAppealComment.sprite2D = sprite;
		}

		public void ChangeImage(Dictionary<string, Texture2D> languageTexture)
		{
			this.DestroyImage();
			if (languageTexture == null || languageTexture.Count == 0)
			{
				return;
			}
			foreach (KeyValuePair<string, Texture2D> keyValuePair in languageTexture)
			{
				if (!(keyValuePair.Value == null) && this.appealLanguageSprites.ContainsKey(keyValuePair.Key))
				{
					Texture2D value = keyValuePair.Value;
					Sprite sprite = Sprite.Create(value, new Rect(0f, 0f, (float)value.width, (float)value.height), default(Vector2));
					sprite.name = "Image _" + value.name;
					this.appealLanguageSprites[keyValuePair.Key].sprite2D = sprite;
				}
			}
		}

		public void SetEnableEditing(bool isEnable)
		{
			if (this.m_ButtonRight != null)
			{
				this.m_ButtonRight.gameObject.SetActive(isEnable);
			}
			if (this.m_ButtonLeft != null)
			{
				this.m_ButtonLeft.gameObject.SetActive(isEnable);
			}
		}

		[SerializeField]
		private UI2DSprite m_ImageAppealComment;

		[SerializeField]
		private UIButton m_ButtonRight;

		[SerializeField]
		private UIButton m_ButtonLeft;

		private Dictionary<string, UI2DSprite> appealLanguageSprites = new Dictionary<string, UI2DSprite>();
	}
}
