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

import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.ui.components.LabelProgressBar;
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.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.geometry.Insets;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

/**
 * 标签进度
 *
 * @author 夜雨
 * @since 2022-08-29 21:49
 */
@Component
public class LabelProgressBarDemo extends AbstractDemoPane {

	private final Timeline tl;

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

		// 静态
		LabelProgressBar text = new LabelProgressBar();
		text.setText(TimiFXUI.MULTILINGUAL.text("fx.example.label_progress_bar"));
		text.setMaxWidth(Double.MAX_VALUE);

		// 动态
		LabelProgressBar dynamic = new LabelProgressBar();
		dynamic.textProperty().bind(dynamic.progressProperty().multiply(100).asString("%.2f %%"));
		dynamic.setMaxWidth(Double.MAX_VALUE);
		tl = new Timeline();
		tl.getKeyFrames().add(new KeyFrame(Duration.ZERO, new KeyValue(dynamic.progressProperty(), 0)));
		tl.getKeyFrames().add(new KeyFrame(Duration.seconds(10), new KeyValue(dynamic.progressProperty(), 1)));
		tl.setCycleCount(Timeline.INDEFINITE);
		tl.play();

		setCenter(new VBox() {{
			setSpacing(6);
			setPadding(new Insets(20));
			getChildren().addAll(text, dynamic);
		}});
	}

	@Override
	protected void onShow() {
		tl.play();
	}

	@Override
	protected void onHide() {
		tl.pause();
	}
}
