using System.Globalization;
using Turbo.Plugins.Default;

namespace Turbo.Plugins.User
{
	public class AttackSpeed : BasePlugin, IInGameTopPainter
	{
		public TopLabelWithTitleDecorator AttackSpeedDecorator { get; set; }
		public AttackSpeed()
		{
			Enabled = true;
		}

		public override void Load(IController hud)
		{
			base.Load(hud);			
			AttackSpeedDecorator = new TopLabelWithTitleDecorator(Hud)
			{
				BackgroundBrush = Hud.Render.CreateBrush(0, 255, 255, 255, 0),
				BorderBrush = Hud.Render.CreateBrush(0, 0, 0, 0, -1),
				TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 0, 0, true, false, false),
			};
		}

		public void PaintTopInGame(ClipState clipState)
		{
			if (Hud.Render.UiHidden) return;

			if (clipState == ClipState.BeforeClip)
			{
				var w = Hud.Window.Size.Width * 0.04f;
				var h = Hud.Window.Size.Height * 0.02f;						
				foreach(var player in Hud.Game.Players)
				{
					if (player.HeroClassDefinition.HeroClass == HeroClass.WitchDoctor)
					{						
						float x = Hud.Window.Size.Width * 0.16f; //0.041f
						float y = Hud.Window.Size.Height * 0.981f;
						AttackSpeedDecorator.Paint(x , y, w, h, player.Offense.AttackSpeed.ToString("F2", CultureInfo.InvariantCulture) + "/s"); // CultureInfo.InvariantCulture, "{0:0.##}%" //"F2", CultureInfo.InvariantCulture) + "/s"
					}
				}
			}
		}
	}
}