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

import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.ui.components.popup.PopupTipsService;
import com.imyeyu.fx.ui.components.popup.tips.AbstractPopupTips;
import com.imyeyu.fx.ui.examples.component.AbstractDemoPane;
import com.imyeyu.fx.ui.examples.component.sidebar.SidebarItem;
import com.imyeyu.inject.annotation.Component;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

/**
 * 弹出提示
 *
 * @author 夜雨
 * @since 2022-09-01 14:40
 */
@Component
public class PopupTipsDemo extends AbstractDemoPane {

	public PopupTipsDemo() {
		title.setText(SidebarItem.POPUP_TIPS.getText());
		document.sync("https://doc.imyeyu.net/timi-fx/net/imyeyu/timifx/component/popup/PopupTipsService.html");
		source.sync("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/java/net/imyeyu/timifx/component/popup/AbstractPopupTips.java");
		tips.setText(TimiFXUI.MULTILINGUAL.text("fx.example.popup_tips.tips"));

		// 一般
		Button text = new Button(TimiFXUI.MULTILINGUAL.text("text"));
		PopupTipsService.installText(text, TimiFXUI.MULTILINGUAL.text("fx.example.demo.text"));

		// 长文本
		Button textLong = new Button(TimiFXUI.MULTILINGUAL.text("fx.example.popup_tips.text_long"));
		textLong.setBorder(Stroke.EX_LEFT);
		PopupTipsService.installText(textLong, TimiFXUI.MULTILINGUAL.text("fx.example.demo.text_long"));

		// 图片
		Button image = new Button(TimiFXUI.MULTILINGUAL.text("image"));
		image.setBorder(Stroke.EX_LEFT);
		PopupTipsService.installImage(image, new Image(RESOURCE + "icon.png", 64, 64, false, false));

		// 自定义
		Button custom = new Button(TimiFXUI.MULTILINGUAL.text("custom"));
		custom.setBorder(Stroke.EX_LEFT);

		// 保持显示
		Button keepShow = new Button(TimiFXUI.MULTILINGUAL.text("fx.example.popup_tips.keep_show"));
		keepShow.setBorder(Stroke.EX_LEFT);
		{
			ListView<String> list = new ListView<>();
			for (int i = 0; i < 20; i++) {
				list.getItems().add("item " + i);
			}
			BorderPane customPane = new BorderPane();
			BorderPane.setMargin(list, new Insets(12, 0, 0, 0));
			customPane.setTop(new Button(TimiFXUI.MULTILINGUAL.text("custom")));
			customPane.setCenter(list);
			customPane.setPadding(new Insets(20));
			customPane.setPrefHeight(320);
			customPane.setBackground(BG.DEFAULT);
			AbstractPopupTips<BorderPane> customTips = new AbstractPopupTips<>(customPane);
			PopupTipsService.installTips(custom, customTips);
			PopupTipsService.installTips(keepShow, customTips);

			keepShow.setOnAction(e -> customTips.setKeepShow(true));
		}

		setCenter(new VBox() {{
			setPadding(new Insets(20));
			getChildren().add(new HBox(text, textLong, image, custom, keepShow));
		}});
	}
}
