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

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

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

		public void PaintTopInGame(ClipState clipState)
		{
			if (clipState == ClipState.BeforeClip)
			{
				var w = Hud.Window.Size.Width * -0.062f;  var h = Hud.Window.Size.Height * 0.1904f;					
				foreach(var player in Hud.Game.Players)
				{
					if (!player.HasValidActor) continue;					
					var pt = player.PortraitUiElement.Rectangle; 
					double exper = (player.CurrentLevelNormal < 70)? (player.CurrentLevelNormal/70d) : (player.CurrentLevelParagonDouble - player.CurrentLevelParagon);	
					ParagonDecorator.Paint(pt.X + pt.Width * 0.73f, pt.Y + pt.Height * 0.20f, w, h, string.Format(CultureInfo.InvariantCulture, "{0:0%}", exper));						
				}
			}
		}
	}
}