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

import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.ui.components.FileTreeView;
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;

import java.io.File;

/**
 * 文件树
 *
 * @author 夜雨
 * @since 2022-08-29 17:38
 */
@Component
public class FileTreeViewDemo extends AbstractDemoPane {

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

		// 一般
		Label labelDefault = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("default"));
		labelDefault.setAlignment(Pos.CENTER);
		FileTreeView def = new FileTreeView();
		def.setBorder(Stroke.DEFAULT);

		// 文件夹
		Label labelDirectory = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.file_tree_view.directory"));
		labelDirectory.setAlignment(Pos.CENTER);
		FileTreeView dir = new FileTreeView();
		dir.setBorder(Stroke.EX_LEFT);
		dir.addItemFilter(File::isDirectory);

		// 自定义过滤
		Label labelFilter = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.file_tree_view.filter"));
		labelFilter.setAlignment(Pos.CENTER);
		FileTreeView filter = new FileTreeView();
		filter.setBorder(Stroke.EX_LEFT);
		filter.addItemFilter(file -> file.isDirectory() || file.getName().endsWith(".txt"));

		// 显示隐藏文件
		Label labelHide = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("fx.example.file_tree_view.hide"));
		labelHide.setAlignment(Pos.CENTER);
		FileTreeView hide = new FileTreeView();
		hide.setBorder(Stroke.EX_LEFT);
		hide.setShowHide(true);

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

			addRow(0, labelDefault, labelDirectory, labelFilter, labelHide);
			addRow(1, def, dir, filter, hide);
		}});
	}
}
