package cn.forevermc.launcher.view.pages;

import cn.forevermc.launcher.bean.ComponentSize;
import cn.forevermc.launcher.view.components.AbstractPane;
import cn.forevermc.launcher.view.components.control.MCButton;
import cn.forevermc.launcher.view.components.control.MCLabel;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import lombok.Getter;
import com.imyeyu.fx.ui.TimiFXUI;

/**
 * 会话面板
 *
 * @author 夜雨
 * @since 2022-11-28 17:32
 */
public abstract class DialogPane extends AbstractPane {

	/** 标题 */
	@Getter
	protected final MCLabel title;

	/** 内容 */
	@Getter
	protected final MCLabel content;

	protected HBox buttonPane;
	protected MCButton confirm, deny, cancel, close;
	protected ObjectProperty<Node> graphic;

	private final StackPane graphicPane;

	public DialogPane() {
		graphic = new SimpleObjectProperty<>();

		// 标题
		title = new MCLabel();
		title.setTextFill(Colorful.LIGHT_GRAY);

		// 内容
		content = new MCLabel("content");
		content.setPadding(new Insets(0, 8, 0, 8));

		// 自定义组件
		graphicPane = new StackPane();
		graphic.addListener((obs, o, newGraphic) -> {
			if (newGraphic == null) {
				graphicPane.getChildren().clear();
			} else {
				graphicPane.getChildren().setAll(newGraphic);
			}
		});

		// 确认
		confirm = new MCButton(TimiFXUI.MULTILINGUAL.text("confirm"));
		confirm.setPrefWidth(ComponentSize.SMALL);
		confirm.managedProperty().bind(confirm.visibleProperty());

		// 拒绝
		deny = new MCButton(TimiFXUI.MULTILINGUAL.text("no"));
		deny.setPrefWidth(ComponentSize.SMALL);
		deny.managedProperty().bind(deny.visibleProperty());

		// 取消
		cancel = new MCButton(TimiFXUI.MULTILINGUAL.text("cancel"));
		cancel.setPrefWidth(ComponentSize.SMALL);
		cancel.managedProperty().bind(cancel.visibleProperty());

		// 关闭
		close = new MCButton(TimiFXUI.MULTILINGUAL.text("close"));
		close.setPrefWidth(ComponentSize.SMALL);
		close.managedProperty().bind(close.visibleProperty());

		setCenter(new VBox() {{
			setSpacing(8);
			setAlignment(Pos.CENTER);
			getChildren().addAll(title, content, graphicPane);
		}});
		setBottom(buttonPane = new HBox() {{
			setSpacing(16);
			setPadding(new Insets(16, 16, 64, 16));
			setAlignment(Pos.CENTER);
			getChildren().setAll(confirm, deny, cancel, close);
		}});
	}
}
