using System;
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 OnDestroy()
		{
			this.DestroyImage();
		}

		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;
			}
		}

		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 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;
	}
}
