package components;

import model.String.Strings;
import haxe.macro.Expr.Case;
import feathers.text.TextFormat;
import openfl.Assets;
import openfl.text.Font;
import feathers.controls.Label;
import feathers.layout.HorizontalLayout;
import openfl.display.Shape;
import model.Constants;
import feathers.skins.RectangleSkin;
import feathers.controls.LayoutGroup;

class RidersListRendererAccessory extends LayoutGroup {
	private var riderCredit:Int;

	public function new(pRiderCredit:Int = 0) {
		super();
		riderCredit = pRiderCredit;
	}

	override private function initialize():Void {
		super.initialize();

		var l:HorizontalLayout = new HorizontalLayout();
		// l.setPadding(Std.int(headerHeight * .1));
		l.verticalAlign = MIDDLE;
		l.gap = 10;
		layout = l;

		backgroundSkin = new RectangleSkin(SolidColor(Constants.PURE_WHITE, 0));

		// Title label
		var lbl1 = new Label();

		// lbl1.layoutData = ld1;
		// lb1.backgroundSkin = new RectangleSkin(SolidColor(Constants.ACCENT_COLOR2, 1));
		// lb1.verticalAlign = VerticalAlign.TOP;

		var iconColor:Int;
		var fnt:Font = Assets.getFont(Constants.MONTSERRAT_MEDIUM_500);

		if (riderCredit <= Constants.CREDIT_ULTRA_LOW_LIMIT) {
			iconColor = Constants.ALARM;
		} else if (riderCredit <= Constants.CREDIT_LOW_LIMIT) {
			iconColor = Constants.ALERT;
		} else if (riderCredit <= Constants.CREDIT_AVERAGE_LIMIT) {
			iconColor = Constants.WARNING;
		} else {
			iconColor = Constants.INFO;
		}

		lbl1.text = Strings.RL_S1 + Std.string(riderCredit);
		lbl1.embedFonts = true;
		lbl1.textFormat = new TextFormat(fnt.fontName, 14, Constants.MAIN_COLOR1);
		addChild(lbl1);

		var s:Shape = new Shape();
		s.graphics.beginFill(iconColor, 1);
		s.graphics.drawCircle(10, 10, 10);
		s.graphics.endFill();
		addChild(s);
	}
}
