package com.imyeyu.fx.ui.examples.view.pages.other;

import com.imyeyu.fx.draggable.DraggableNode;
import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.ui.components.TextAreaEditor;
import com.imyeyu.fx.ui.examples.component.AbstractDemoPane;
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
import com.imyeyu.fx.utils.BorderBuilder;
import com.imyeyu.inject.annotation.Component;
import javafx.geometry.Orientation;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.StackPane;

/**
 * @author 夜雨
 * @since 2023-04-13 10:40
 */
@Component
public class DraggableNodeDemo extends AbstractDemoPane {

	public DraggableNodeDemo() {
		title.setText(SidebarItem.DRAGGABLE_NODE.getText());
		document.sync("https://doc.imyeyu.net/timi-fx/net/imyeyu/timifx/util/DraggableNode.html");
		source.sync("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/java/net/imyeyu/timifx/util/DraggableNode.java");
		tips.setText(TimiFXUI.MULTILINGUAL.text("fx.example.draggable_node.tips"));

		TextAreaEditor demo = new TextAreaEditor();
		demo.setBorder(Stroke.TOP);
		demo.setEditable(false);
		demo.setText("""
StackPane box = new StackPane();

StackPane pane = new StackPane(new Label("Drag Me"));
pane.setBorder(new XBorder(FOCUSED_DEFAULT).width(2).build());
pane.setMaxSize(200, 40);
pane.setEffect(SHADOW_POPUP);
pane.setBackground(BG_WHITE);
box.getChildren().add(pane);

DraggableNode draggable = new DraggableNode(pane);
draggable.minXProperty().bind(box.widthProperty().multiply(.5).negate().add(pane.widthProperty().multiply(.5)));
draggable.minYProperty().bind(box.heightProperty().multiply(.5).negate().add(pane.heightProperty().multiply(.5)));
draggable.maxXProperty().bind(box.widthProperty().multiply(.5).subtract(pane.widthProperty().multiply(.5)));
draggable.maxYProperty().bind(box.heightProperty().multiply(.5).subtract(pane.heightProperty().multiply(.5)));
				""".trim());

		StackPane box = new StackPane();

		StackPane pane = new StackPane(new Label(TimiFXUI.MULTILINGUAL.text("fx.example.drag_me")));
		pane.setBorder(BorderBuilder.solid(Colorful.FOCUSED_DEFAULT).width(2).build());
		pane.setMaxSize(200, 40);
		pane.setEffect(Shadow.POPUP);
		pane.setBackground(BG.WHITE);
		box.getChildren().add(pane);

		DraggableNode draggable = new DraggableNode(pane);
		draggable.minXProperty().bind(box.widthProperty().multiply(.5).negate().add(pane.widthProperty().multiply(.5)));
		draggable.minYProperty().bind(box.heightProperty().multiply(.5).negate().add(pane.heightProperty().multiply(.5)));
		draggable.maxXProperty().bind(box.widthProperty().multiply(.5).subtract(pane.widthProperty().multiply(.5)));
		draggable.maxYProperty().bind(box.heightProperty().multiply(.5).subtract(pane.heightProperty().multiply(.5)));

		setCenter(new SplitPane() {{
			setOrientation(Orientation.VERTICAL);
			setDividerPositions(.5);
			getItems().addAll(demo, box);
		}});
	}
}
