package ui;

import feathers.controls.TextInputState;
import feathers.controls.TextInput;
import openfl.Assets;
import model.Constants;
import feathers.text.TextFormat;
import feathers.controls.ButtonState;
import feathers.skins.RectangleSkin;
import feathers.controls.Button;
import feathers.themes.ClassVariantTheme;

class LPTCTheme extends ClassVariantTheme {

    public static final BUTTON_VARIANT_WHITE:String = "buttonVariantWhite";
    public static final BUTTON_VARIANT_ORANGE:String = "buttonVariantOrange";

    public static final TEXT_INPUT_VARIANT_SEARCH:String = "textInputVariantSearch";

	public function new() {
		super();

		initialize();
	}

	private function initialize():Void {
        styleProvider.setStyleFunction(Button, null, setButtonStyles);
        styleProvider.setStyleFunction(Button, LPTCTheme.BUTTON_VARIANT_WHITE, setWhiteButtonStyles);
        styleProvider.setStyleFunction(Button, LPTCTheme.BUTTON_VARIANT_ORANGE, setOrangeButtonStyles);

        styleProvider.setStyleFunction(TextInput, null, setSearchTextInputStyles);
    }

    //############################################################### BUTTONS
	private function setButtonStyles(button:Button):Void {
		var backgroundSkin = new RectangleSkin();
		backgroundSkin.border = SolidColor(1.0, Constants.HERO_COLOR);
		backgroundSkin.fill = SolidColor(Constants.HERO_COLOR);
		backgroundSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		button.backgroundSkin = backgroundSkin;

		var downSkin = new RectangleSkin();
		downSkin.border = SolidColor(1.0, Constants.HERO_COLOR);
		downSkin.fill = SolidColor(Constants.MAIN_COLOR3);
		downSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		button.setSkinForState(ButtonState.DOWN, downSkin);

		var format = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.MAIN_COLOR3);
		button.textFormat = format;

		var downFormat = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.HERO_COLOR);
		button.setTextFormatForState(ButtonState.DOWN, downFormat);

        button.paddingLeft = button.paddingRight = 10;
        button.paddingTop = button.paddingBottom = 5;
         button.iconOffsetX = Constants.GLOBAL_BUTTON_ICON_OFFSET;
	}

    private function setWhiteButtonStyles(button:Button):Void {
        var backgroundSkin = new RectangleSkin();
		backgroundSkin.border = SolidColor(1.0, Constants.HERO_COLOR);
		backgroundSkin.fill = SolidColor(Constants.MAIN_COLOR3);
		backgroundSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		button.backgroundSkin = backgroundSkin;

		var downSkin = new RectangleSkin();
		downSkin.border = SolidColor(1.0, Constants.HERO_COLOR);
		downSkin.fill = SolidColor(Constants.HERO_COLOR);
		downSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		button.setSkinForState(ButtonState.DOWN, downSkin);

		var format = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.HERO_COLOR);
		button.textFormat = format;

		var downFormat = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.MAIN_COLOR3);
		button.setTextFormatForState(ButtonState.DOWN, downFormat);
        
        button.paddingLeft = button.paddingRight = 10;
        button.paddingTop = button.paddingBottom = 5;
        button.iconOffsetX = Constants.GLOBAL_BUTTON_ICON_OFFSET;
    }

    private function setOrangeButtonStyles(button:Button):Void {
        var backgroundSkin = new RectangleSkin();
		backgroundSkin.border = SolidColor(1.0, Constants.ACCENT_COLOR2);
		backgroundSkin.fill = SolidColor(Constants.ACCENT_COLOR2);
		backgroundSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		button.backgroundSkin = backgroundSkin;

		var downSkin = new RectangleSkin();
		downSkin.border = SolidColor(1.0, Constants.ACCENT_COLOR2);
		downSkin.fill = SolidColor(Constants.MAIN_COLOR3);
		downSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		button.setSkinForState(ButtonState.DOWN, downSkin);

		var format = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.HERO_COLOR);
		button.textFormat = format;

		var downFormat = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.MAIN_COLOR3);
		button.setTextFormatForState(ButtonState.DOWN, downFormat);
        
        button.paddingLeft = button.paddingRight = 10;
        button.paddingTop = button.paddingBottom = 5;
        button.iconOffsetX = Constants.GLOBAL_BUTTON_ICON_OFFSET;
    }

    //############################################################### TEXT_INPUTS
    private function setSearchTextInputStyles(pTextInput:TextInput):Void {

		var backgroundSkin = new RectangleSkin();
		backgroundSkin.border = SolidColor(1, Constants.MAIN_COLOR3, .1);
		backgroundSkin.fill = SolidColor(Constants.MAIN_COLOR3, 0.1);
		backgroundSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		pTextInput.backgroundSkin = backgroundSkin;

        var disabledSkin = new RectangleSkin();
		disabledSkin.border = SolidColor(1, Constants.MAIN_COLOR3, .1);
		disabledSkin.fill = SolidColor(Constants.MAIN_COLOR3, 0.1);
		disabledSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		pTextInput.setSkinForState(TextInputState.DISABLED, disabledSkin);

		var focusSkin = new RectangleSkin();
		focusSkin.border = SolidColor(1, Constants.MAIN_COLOR3, .8);
		focusSkin.fill = SolidColor(Constants.MAIN_COLOR3, 0.2);
		focusSkin.cornerRadius = Constants.GLOBAL_CORNER_RADIUS;
		pTextInput.setSkinForState(TextInputState.FOCUSED, focusSkin);

		var format:TextFormat = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.MAIN_COLOR3);
		pTextInput.textFormat = format;

        var disabledFormat:TextFormat = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.MAIN_COLOR3);
        pTextInput.setTextFormatForState(TextInputState.DISABLED, disabledFormat);

		var focusFormat:TextFormat = new TextFormat(Assets.getFont(Constants.MONTSERRAT_MEDIUM_500).fontName, Constants.FONT_SIZE_14, Constants.MAIN_COLOR3);
        pTextInput.setTextFormatForState(TextInputState.FOCUSED, focusFormat);

        pTextInput.paddingLeft = pTextInput.paddingRight = 10;
        pTextInput.paddingTop = pTextInput.paddingBottom = 5;

        pTextInput.embedFonts = true;
        
	}
}
