package cn.forevermc.launcher.view.pages;

import cn.forevermc.launcher.bean.ComponentSize;
import cn.forevermc.launcher.util.Resources;
import cn.forevermc.launcher.view.components.AbstractPane;
import cn.forevermc.launcher.view.components.control.MCButton;
import cn.forevermc.launcher.view.components.control.MCCheckBox;
import cn.forevermc.launcher.view.components.control.MCLabel;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import lombok.Getter;
import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.utils.BgImage;

/**
 * 画板进度页面
 *
 * @author 夜雨
 * @since 2023-06-15 17:49
 */
public abstract class CanvasProgressPane extends AbstractPane {

	protected static final int SIZE = 128;

	@Getter
	protected final MCLabel label, subLabel;

	protected final Canvas canvas;
	protected final MCButton cancel;
	protected final MCCheckBox bgmToggle;
	protected final GraphicsContext g;

	public CanvasProgressPane() {
		// 主提示
		label = new MCLabel();

		// 副提示
		subLabel = new MCLabel();

		// 图形进度
		canvas = new Canvas();
		canvas.setWidth(SIZE);
		canvas.setHeight(SIZE);
		g = canvas.getGraphicsContext2D();

		// 取消
		cancel = new MCButton(ComponentSize.LARGE, TimiFXUI.MULTILINGUAL.text("cancel"));

		// 背景音乐
		bgmToggle = new MCCheckBox();
		bgmToggle.setSelected(true);

		setCenter(new BorderPane() {{
			setAlignment(canvas, Pos.CENTER);
			setMargin(canvas, new Insets(8, 0, 12, 0));
			setCenter(new VBox() {{
				setSpacing(8);
				setAlignment(Pos.CENTER);
				getChildren().addAll(label, subLabel);
			}});
			setBottom(new BorderPane() {{
				setCenter(canvas);
				setBottom(new HBox() {{
					setSpacing(4);
					setAlignment(Pos.CENTER);
					visibleProperty().bind(bgmToggle.visibleProperty());
					managedProperty().bind(visibleProperty());
					getChildren().addAll(bgmToggle, new MCLabel() {{
						bgmToggle.setLabel(this);
						setText(TimiFXUI.MULTILINGUAL.text("bgm"));
					}});
				}});
			}});
		}});
		setBottom(new HBox() {{
			setSpacing(16);
			setPadding(new Insets(16, 16, 64, 16));
			setAlignment(Pos.CENTER);
			getChildren().setAll(cancel);
		}});
	}
}
