package com.imyeyu.fx.ui.examples.component;

import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.ui.components.Hyperlink;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;

/**
 * 抽象示例面板
 *
 * @author 夜雨
 * @since 2022-08-29 15:44
 */
public abstract class AbstractDemoPane extends AbstractPane {

	/** 标题 */
	protected Label title;

	/** 提示 */
	protected Label tips;

	/** 文档 */
	protected Hyperlink document;

	/** 源码 */
	protected Hyperlink source;

	public AbstractDemoPane() {
		// 标题
		title = new Label();
		title.setBorder(Stroke.BOTTOM);
		title.setPadding(new Insets(4, 6, 4, 6));
		title.setMaxWidth(Double.MAX_VALUE);
		title.setBackground(BG.WHITE);

		// 文档
		Label labelDocument = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("document"));
		document = new Hyperlink();

		// 源码
		Label labelSource = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("source"));
		source = new Hyperlink();

		// 提示
		tips = TimiFXUI.label();
		tips.setPadding(new Insets(4, 6, 4, 6));
		tips.setWrapText(true);
		tips.setMaxWidth(Double.MAX_VALUE);
		tips.visibleProperty().bind(tips.textProperty().isNotEmpty());
		tips.managedProperty().bind(tips.visibleProperty());
		tips.textProperty().addListener((obs, o, newTips) -> {
			if (!newTips.startsWith("\t")) {
				tips.setText("\t" + newTips);
			}
		});

		setTop(new VBox() {{
			getChildren().addAll(title, new GridPane() {{
				setHgap(6);
				setVgap(3);
				setBorder(Stroke.BOTTOM);
				setPadding(new Insets(3, 6, 3, 6));

				addRow(0, labelDocument, document);
				addRow(1, labelSource, source);
			}}, tips);
		}});
	}
}
