package cn.forevermc.launcher.service;

import cn.forevermc.launcher.bean.MCPopupTips;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.layout.Background;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import com.imyeyu.fx.ui.components.popup.AbstractPopupTipsService;
import com.imyeyu.fx.utils.BgFill;
import com.imyeyu.inject.annotation.Service;

/**
 * 弹出提示服务
 *
 * @author 夜雨
 * @since 2021-12-04 11:03
 */
@Service
public class MCPopupTipsService extends AbstractPopupTipsService<BorderPane> {

	private static final Background BG = new BgFill("#101D").build();

	private BorderPane main;

	public MCPopupTipsService() {
		showOnRoot = node -> main.setCenter(node);
	}

	@Override
	protected BorderPane createRoot() {
		main = new BorderPane();
		main.setBackground(BG);

		BorderPane root = new BorderPane(main);

		Pane t = new Pane();
		Pane r = new Pane();
		Pane l = new Pane();
		Pane b = new Pane();

		t.setPrefHeight(3);
		r.setPrefWidth(3);
		b.setPrefHeight(3);
		l.setPrefWidth(3);

		t.setBackground(BG);
		r.setBackground(BG);
		b.setBackground(BG);
		l.setBackground(BG);

		final Insets MARGIN = new Insets(0, 3, 0, 3);
		BorderPane.setMargin(t, MARGIN);
		BorderPane.setMargin(b, MARGIN);

		root.setTop(t);
		root.setRight(r);
		root.setBottom(b);
		root.setLeft(l);

		return root;
	}

	/**
	 * 安装提示
	 *
	 * @param node 被安装节点
	 * @param text 文本
	 * @return 弹出提示
	 */
	public MCPopupTips install(Node node, String text) {
		MCPopupTips tips = new MCPopupTips(text);
		install(node, tips);
		return tips;
	}
}
