package ctbrec.ui.tabs;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ctbrec.docs.DocServer;
import ctbrec.ui.DesktopIntegration;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.layout.BorderPane;

public class HelpTab extends Tab {

    private static final Logger LOG = LoggerFactory.getLogger(HelpTab.class);

    public HelpTab() {
        setClosable(true);
        setText("Help");

        Button openHelp = new Button("Open Help");
        openHelp.setPadding(new Insets(20));
        BorderPane layout = new BorderPane(openHelp);
        BorderPane.setMargin(openHelp, new Insets(20));
        setContent(layout);
        openHelp.setOnAction(e -> {
            new Thread(() -> {
                try {
                    DocServer.start();
                } catch (Exception ex) {
                    LOG.error("Couldn't start documentation server", ex);
                }
            }).start();
            DesktopIntegration.open("http://localhost:5689/docs/index.md");
        });
    }
}
