package be.iminds.ilabt.jfed.experimenter_gui.bugreporting;

import javafx.beans.Observable;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import org.controlsfx.dialog.CommandLinksDialog;

/**
 * BugReportQuestionButton
 */
public class BugReportQuestionButton extends Button {
    private StringProperty firstLine = new SimpleStringProperty();
    private StringProperty secondLine = new SimpleStringProperty();

    public BugReportQuestionButton() {
        super();

        this.getStylesheets().add(this.getClass().getResource("bugreportquestionbutton.css").toExternalForm());

        this.getStyleClass().addAll(new String[]{"command-link-button"});
        this.setMaxHeight(1.7976931348623157E308D);
        this.setMaxWidth(1.7976931348623157E308D);
        this.setAlignment(Pos.CENTER_LEFT);
//        this.setDefaultButton(todo);
        final Label titleLabel = new Label();
        titleLabel.textProperty().bindBidirectional(firstLine);
        titleLabel.minWidthProperty().bind(new DoubleBinding() {
            {
                this.bind(new Observable[]{titleLabel.prefWidthProperty()});
            }

            protected double computeValue() {
                return titleLabel.getPrefWidth() + 400.0D;
            }
        });
        titleLabel.getStyleClass().addAll(new String[]{"line-1"});
        titleLabel.setWrapText(true);
        titleLabel.setAlignment(Pos.TOP_LEFT);
        GridPane.setVgrow(titleLabel, Priority.NEVER);
        Label messageLabel = new Label();
        messageLabel.textProperty().bindBidirectional(secondLineProperty());
        messageLabel.getStyleClass().addAll(new String[]{"line-2"});
        messageLabel.setWrapText(true);
        messageLabel.setAlignment(Pos.TOP_LEFT);
//        messageLabel.setMaxHeight(1.7976931348623157E308D);
        GridPane.setVgrow(messageLabel, Priority.SOMETIMES);
        Node commandLinkImage = null;
        Object view = commandLinkImage == null?
                new ImageView(CommandLinksDialog.class.getResource("arrow-green-right.png").toExternalForm()) :
                commandLinkImage;
        Pane graphicContainer = new Pane(new Node[]{(Node)view});
        graphicContainer.getStyleClass().add("graphic-container");
        GridPane.setValignment(graphicContainer, VPos.TOP);
        GridPane.setMargin(graphicContainer, new Insets(0.0D, 10.0D, 0.0D, 0.0D));
        GridPane grid = new GridPane();
        grid.minWidthProperty().bind(titleLabel.prefWidthProperty());
//        grid.setMaxHeight(1.7976931348623157E308D);
        grid.setMaxWidth(1.7976931348623157E308D);
        grid.getStyleClass().add("container");
        grid.add(graphicContainer, 0, 0, 1, 2);
        grid.add(titleLabel, 1, 0);
        grid.add(messageLabel, 1, 1);
        this.setGraphic(grid);
        this.minWidthProperty().bind(titleLabel.prefWidthProperty());
    }

    public String getFirstLine() {
        return this.firstLine.get();
    }

    public StringProperty firstLineProperty() {
        return this.firstLine;
    }

    public void setFirstLine(String firstLine) {
        this.firstLine.set(firstLine);
    }

    public String getSecondLine() {
        return this.secondLine.get();
    }

    public StringProperty secondLineProperty() {
        return this.secondLine;
    }

    public void setSecondLine(String secondLine) {
        this.secondLine.set(secondLine);
    }
}
