package be.iminds.ilabt.jfed.ui.javafx.scanner;

import be.iminds.ilabt.jfed.scanner.ServerScanner;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;

/**
 * ScanFactPane
 */
public class ScanFactPane extends HBox {
    private final CheckBox select;
//    private final Label typeLab;
    private final Label type;
    private final Label certainityLab;
    private final Label certainityVal;
    private final Label valueLab;
    private final Label valueVal;

    private final String singleFactName;
    private final ServerScanner.ScannedSingleFact singleFact;

    private static final String scannerCss = ScanFactPane.class.getResource("scanner.css").toExternalForm();

    public ScanFactPane(String singleFactName, ServerScanner.ScannedSingleFact singleFact) {
        getStylesheets().add(scannerCss);

        this.singleFact = singleFact;
        this.singleFactName = singleFactName;

        select = new CheckBox();
//        typeLab = new Label("Type:");
        type = new Label(singleFactName);
        certainityLab = new Label("Certainity:");
        certainityVal = new Label(singleFact.getCertainty().toString());
        valueLab = new Label("Value:");
        valueVal = new Label(singleFact.getFact()+"");

        select.setSelected(true);
        this.getStyleClass().add("scan-box");
//        typeLab.getStyleClass().add("scan-label");
        type.getStyleClass().add("scan-typename");
        certainityLab.getStyleClass().add("scan-label");
        certainityVal.getStyleClass().add("scan-value");
        valueLab.getStyleClass().add("scan-label");
        valueVal.getStyleClass().add("scan-value");

        String certHelper = singleFact.getCertainty().toString().toLowerCase().replaceAll("_", "-");
        certainityVal.getStyleClass().add("certainty-"+certHelper);

        getChildren().addAll(select, /*typeLab,*/ type, certainityLab, certainityVal, valueLab, valueVal);
    }

    public ServerScanner.ScannedSingleFact getSingleFact() {
        return singleFact;
    }

    public boolean isSelected() {
        return select.isSelected();
    }

    public void setSelected(boolean newSelected) {
        select.setSelected(newSelected);
    }
}
