using System;
using System.Drawing;
using Decal.Adapter.Support;
using Decal.Interop.Controls;

namespace Decal.Adapter.Wrappers;

public class PushButtonWrapper : ControlWrapperBase<PushButtonClass>
{
	private EventHandler<ControlEventArgs> evtClick;

	private EventHandler<ControlEventArgs> evtCancel;

	private EventHandler<ControlEventArgs> evtDestroy;

	private EventHandler<ControlEventArgs> evtHit;

	private EventHandler<ControlEventArgs> evtUnhit;

	public Color FaceColor
	{
		get
		{
			return Util.ColorFromBGR(base.Control.FaceColor);
		}
		set
		{
			base.Control.FaceColor = Util.ColorToBGR(value);
		}
	}

	public Color TextColor
	{
		get
		{
			return Util.ColorFromBGR(base.Control.TextColor);
		}
		set
		{
			base.Control.TextColor = Util.ColorToBGR(value);
		}
	}

	public string Text
	{
		get
		{
			return base.Control.Text;
		}
		set
		{
			base.Control.Text = value;
		}
	}

	public event EventHandler<ControlEventArgs> Click
	{
		add
		{
			if (evtClick == null)
			{
				base.Control.Accepted += ClickEvent;
			}
			evtClick = (EventHandler<ControlEventArgs>)Delegate.Combine(evtClick, value);
		}
		remove
		{
			evtClick = (EventHandler<ControlEventArgs>)Delegate.Remove(evtClick, value);
			if (evtClick == null)
			{
				base.Control.Accepted -= ClickEvent;
			}
		}
	}

	public event EventHandler<ControlEventArgs> Canceled
	{
		add
		{
			if (evtCancel == null)
			{
				base.Control.Canceled += CanceledEvent;
			}
			evtCancel = (EventHandler<ControlEventArgs>)Delegate.Combine(evtCancel, value);
		}
		remove
		{
			evtCancel = (EventHandler<ControlEventArgs>)Delegate.Remove(evtCancel, value);
			if (evtCancel == null)
			{
				base.Control.Canceled -= CanceledEvent;
			}
		}
	}

	public event EventHandler<ControlEventArgs> Destroy
	{
		add
		{
			if (evtDestroy == null)
			{
				base.Control.Destroy += DestroyEvent;
			}
			evtDestroy = (EventHandler<ControlEventArgs>)Delegate.Combine(evtDestroy, value);
		}
		remove
		{
			evtDestroy = (EventHandler<ControlEventArgs>)Delegate.Remove(evtDestroy, value);
			if (evtDestroy == null)
			{
				base.Control.Destroy -= DestroyEvent;
			}
		}
	}

	public event EventHandler<ControlEventArgs> Hit
	{
		add
		{
			if (evtHit == null)
			{
				base.Control.Hit += HitEvent;
			}
			evtHit = (EventHandler<ControlEventArgs>)Delegate.Combine(evtHit, value);
		}
		remove
		{
			evtHit = (EventHandler<ControlEventArgs>)Delegate.Remove(evtHit, value);
			if (evtHit == null)
			{
				base.Control.Hit -= HitEvent;
			}
		}
	}

	public event EventHandler<ControlEventArgs> Unhit
	{
		add
		{
			if (evtUnhit == null)
			{
				base.Control.Unhit += UnhitEvent;
			}
			evtUnhit = (EventHandler<ControlEventArgs>)Delegate.Combine(evtUnhit, value);
		}
		remove
		{
			evtUnhit = (EventHandler<ControlEventArgs>)Delegate.Remove(evtUnhit, value);
			if (evtUnhit == null)
			{
				base.Control.Unhit -= UnhitEvent;
			}
		}
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing)
		{
			if (evtClick != null)
			{
				evtClick = (EventHandler<ControlEventArgs>)Delegate.Remove(evtClick, evtClick);
				base.Control.Accepted -= ClickEvent;
			}
			if (evtCancel != null)
			{
				evtCancel = (EventHandler<ControlEventArgs>)Delegate.Remove(evtCancel, evtCancel);
				base.Control.Canceled -= CanceledEvent;
			}
			if (evtDestroy != null)
			{
				evtDestroy = (EventHandler<ControlEventArgs>)Delegate.Remove(evtDestroy, evtDestroy);
				base.Control.Destroy -= DestroyEvent;
			}
			if (evtHit != null)
			{
				evtHit = (EventHandler<ControlEventArgs>)Delegate.Remove(evtHit, evtHit);
				base.Control.Hit -= HitEvent;
			}
			if (evtUnhit != null)
			{
				evtUnhit = (EventHandler<ControlEventArgs>)Delegate.Remove(evtUnhit, evtUnhit);
				base.Control.Unhit -= UnhitEvent;
			}
		}
		base.Dispose(disposing);
	}

	private void ClickEvent(int ID)
	{
		if (evtClick != null)
		{
			evtClick(this, new ControlEventArgs(ID));
		}
	}

	private void UnhitEvent(int ID)
	{
		if (evtUnhit != null)
		{
			evtUnhit(this, new ControlEventArgs(ID));
		}
	}

	private void HitEvent(int ID)
	{
		if (evtHit != null)
		{
			evtHit(this, new ControlEventArgs(ID));
		}
	}

	private void DestroyEvent(int ID)
	{
		if (evtDestroy != null)
		{
			evtDestroy(this, new ControlEventArgs(ID));
		}
	}

	private void CanceledEvent(int ID)
	{
		if (evtCancel != null)
		{
			evtCancel(this, new ControlEventArgs(ID));
		}
	}
}
