package leigh.elements.javafx.type1;

import eu.hansolo.tilesfx.Tile;
import eu.hansolo.tilesfx.TileBuilder;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import leigh.elements.ElementBase;
import leigh.elements.sdk.type1.GaugeTileElement;
import leigh.eo.EO;

public class GaugeTileElementJFX extends ElementBase implements ElementJFX {
    private final Tile tile;

    protected GaugeTileElementJFX(EO cfg) {
        super(cfg);

        String title = cfg.getValueString(GaugeTileElement.KEY_TITLE);
        Double value = cfg.getValueDouble(GaugeTileElement.KEY_VALUE);
        String units = cfg.getValueString(GaugeTileElement.KEY_UNITS);
        Double max = cfg.getValueDouble(GaugeTileElement.KEY_MAX_VALUE);
        Double min = cfg.getValueDouble(GaugeTileElement.KEY_MIN_VALUE);


        TileBuilder tb = TileBuilder.create()
                .skinType(Tile.SkinType.GAUGE)
                .prefSize(150, 150)
                .backgroundColor(Color.web("#505050"));

        if (title != null) {
            tb.title(title);
        }

        if (units != null) {
            tb.unit(units);
        }

        if (min != null) tb.minValue(min);
        if (max != null) tb.maxValue(max);

        tile = tb.build();

        if (value != null) tile.setValue(value);
    }

    @Override
    public Node getJavaFXNode() {
        return tile;
    }
}
