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

import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.ui.components.navigation.Navigation;
import com.imyeyu.fx.ui.components.navigation.NavigationGroup;
import com.imyeyu.fx.ui.components.navigation.NavigationItem;
import com.imyeyu.fx.ui.examples.component.AbstractDemoPane;
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
import com.imyeyu.fx.utils.grid.Column;
import com.imyeyu.fx.utils.grid.Row;
import com.imyeyu.inject.annotation.Component;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;

/**
 * 导航组件
 *
 * @author 夜雨
 * @since 2022-08-29 21:49
 */
@Component
public class NavigationDemo extends AbstractDemoPane {

	public NavigationDemo() {
		title.setText(SidebarItem.NAVIGATION.getText());
		document.sync("https://doc.imyeyu.net/timi-fx/net/imyeyu/timifx/component/Navigation.html");
		source.sync("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/java/net/imyeyu/timifx/component/Navigation.java");
		tips.setText(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.tips"));

		// 一般
		Label labelCommonly = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("commonly"));
		labelCommonly.setAlignment(Pos.CENTER);
		Navigation commonly = new Navigation();
		commonly.setPrefWidth(240);
		commonly.add(new NavigationItem("item 0"));
		commonly.add(new NavigationItem("item 1"));
		commonly.add(new NavigationItem("item 2"));

		// 二级
		Label labelSecond = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.second"));
		labelSecond.setAlignment(Pos.CENTER);
		Navigation second = new Navigation();
		second.add(new NavigationItem("item 0"));
		second.add(new NavigationItem("item 1"));
		second.add(new NavigationItem("item 2"));
		second.add(new NavigationGroup(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.second"))
			.add(new NavigationItem("item 0"), new NavigationItem("item 1")));

		// 默认展开
		Label labelExpanded = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.expanded"));
		labelExpanded.setAlignment(Pos.CENTER);
		Navigation expanded = new Navigation();
		expanded.add(new NavigationItem("item 0"));
		expanded.add(new NavigationItem("item 1"));
		expanded.add(new NavigationItem("item 2"));
		expanded.add(new NavigationGroup(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.second"))
			.expanded(true)
			.add(new NavigationItem("item 0"), new NavigationItem("item 1")));

		// 三级
		Label labelMulti = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.multi"));
		labelMulti.setAlignment(Pos.CENTER);
		Navigation multi = new Navigation();
		multi.add(new NavigationItem("item 0"));
		multi.add(new NavigationItem("item 1"));
		multi.add(new NavigationItem("item 2"));
		multi.add(
			new NavigationGroup(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.second"))
				.expanded(true)
				.add(
					new NavigationItem("item 0"),
					new NavigationGroup(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.multi"))
						.expanded(true)
						.add(new NavigationItem("item 0"), new NavigationItem("item 1"))
				),
			new NavigationGroup(TimiFXUI.MULTILINGUAL.text("fx.example.navigation.second"))
				.expanded(true)
				.add(new NavigationItem("item 0"), new NavigationItem("item 1"))
		);

		setCenter(new GridPane() {{
			getColumnConstraints().addAll(
					Column.builder().width(220).build(),
					Column.builder().width(220).build(),
					Column.builder().width(220).build(),
					Column.builder().width(220).build()
			);
			getRowConstraints().addAll(Row.builder().build(), Row.builder().alwaysPriority().build());
			setVgap(5);
			setHgap(5);
			setPadding(new Insets(32));

			addRow(0, labelCommonly, labelSecond, labelExpanded, labelMulti);
			addRow(1, commonly, second, expanded, multi);
		}});
	}
}
