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

import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.ui.components.Pagination;
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.inject.annotation.Component;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;

/**
 * 分页组件
 *
 * @author 夜雨
 * @since 2022-08-30 09:34
 */
@Component
public class XPaginationDemo extends AbstractDemoPane {

	public XPaginationDemo() {
		title.setText(SidebarItem.X_PAGINATION.getText());
		document.sync("https://doc.imyeyu.net/timi-fx/net/imyeyu/timifx/component/XPagination.html");
		source.sync("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/java/net/imyeyu/timifx/component/XPagination.java");

		Pagination pagination = new Pagination();

		// 总数
		Label total = new Label();
		Slider totalSlider = new Slider(1, 1000, 100);
		pagination.lengthProperty().bind(totalSlider.valueProperty());
		total.textProperty().bind(totalSlider.valueProperty().asString("%.0f"));

		// 当前页数据量
		Label size = new Label();
		Slider sizeSlider = new Slider(1, 200, 10);
		pagination.sizeProperty().bind(sizeSlider.valueProperty());
		size.textProperty().bind(pagination.sizeProperty().asString());

		// 区块数量（页数）
		Label chunk = new Label();
		chunk.textProperty().bind(pagination.chunkProperty().asString());

		// 激活下标
		Label index = new Label();
		index.textProperty().bind(pagination.indexProperty().asString());

		setCenter(new VBox() {{
			setPadding(new Insets(20));
			getChildren().addAll(pagination, new GridPane() {{
				getColumnConstraints().addAll(Column.builder().build(), Column.builder().width(40).build());
				setHgap(10);
				setVgap(8);
				setPadding(new Insets(20 , 0, 0, 0));

				int row = 0;
				addRow(row++, TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.x_pagination.total")), total, totalSlider);
				addRow(row++, TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.x_pagination.size")), size, sizeSlider);
				addRow(row++, TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.x_pagination.chunk")), chunk);
				addRow(row, TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.x_pagination.index")), index);
			}});
		}});
	}
}
