package p.studio.controls.shell;

import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import p.studio.controls.lifecycle.StudioControlLifecycle;
import p.studio.controls.lifecycle.StudioControlLifecycleSupport;

import java.util.Objects;

public final class StudioRightUtilityPanelControl extends BorderPane implements StudioControlLifecycle {
    public StudioRightUtilityPanelControl(
            Node headerContent,
            ObservableValue<String> activityTitle,
            Node activityContent) {
        StudioControlLifecycleSupport.install(this, this);
        getStyleClass().add("studio-right-utility-panel");
        setPrefWidth(280);

        final Tab activityTab = new Tab();
        activityTab.textProperty().bind(Objects.requireNonNull(activityTitle, "activityTitle"));
        activityTab.setClosable(false);
        activityTab.setContent(Objects.requireNonNull(activityContent, "activityContent"));

        final TabPane tabs = new TabPane(activityTab);
        tabs.getStyleClass().add("studio-right-utility-tabs");
        final VBox layout = new VBox(10);
        layout.getStyleClass().add("studio-right-utility-layout");
        if (headerContent != null) {
            layout.getChildren().add(headerContent);
        }
        layout.getChildren().add(tabs);
        setCenter(layout);
    }

    public static Label createPlaceholderContent(ObservableValue<String> text) {
        final Label label = new Label();
        label.textProperty().bind(Objects.requireNonNull(text, "text"));
        label.getStyleClass().add("studio-utility-placeholder");
        return label;
    }
}
